/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "memory/gcLocker.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/orderAccess.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/preserveException.hpp"
#ifdef TARGET_OS_FAMILY_linux
# include "thread_linux.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_solaris
# include "thread_solaris.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_windows
# include "thread_windows.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_bsd
# include "thread_bsd.inline.hpp"
#endif
// Wrapper for all entry points to the virtual machine.
// The HandleMarkCleaner is a faster version of HandleMark.
// It relies on the fact that there is a HandleMark further
// down the stack (in JavaCalls::call_helper), and just resets
// to the saved values in that HandleMark.
private:
public:
}
~HandleMarkCleaner() {
}
private:
return ptr;
}
};
// InterfaceSupport provides functionality used by the VM_LEAF_BASE and
// VM_ENTRY_BASE macros. These macros are used to guard entry points into
// the VM and perform checks upon leave of the VM.
# ifdef ASSERT
public:
static long _scavenge_alot_counter;
static long _fullgc_alot_counter;
static long _number_of_calls;
static long _fullgc_alot_invocation;
// tracing
// Helper methods used to implement +ScavengeALot and +FullGCALot
static void gc_alot();
static void walk_stack();
# ifdef ENABLE_ZAP_DEAD_LOCALS
static void zap_dead_locals_old();
# endif
static void zombieAll();
static void unlinkSymbols();
static void deoptimizeAll();
static void stress_derived_pointers();
static void verify_stack();
static void verify_last_frame();
# endif
public:
// OS dependent stuff
#ifdef TARGET_OS_FAMILY_linux
# include "interfaceSupport_linux.hpp"
#endif
#ifdef TARGET_OS_FAMILY_solaris
# include "interfaceSupport_solaris.hpp"
#endif
#ifdef TARGET_OS_FAMILY_windows
# include "interfaceSupport_windows.hpp"
#endif
#ifdef TARGET_OS_FAMILY_bsd
# include "interfaceSupport_bsd.hpp"
#endif
};
// Basic class for all thread transition classes.
protected:
public:
}
// Change threadstate in a manner, so safepoint can detect changes.
// Time-critical: called on exit from every runtime routine
// Change to transition state (assumes total store ordering! -Urs)
// Make sure new state is seen by VM thread
if (UseMembar) {
// Force a fence between the write above and read below
OrderAccess::fence();
} else {
// store to serialize page so VM thread can do pseudo remote membar
}
}
if (SafepointSynchronize::do_call_back()) {
}
}
// transition_and_fence must be used on any thread state transition
// where there might not be a Java call stub on the stack, in
// particular on Windows where the Structured Exception Handler is
// set up in the call stub. os::write_memory_serialize_page() can
// fault and we can't recover from it on Windows without a SEH in
// place.
static inline void transition_and_fence(JavaThread *thread, JavaThreadState from, JavaThreadState to) {
// Change to transition state (assumes total store ordering! -Urs)
// Make sure new state is seen by VM thread
if (UseMembar) {
// Force a fence between the write above and read below
OrderAccess::fence();
} else {
// Must use this rather than serialization page in particular on Windows
}
}
if (SafepointSynchronize::do_call_back()) {
}
}
// Same as above, but assumes from = _thread_in_Java. This is simpler, since we
// never block on entry to the VM. This will break the code, since e.g. preserve arguments
// have not been setup.
}
// Change to transition state (assumes total store ordering! -Urs)
// Make sure new state is seen by GC thread
if (UseMembar) {
// Force a fence between the write above and read below
OrderAccess::fence();
} else {
// Must use this rather than serialization page in particular on Windows
}
}
// We never install asynchronous exceptions when coming (back) in
// to the runtime from native code because the runtime is not set
// up to handle exceptions floating around at arbitrary points.
// Clear unhandled oops anywhere where we could block, even if we don't.
}
}
protected:
void trans_and_fence(JavaThreadState from, JavaThreadState to) { transition_and_fence(_thread, from, to); }
};
public:
}
~ThreadInVMfromJava() {
// Check for pending. async. exceptions or suspends.
if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition();
}
};
class ThreadInVMfromUnknown {
private:
public:
if (t->is_Java_thread()) {
// Used to have a HandleMarkCleaner but that is dangerous as
// it could free a handle in our (indirect, nested) caller.
// We expect any handles will be short lived and figure we
// don't need an actual HandleMark.
}
}
}
if (_thread) {
}
}
};
public:
}
~ThreadInVMfromNative() {
}
};
public:
// We are leaving the VM at this point and going directly to native code.
// Block, if we are in the middle of a safepoint synchronization.
// Check for pending. async. exceptions or suspends.
if (_thread->has_special_runtime_exit_condition()) _thread->handle_special_runtime_exit_condition(false);
}
~ThreadToNativeFromVM() {
// We don't need to clear_walkable because it will happen automagically when we return to java
}
};
public:
// Once we are blocked vm expects stack to be walkable
}
~ThreadBlockInVM() {
// We don't need to clear_walkable because it will happen automagically when we return to java
}
};
// This special transition class is only used to prevent asynchronous exceptions
// from being installed on vm exit in situations where we can't tolerate them.
// See bugs: 4324348, 4854693, 4998314, 5040492, 5050705.
public:
}
// NOTE: We do not check for pending. async. exceptions.
// If we did and moved the pending async exception over into the
// pending exception field, we would need to deopt (currently C2
// only). However, to do so would require that we transition back
// to the _thread_in_vm state. Instead we postpone the handling of
// the async exception.
// Check for pending. suspends only.
}
};
// Debug class instantiated in JRT_ENTRY and ITR_ENTRY macro.
#ifdef ASSERT
class VMEntryWrapper {
public:
VMEntryWrapper() {
if (VerifyLastFrame) {
}
}
~VMEntryWrapper() {
if (WalkStackALot) {
}
#ifdef ENABLE_ZAP_DEAD_LOCALS
if (ZapDeadLocalsOld) {
}
#endif
#ifdef COMPILER2
// This option is not used by Compiler 1
if (StressDerivedPointers) {
}
#endif
if (DeoptimizeALot || DeoptimizeRandom) {
}
if (ZombieALot) {
}
if (UnlinkSymbolsALot) {
}
// do verification AFTER potential deoptimization
if (VerifyStack) {
}
}
};
class VMNativeEntryWrapper {
public:
}
~VMNativeEntryWrapper() {
}
};
#endif
// VM-internal runtime interface support
#ifdef ASSERT
public:
RuntimeHistogramElement(const char* name);
};
if (TraceRuntimeCalls) \
if (CountRuntimeCalls) { \
if (e != NULL) e->increment_count(); \
}
#else
/* do nothing */
#endif
// LEAF routines do not lock, GC or throw exceptions
os::verify_stack_alignment(); \
/* begin of body */
// ENTRY routines may lock, GC and throw exceptions
os::verify_stack_alignment(); \
/* begin of body */
// QUICK_ENTRY routines behave like ENTRY but without a handle mark
os::verify_stack_alignment(); \
/* begin of body */
// Definitions for IRT (Interpreter Runtime)
// (thread is an argument passed in to all these routines)
result_type header { \
result_type header { \
result_type header { \
// Another special case for nmethod_entry_point so the nmethod that the
// interpreter is about to branch to doesn't get flushed before as we
// branch to it's interpreter_entry_point. Skip stress testing here too.
// Also we don't allow async exceptions because it is just too painful.
result_type header { \
#define IRT_END }
result_type header { \
result_type header { \
result_type header { \
// Same as JRT Entry but allows for return value after the safepoint
// to get back into Java from the VM
result_type header { \
#define JRT_BLOCK \
{ \
#define JRT_BLOCK_END }
#define JRT_END }
// Definitions for JNI
extern "C" { \
assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
// Ensure that the VMNativeEntryWrapper constructor, which can cause
// a GC, is called outside the NoHandleMark (set via VM_QUICK_ENTRY_BASE).
extern "C" { \
assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
extern "C" { \
assert( !VerifyJNIEnvThread || (thread == Thread::current()), "JNIEnv is only valid in same thread"); \
// Close the routine and the extern "C"
#define JNI_END } }
// Definitions for JVM
extern "C" { \
extern "C" { \
extern "C" { \
extern "C" { \
VM_Exit::block_if_vm_exited(); \
#define JVM_END } }
#endif // SHARE_VM_RUNTIME_INTERFACESUPPORT_HPP