/* * Copyright (c) 1999, 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. *
*/
// Helper to log more context on a JNI exception #define JVMCI_EXCEPTION_CHECK(env, ...) \ do { \ if (env->ExceptionCheck()) { \ if (env != JavaThread::current()->jni_environment()) { \ char* sl_path; \ if (::JVMCI::get_shared_library(sl_path, false) != NULL) { \
tty->print_cr("In JVMCI shared library (%s):", sl_path); \
} \
} \
tty->print_cr(__VA_ARGS__); \ return; \
} \
} while(0)
// Helper class to ensure that references to Klass* are kept alive for G1 class JVMCIKlassHandle : public StackObj { private:
Klass* _klass;
Handle _holder;
Thread* _thread;
// A class that maintains the state needed for compilations requested // by the CompileBroker. It is created in the broker and passed through // into the code installation step. class JVMCICompileState : public ResourceObj { friendclass JVMCIVMStructs; private:
CompileTask* _task;
JVMCICompiler* _compiler;
// Cache JVMTI state. Defined as bytes so that reading them from Java // via Unsafe is well defined (the C++ type for bool is implementation // defined and may not be the same as a Java boolean).
uint64_t _jvmti_redefinition_count;
jbyte _jvmti_can_hotswap_or_post_breakpoint;
jbyte _jvmti_can_access_local_variables;
jbyte _jvmti_can_post_on_exceptions;
jbyte _jvmti_can_pop_frame; bool _target_method_is_old;
// Compilation result values. bool _retryable; constchar* _failure_reason;
// Specifies if _failure_reason is on the C heap. If so, it is allocated // with the mtJVMCI NMT flag. bool _failure_reason_on_C_heap;
// A value indicating compilation activity during the compilation. // If successive calls to this method return a different value, then // some degree of JVMCI compilation occurred between the calls.
jint _compilation_ticks;
// This class is a top level wrapper around interactions between HotSpot // and the JVMCI Java code. It supports both a HotSpot heap based // runtime with HotSpot oop based accessors as well as a shared library // based runtime that is accessed through JNI. It abstracts away all // interactions with JVMCI objects so that a single version of the // HotSpot C++ code can can work with either runtime. class JVMCIEnv : public ResourceObj { friendclass JNIAccessMark;
// Initializes the _env, _mode and _runtime fields. void init_env_mode_runtime(JavaThread* thread, JNIEnv* parent_env, bool attach_OOME_is_fatal = true);
void init(JavaThread* thread, bool is_hotspot, constchar* file, int line);
JNIEnv* _env; // JNI env for calling into shared library bool _pop_frame_on_close; // Must pop frame on close? bool _detach_on_close; // Must detach on close?
JVMCIRuntime* _runtime; // Access to a HotSpotJVMCIRuntime bool _is_hotspot; // Which heap is the HotSpotJVMCIRuntime in bool _throw_to_caller; // Propagate an exception raised in this env to the caller? constchar* _file; // The file and ... int _line; // ... line where this JNIEnv was created bool _attach_threw_OOME; // Failed to attach thread due to OutOfMemoryError, the JVMCIEnv is invalid
// Translates an exception on the HotSpot heap (i.e., hotspot_env) to an exception on // the shared library heap (i.e., jni_env). The translation includes the stack and cause(s) of `throwable`. // The translated exception is pending in jni_env upon returning. staticvoid translate_to_jni_exception(JavaThread* THREAD, const Handle& throwable, JVMCIEnv* hotspot_env, JVMCIEnv* jni_env);
// Translates an exception on the shared library heap (i.e., jni_env) to an exception on // the HotSpot heap (i.e., hotspot_env). The translation includes the stack and cause(s) of `throwable`. // The translated exception is pending in hotspot_env upon returning. staticvoid translate_from_jni_exception(JavaThread* THREAD, jthrowable throwable, JVMCIEnv* hotspot_env, JVMCIEnv* jni_env);
// Used by copy_saved_properties() to avoid OutOfMemoryErrors when // initializing a libjvmci runtime in low HotSpot heap conditions. // Must hold JVMCI_lock when initializing. static jbyte* _serialized_saved_properties; staticint _serialized_saved_properties_len;
public: // Opens a JVMCIEnv scope for a Java to VM call (e.g., via CompilerToVM). // An exception occurring within the scope is left pending when the // scope closes so that it will be propagated back to Java. // The JVMCIEnv destructor translates the exception object for the // Java runtime if necessary.
JVMCIEnv(JavaThread* thread, JNIEnv* env, constchar* file, int line);
// Opens a JVMCIEnv scope for a compilation scheduled by the CompileBroker. // An exception occurring within the scope must not be propagated back to // the CompileBroker.
JVMCIEnv(JavaThread* thread, JVMCICompileState* compile_state, constchar* file, int line);
// Opens a JNIEnv scope for a call from within the VM. An exception occurring // within the scope must not be propagated back to the caller.
JVMCIEnv(JavaThread* env, constchar* file, int line);
// Opens a JNIEnv scope for accessing `for_object`. An exception occurring // within the scope must not be propagated back to the caller.
JVMCIEnv(JavaThread* thread, JVMCIObject for_object, constchar* file, int line) { // A JNI call to access an object in the shared library heap // can block or take a long time so do not allow such access // on the VM thread.
assert(for_object.is_hotspot() || !Thread::current()->is_VM_thread(), "cannot open JVMCIEnv scope when in the VM thread for accessing a shared library heap object");
init(thread, for_object.is_hotspot(), file, line);
}
// Opens a JNIEnv scope for the HotSpot runtime if `is_hotspot` is true // otherwise for the shared library runtime. An exception occurring // within the scope must not be propagated back to the caller.
JVMCIEnv(JavaThread* thread, bool is_hotspot, constchar* file, int line) {
init(thread, is_hotspot, file, line);
}
~JVMCIEnv();
JVMCIRuntime* runtime() { return _runtime;
}
// Gets the serialized saved properties from the HotSpot heap. // The length of the returned array is saved in `len`.
jbyte* get_serialized_saved_properties(int& len, TRAPS);
// Initializes Services.savedProperties in the shared library from the given // properties in the format produced by `get_serialized_saved_properties`. void copy_saved_properties(jbyte* properties, int properties_len, JVMCI_TRAPS);
// If this env has a pending exception, it is translated to be a pending // exception in `peer_env` and is cleared from this env. Returns true // if a pending exception was transferred, false otherwise.
jboolean transfer_pending_exception(JavaThread* THREAD, JVMCIEnv* peer_env);
// If there is a pending HotSpot exception, clears it and translates it to the shared library heap. // The translated exception is pending in the shared library upon returning. // Returns true if a pending exception was transferred, false otherwise. static jboolean transfer_pending_exception_to_jni(JavaThread* THREAD, JVMCIEnv* hotspot_env, JVMCIEnv* jni_env);
// Prints an exception and stack trace of a pending exception. void describe_pending_exception(bool clear);
int get_length(JVMCIArray array);
JVMCIObject get_object_at(JVMCIObjectArray array, int index); void put_object_at(JVMCIObjectArray array, int index, JVMCIObject value);
jboolean get_bool_at(JVMCIPrimitiveArray array, int index); void put_bool_at(JVMCIPrimitiveArray array, int index, jboolean value);
jbyte get_byte_at(JVMCIPrimitiveArray array, int index); void put_byte_at(JVMCIPrimitiveArray array, int index, jbyte value);
jint get_int_at(JVMCIPrimitiveArray array, int index); void put_int_at(JVMCIPrimitiveArray array, int index, jint value);
jlong get_long_at(JVMCIPrimitiveArray array, int index); void put_long_at(JVMCIPrimitiveArray array, int index, jlong value);
void copy_bytes_to(JVMCIPrimitiveArray src, jbyte* dest, int offset, jsize length); void copy_bytes_from(jbyte* src, JVMCIPrimitiveArray dest, int offset, jsize length);
void copy_longs_from(jlong* src, JVMCIPrimitiveArray dest, int offset, jsize length);
// Get the primitive value from a Java boxing object. It's hard error to // pass a non-primitive BasicType.
jvalue get_boxed_value(BasicType type, JVMCIObject object);
// Return the BasicType of the object if it's a boxing object, otherwise return T_ILLEGAL.
BasicType get_box_type(JVMCIObject object);
// Create a boxing object of the appropriate primitive type.
JVMCIObject create_box(BasicType type, jvalue* value, JVMCI_TRAPS);
public: // Compiles a method with the JVMCI compiler. // Caller must handle pending exception.
JVMCIObject call_HotSpotJVMCIRuntime_compileMethod(JVMCIObject runtime, JVMCIObject method, int entry_bci,
jlong compile_state, int id);
// Unpack an instance of HotSpotConstantPool into the original ConstantPool*
ConstantPool* asConstantPool(JVMCIObject constant_pool);
ConstantPool* asConstantPool(jobject constant_pool) { return asConstantPool(wrap(constant_pool)); }
// Makes a handle to a HotSpot heap object. These handles are // individually reclaimed by JVMCIRuntime::destroy_oop_handle and // bulk reclaimed by JVMCIRuntime::release_and_clear_globals.
jlong make_oop_handle(const Handle& obj);
oop resolve_oop_handle(jlong oopHandle);
// These are analogous to the JNI routines
JVMCIObject make_local(JVMCIObject object); void destroy_local(JVMCIObject object);
// Makes a JNI global handle that is not scoped by the // lifetime of a JVMCIRuntime (cf JVMCIRuntime::make_global). // These JNI handles are used when translating an object // between the HotSpot and JVMCI shared library heap via // HotSpotJVMCIRuntime.translate(Object) and // HotSpotJVMCIRuntime.unhand(Class<T>, long). Translation // can happen in either direction so the referenced object // can reside in either heap which is why JVMCIRuntime scoped // handles cannot be used (they are specific to HotSpot heap objects).
JVMCIObject make_global(JVMCIObject object);
// Destroys a JNI global handle created by JVMCIEnv::make_global. void destroy_global(JVMCIObject object);
// Updates the nmethod (if any) in the HotSpotNmethod.address // field of `mirror` to prevent it from being called. // If `deoptimize` is true, the nmethod is immediately deoptimized. // The HotSpotNmethod.address field is zero upon returning. void invalidate_nmethod_mirror(JVMCIObject mirror, bool deoptimze, JVMCI_TRAPS);
// Determines if this is for the JVMCI runtime in the HotSpot // heap (true) or the shared library heap (false). bool is_hotspot() { return _is_hotspot; }
JVMCICompileState* compile_state() { return _compile_state; } void set_compile_state(JVMCICompileState* compile_state) {
assert(_compile_state == NULL, "set only once");
_compile_state = compile_state;
} // Generate declarations for the initialize, new, isa, get and set methods for all the types and // fields declared in the JVMCI_CLASSES_DO macro.
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.