/* * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * 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.
*/
class JVMCIEnv; class JVMCICompiler; class JVMCICompileState; class MetadataHandles;
// Encapsulates the JVMCI metadata for an nmethod. // JVMCINMethodData objects are inlined into nmethods // at nmethod::_jvmci_data_offset. class JVMCINMethodData { friendclass JVMCIVMStructs; // Index for the HotSpotNmethod mirror in the nmethod's oops table. // This is -1 if there is no mirror in the oops table. int _nmethod_mirror_index;
// Is HotSpotNmethod.name non-null? If so, the value is // embedded in the end of this object. bool _has_name;
// Address of the failed speculations list to which a speculation // is appended when it causes a deoptimization.
FailedSpeculation** _failed_speculations;
// A speculation id is a length (low 5 bits) and an index into // a jbyte array (i.e. 31 bits for a positive Java int). enum { // Keep in sync with HotSpotSpeculationEncoding.
SPECULATION_LENGTH_BITS = 5,
SPECULATION_LENGTH_MASK = (1 << SPECULATION_LENGTH_BITS) - 1
};
public: // Computes the size of a JVMCINMethodData object staticint compute_size(constchar* nmethod_mirror_name) { int size = sizeof(JVMCINMethodData); if (nmethod_mirror_name != NULL) {
size += (int) strlen(nmethod_mirror_name) + 1;
} return size;
}
// Adds `speculation` to the failed speculations list. void add_failed_speculation(nmethod* nm, jlong speculation);
// Gets the JVMCI name of the nmethod (which may be NULL). constchar* name() { return _has_name ? (char*)(((address) this) + sizeof(JVMCINMethodData)) : NULL; }
// Clears the HotSpotNmethod.address field in the mirror. If nm // is dead, the HotSpotNmethod.entryPoint field is also cleared. void invalidate_nmethod_mirror(nmethod* nm);
// Gets the mirror from nm's oops table.
oop get_nmethod_mirror(nmethod* nm, bool phantom_ref);
// Sets the mirror in nm's oops table. void set_nmethod_mirror(nmethod* nm, oop mirror);
};
// A top level class that represents an initialized JVMCI runtime. // There is one instance of this class per HotSpotJVMCIRuntime object. class JVMCIRuntime: public CHeapObj<mtJVMCI> { friendclass JVMCI; friendclass JavaVMRefsInitialization; public: // Constants describing whether JVMCI wants to be able to adjust the compilation // level selected for a method by the VM compilation policy and if so, based on // what information about the method being schedule for compilation. enum CompLevelAdjustment {
none = 0, // no adjustment
by_holder = 1, // adjust based on declaring class of method
by_full_signature = 2 // adjust based on declaring class, name and signature of method
};
// Initialization state of this JVMCIRuntime.
InitState _init_state;
// Initialization state of the references to classes, methods // and fields in the JVMCI shared library. static InitState _shared_library_javavm_refs_init_state;
// Initialization state of the references to classes, methods // and fields in HotSpot metadata. static InitState _hotspot_javavm_refs_init_state;
// A wrapper for a VM scoped JNI global handle (i.e. JVMCIEnv::make_global) // to a HotSpotJVMCIRuntime instance. This JNI global handle must never // be explicitly destroyed as it can be accessed in a racy way during // JVMCI shutdown. Furthermore, it will be reclaimed when // the VM or shared library JavaVM managing the handle dies.
JVMCIObject _HotSpotJVMCIRuntime_instance;
// Lock for operations that may be performed by // any thread attached this runtime. To avoid deadlock, // this lock must always be acquired before JVMCI_lock.
Monitor* _lock;
// Result of calling JNI_CreateJavaVM in the JVMCI shared library. // Must only be mutated under _lock.
JavaVM* _shared_library_javavm;
// Id for _shared_library_javavm. int _shared_library_javavm_id;
// Position and link in global list of JVMCI shared library runtimes. // The HotSpot heap based runtime will have an id of -1 and the // runtime reserved for threads attaching during JVMCI shutdown // will have an id of -2. int _id;
JVMCIRuntime* _next;
// Handles to Metadata objects.
MetadataHandles* _metadata_handles;
// List of oop handles allocated via make_oop_handle. This is to support // destroying remaining oop handles when the JavaVM associated // with this runtime is shutdown.
GrowableArray<oop*> _oop_handles;
// Number of threads attached or about to be attached to this runtime. // Must only be mutated under JVMCI_lock to facilitate safely moving // threads between JVMCI runtimes. A value of -1 implies this runtime is // not available to be attached to another thread because it is in the // process of shutting down and destroying its JavaVM. int _num_attached_threads; staticconstint cannot_be_attached = -1;
// Is this runtime for threads managed by the CompileBroker? // Examples of non-CompileBroker threads are CompileTheWorld threads // or Truffle compilation threads. bool _for_compile_broker;
// Selects an existing runtime (except for `skip`) that has // fewer than JVMCI::max_threads_per_runtime() attached threads. // If such a runtime exists, its _num_attached_threads is incremented // and the caller must subsequently attach `thread` to it. // JVMCI_lock must be held by current thread. // If nullptr is returned, then `*count` contains the number of JVMCIRuntimes // currently allocated. static JVMCIRuntime* select_runtime(JavaThread* thread, JVMCIRuntime* skip, int* count);
// Selects an existing runtime for `thread` or creates a new one if // no applicable runtime exists. // JVMCI_lock must be held by current thread static JVMCIRuntime* select_or_create_runtime(JavaThread* thread);
// Selects an existing runtime for `thread` when in JVMCI shutdown. // JVMCI_lock must be held by current thread static JVMCIRuntime* select_runtime_in_shutdown(JavaThread* thread);
// Releases all the non-null entries in _oop_handles and then clears // the list. Returns the number released handles. int release_and_clear_oop_handles();
public:
JVMCIRuntime(JVMCIRuntime* next, int id, bool for_compile_broker);
// Ensures that a JVMCI shared library JavaVM exists for this runtime. // If the JavaVM was created by this call, then the thread-local JNI // interface pointer for the JavaVM is returned otherwise nullptr is returned.
JNIEnv* init_shared_library_javavm();
// Determines if the JVMCI shared library JavaVM exists for this runtime. bool has_shared_library_javavm() { return _shared_library_javavm != nullptr; }
// Gets an ID for the JVMCI shared library JavaVM associated with this runtime. int get_shared_library_javavm_id() { return _shared_library_javavm_id; }
// Copies info about the JVMCI shared library JavaVM associated with this // runtime into `info` as follows: // { // javaVM, // the {@code JavaVM*} value // javaVM->functions->reserved0, // javaVM->functions->reserved1, // javaVM->functions->reserved2 // } void init_JavaVM_info(jlongArray info, JVMCI_TRAPS);
// Wrappers for calling Invocation Interface functions on the // JVMCI shared library JavaVM associated with this runtime. // These wrappers ensure all required thread state transitions are performed.
jint AttachCurrentThread(JavaThread* thread, void **penv, void *args);
jint AttachCurrentThreadAsDaemon(JavaThread* thread, void **penv, void *args);
jint DetachCurrentThread(JavaThread* thread);
jint GetEnv(JavaThread* thread, void **penv, jint version);
// Compute offsets and construct any state required before executing JVMCI code. void initialize(JVMCIEnv* jvmciEnv);
// Allocation and management of handles to HotSpot heap objects // whose lifetime is scoped by this JVMCIRuntime. The max lifetime // of these handles is the same as the JVMCI shared library JavaVM // associated with this JVMCIRuntime. These JNI handles are // used when creating an IndirectHotSpotObjectConstantImpl in the // shared library JavaVM.
jlong make_oop_handle(const Handle& obj);
// Releases all the non-null entries in _oop_handles whose referent is null. // Returns the number of handles released by this call. // The method also resets _last_found_oop_handle_index to -1 // and _null_oop_handles to 0. int release_cleared_oop_handles();
// Allocation and management of metadata handles.
jmetadata allocate_handle(const methodHandle& handle);
jmetadata allocate_handle(const constantPoolHandle& handle); void release_handle(jmetadata handle);
// Finds a JVMCI runtime for `thread`. A new JVMCI runtime is created if // there are none currently available with JVMCI::max_threads_per_runtime() // or fewer attached threads. static JVMCIRuntime* for_thread(JavaThread* thread);
// Finds the JVMCI runtime owning `javavm` and attaches `thread` to it. // Returns an error message if attaching fails. staticconstchar* attach_shared_library_thread(JavaThread* thread, JavaVM* javaVM);
// Reserves a slot in this runtime for `thread` to prevent it being // shutdown before `thread` is attached. JVMCI_lock must be held // and the caller must call `attach_thread` upon releasing it. void pre_attach_thread(JavaThread* thread);
// Attaches `thread` to this runtime. void attach_thread(JavaThread* thread);
// Detaches `thread` from this runtime. // Returns whether DestroyJavaVM was called on the JavaVM associated // with this runtime as a result of detaching. // The `can_destroy_javavm` is false when in the scope of // a down call from the JVMCI shared library JavaVM. Since the scope // will return to the shared library JavaVM, the JavaVM must not be destroyed. bool detach_thread(JavaThread* thread, constchar* reason, bool can_destroy_javavm=true);
// If `thread` is the last thread attached to this runtime, // move it to another runtime with an existing JavaVM and available capacity // if possible, thus allowing this runtime to release its JavaVM. void repack(JavaThread* thread);
// Gets the HotSpotJVMCIRuntime instance for this runtime, // initializing it first if necessary.
JVMCIObject get_HotSpotJVMCIRuntime(JVMCI_TRAPS);
// Gets the current HotSpotJVMCIRuntime instance for this runtime which // may be a "null" JVMCIObject value.
JVMCIObject probe_HotSpotJVMCIRuntime() { return _HotSpotJVMCIRuntime_instance;
}
// Trigger initialization of HotSpotJVMCIRuntime through JVMCI.getRuntime() void initialize_JVMCI(JVMCI_TRAPS);
// Shuts down this runtime by calling HotSpotJVMCIRuntime.shutdown(). // If this is the last thread attached to this runtime, then // `_HotSpotJVMCIRuntime_instance` is set to nullptr and `_init_state` // to uninitialized. void shutdown();
// Destroys the JVMCI shared library JavaVM attached to this runtime. // Return true iff DestroyJavaVM was called on the JavaVM. bool destroy_shared_library_javavm();
void bootstrap_finished(TRAPS);
// Look up a klass by name from a particular class loader (the accessor's). // If require_local, result must be defined in that class loader, or NULL. // If !require_local, a result from remote class loader may be reported, // if sufficient class loader constraints exist such that initiating // a class loading request from the given loader is bound to return // the class defined in the remote loader (or throw an error). // // Return an unloaded klass if !require_local and no class at all is found. // // The CI treats a klass as loaded if it is consistently defined in // another loader, even if it hasn't yet been loaded in all loaders // that could potentially see it via delegation. static Klass* get_klass_by_name(Klass* accessing_klass,
Symbol* klass_name, bool require_local);
// Constant pool access. static Klass* get_klass_by_index(const constantPoolHandle& cpool, int klass_index, bool& is_accessible,
Klass* loading_klass); staticvoid get_field_by_index(InstanceKlass* loading_klass, fieldDescriptor& fd, int field_index); static Method* get_method_by_index(const constantPoolHandle& cpool, int method_index, Bytecodes::Code bc,
InstanceKlass* loading_klass);
// converts the Klass* representing the holder of a method into a // InstanceKlass*. This is needed since the holder of a method in // the bytecodes could be an array type. Basically this converts // array types into java/lang/Object and other types stay as they are. static InstanceKlass* get_instance_klass_for_declared_method_holder(Klass* klass);
// Helper routine for determining the validity of a compilation // with respect to concurrent class loading. static JVMCI::CodeInstallResult validate_compile_task_dependencies(Dependencies* target, JVMCICompileState* task, char** failure_detail);
// Compiles `target` with the JVMCI compiler. void compile_method(JVMCIEnv* JVMCIENV, JVMCICompiler* compiler, const methodHandle& target, int entry_bci);
// Determines if the GC identified by `name` is supported by the JVMCI compiler. bool is_gc_supported(JVMCIEnv* JVMCIENV, CollectedHeap::Name name);
// Register the result of a compilation.
JVMCI::CodeInstallResult register_method(JVMCIEnv* JVMCIENV, const methodHandle& target,
nmethod*& nm, int entry_bci,
CodeOffsets* offsets, int orig_pc_offset,
CodeBuffer* code_buffer, int frame_words,
OopMapSet* oop_map_set,
ExceptionHandlerTable* handler_table,
ImplicitExceptionTable* implicit_exception_table,
AbstractCompiler* compiler,
DebugInformationRecorder* debug_info,
Dependencies* dependencies, int compile_id, bool has_monitors, bool has_unsafe_access, bool has_wide_vector,
JVMCIObject compiled_code,
JVMCIObject nmethod_mirror,
FailedSpeculation** failed_speculations, char* speculations, int speculations_len);
// Detach `thread` from this runtime and destroy this runtime's JavaVM // if using one JavaVM per JVMCI compilation . void post_compile(JavaThread* thread);
// Reports an unexpected exception and exits the VM with a fatal error. staticvoid fatal_exception(JVMCIEnv* JVMCIENV, constchar* message);
// The following routines are called from compiled JVMCI code
// When allocation fails, these stubs: // 1. Exercise -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError handling and also // post a JVMTI_EVENT_RESOURCE_EXHAUSTED event if the failure is an OutOfMemroyError // 2. Return NULL with a pending exception. // Compiled code must ensure these stubs are not called twice for the same allocation // site due to the non-repeatable side effects in the case of OOME. staticvoid new_instance(JavaThread* current, Klass* klass) { new_instance_common(current, klass, false); } staticvoid new_array(JavaThread* current, Klass* klass, jint length) { new_array_common(current, klass, length, false); } staticvoid new_multi_array(JavaThread* current, Klass* klass, int rank, jint* dims) { new_multi_array_common(current, klass, rank, dims, false); } staticvoid dynamic_new_array(JavaThread* current, oopDesc* element_mirror, jint length) { dynamic_new_array_common(current, element_mirror, length, false); } staticvoid dynamic_new_instance(JavaThread* current, oopDesc* type_mirror) { dynamic_new_instance_common(current, type_mirror, false); }
// When allocation fails, these stubs return NULL and have no pending exception. Compiled code // can use these stubs if a failed allocation will be retried (e.g., by deoptimizing and // re-executing in the interpreter). staticvoid new_instance_or_null(JavaThread* thread, Klass* klass) { new_instance_common(thread, klass, true); } staticvoid new_array_or_null(JavaThread* thread, Klass* klass, jint length) { new_array_common(thread, klass, length, true); } staticvoid new_multi_array_or_null(JavaThread* thread, Klass* klass, int rank, jint* dims) { new_multi_array_common(thread, klass, rank, dims, true); } staticvoid dynamic_new_array_or_null(JavaThread* thread, oopDesc* element_mirror, jint length) { dynamic_new_array_common(thread, element_mirror, length, true); } staticvoid dynamic_new_instance_or_null(JavaThread* thread, oopDesc* type_mirror) { dynamic_new_instance_common(thread, type_mirror, true); }
staticvoid vm_message(jboolean vmError, jlong format, jlong v1, jlong v2, jlong v3); static jint identity_hash_code(JavaThread* current, oopDesc* obj); static address exception_handler_for_pc(JavaThread* current); staticvoid monitorenter(JavaThread* current, oopDesc* obj, BasicLock* lock); staticvoid monitorexit (JavaThread* current, oopDesc* obj, BasicLock* lock); static jboolean object_notify(JavaThread* current, oopDesc* obj); static jboolean object_notifyAll(JavaThread* current, oopDesc* obj); staticvoid vm_error(JavaThread* current, jlong where, jlong format, jlong value); static oopDesc* load_and_clear_exception(JavaThread* thread); staticvoid log_printf(JavaThread* thread, constchar* format, jlong v1, jlong v2, jlong v3); staticvoid log_primitive(JavaThread* thread, jchar typeChar, jlong value, jboolean newline); // Print the passed in object, optionally followed by a newline. If // as_string is true and the object is a java.lang.String then it // printed as a string, otherwise the type of the object is printed // followed by its address. staticvoid log_object(JavaThread* thread, oopDesc* object, bool as_string, bool newline); #if INCLUDE_G1GC using CardValue = G1CardTable::CardValue; staticvoid write_barrier_pre(JavaThread* thread, oopDesc* obj); staticvoid write_barrier_post(JavaThread* thread, volatile CardValue* card); #endif static jboolean validate_object(JavaThread* thread, oopDesc* parent, oopDesc* child);
// used to throw exceptions from compiled JVMCI code staticint throw_and_post_jvmti_exception(JavaThread* current, constchar* exception, constchar* message); // helper methods to throw exception with complex messages staticint throw_klass_external_name_exception(JavaThread* current, constchar* exception, Klass* klass); staticint throw_class_cast_exception(JavaThread* current, constchar* exception, Klass* caster_klass, Klass* target_klass);
// A helper to allow invocation of an arbitrary Java method. For simplicity the method is // restricted to a static method that takes at most one argument. For calling convention // simplicity all types are passed by being converted into a jlong static jlong invoke_static_method_one_arg(JavaThread* current, Method* method, jlong argument);
// Test only function static jint test_deoptimize_call_int(JavaThread* current, int value);
}; #endif// SHARE_JVMCI_JVMCIRUNTIME_HPP
Messung V0.5
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.