Skip to content

Commit c0aa6bf

Browse files
author
Doug Simon
committed
8309390: [JVMCI] improve copying system properties into libgraal
Reviewed-by: never, kvn
1 parent 63843b1 commit c0aa6bf

File tree

19 files changed

+451
-195
lines changed

19 files changed

+451
-195
lines changed

src/hotspot/share/classfile/vmSymbols.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@
754754
do_alias(appendToClassPathForInstrumentation_signature, string_void_signature) \
755755
template(serializePropertiesToByteArray_name, "serializePropertiesToByteArray") \
756756
template(serializeAgentPropertiesToByteArray_name, "serializeAgentPropertiesToByteArray") \
757-
template(serializeSavedPropertiesToByteArray_name, "serializeSavedPropertiesToByteArray") \
758757
template(encodeThrowable_name, "encodeThrowable") \
759758
template(encodeThrowable_signature, "(Ljava/lang/Throwable;JI)I") \
760759
template(decodeAndThrowThrowable_name, "decodeAndThrowThrowable") \

src/hotspot/share/jvmci/jvmciEnv.cpp

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "oops/typeArrayOop.inline.hpp"
3838
#include "prims/jvmtiExport.hpp"
3939
#include "runtime/deoptimization.hpp"
40+
#include "runtime/fieldDescriptor.inline.hpp"
4041
#include "runtime/jniHandles.inline.hpp"
4142
#include "runtime/javaCalls.hpp"
4243
#include "runtime/thread.inline.hpp"
@@ -45,9 +46,6 @@
4546
#include "jvmci/jvmciCompiler.hpp"
4647
#include "jvmci/jvmciRuntime.hpp"
4748

48-
jbyte* JVMCIEnv::_serialized_saved_properties = nullptr;
49-
int JVMCIEnv::_serialized_saved_properties_len = 0;
50-
5149
JVMCICompileState::JVMCICompileState(CompileTask* task, JVMCICompiler* compiler):
5250
_task(task),
5351
_compiler(compiler),
@@ -117,76 +115,6 @@ bool JVMCICompileState::jvmti_state_changed() const {
117115
return false;
118116
}
119117

120-
jbyte* JVMCIEnv::get_serialized_saved_properties(int& props_len, TRAPS) {
121-
jbyte* props = _serialized_saved_properties;
122-
if (props == nullptr) {
123-
// load VMSupport
124-
Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport();
125-
Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK_NULL);
126-
127-
InstanceKlass* ik = InstanceKlass::cast(k);
128-
if (ik->should_be_initialized()) {
129-
ik->initialize(CHECK_NULL);
130-
}
131-
132-
// invoke the serializeSavedPropertiesToByteArray method
133-
JavaValue result(T_OBJECT);
134-
JavaCallArguments args;
135-
136-
Symbol* signature = vmSymbols::void_byte_array_signature();
137-
JavaCalls::call_static(&result,
138-
ik,
139-
vmSymbols::serializeSavedPropertiesToByteArray_name(),
140-
signature,
141-
&args,
142-
CHECK_NULL);
143-
144-
oop res = result.get_oop();
145-
assert(res->is_typeArray(), "must be");
146-
assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "must be");
147-
typeArrayOop ba = typeArrayOop(res);
148-
props_len = ba->length();
149-
150-
// Copy serialized saved properties from HotSpot object into C heap
151-
props = NEW_C_HEAP_ARRAY(jbyte, props_len, mtJVMCI);
152-
memcpy(props, ba->byte_at_addr(0), props_len);
153-
154-
_serialized_saved_properties_len = props_len;
155-
_serialized_saved_properties = props;
156-
} else {
157-
props_len = _serialized_saved_properties_len;
158-
}
159-
return props;
160-
}
161-
162-
void JVMCIEnv::copy_saved_properties(jbyte* properties, int properties_len, JVMCI_TRAPS) {
163-
assert(!is_hotspot(), "can only copy saved properties from HotSpot to native image");
164-
JavaThread* thread = JavaThread::current(); // For exception macros.
165-
166-
// Copy native buffer into shared library object
167-
JVMCIPrimitiveArray buf = new_byteArray(properties_len, this);
168-
if (has_pending_exception()) {
169-
_runtime->fatal_exception(JVMCIENV, "Error in copy_saved_properties");
170-
}
171-
copy_bytes_from(properties, buf, 0, properties_len);
172-
if (has_pending_exception()) {
173-
_runtime->fatal_exception(JVMCIENV, "Error in copy_saved_properties");
174-
}
175-
176-
// Initialize saved properties in shared library
177-
jclass servicesClass = JNIJVMCI::Services::clazz();
178-
jmethodID initializeSavedProperties = JNIJVMCI::Services::initializeSavedProperties_method();
179-
bool exception = false;
180-
{
181-
JNIAccessMark jni(this, thread);
182-
jni()->CallStaticVoidMethod(servicesClass, initializeSavedProperties, buf.as_jobject());
183-
exception = jni()->ExceptionCheck();
184-
}
185-
if (exception) {
186-
_runtime->fatal_exception(JVMCIENV, "Error calling jdk.vm.ci.services.Services.initializeSavedProperties");
187-
}
188-
}
189-
190118
void JVMCIEnv::init_env_mode_runtime(JavaThread* thread, JNIEnv* parent_env, bool jni_enomem_is_fatal) {
191119
assert(thread != nullptr, "npe");
192120
_env = nullptr;
@@ -1937,7 +1865,7 @@ nmethod* JVMCIEnv::get_nmethod(JVMCIObject obj) {
19371865
}
19381866
#define STATIC_INT_FIELD(className, name) STATIC_PRIMITIVE_FIELD(className, name, jint, Int, EMPTY_CAST)
19391867
#define STATIC_BOOLEAN_FIELD(className, name) STATIC_PRIMITIVE_FIELD(className, name, jboolean, Boolean, EMPTY_CAST)
1940-
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName, args)
1868+
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName)
19411869
#define CONSTRUCTOR(className, signature)
19421870

19431871
JVMCI_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, FLOAT_FIELD, OBJECT_FIELD, PRIMARRAY_FIELD, OBJECTARRAY_FIELD, STATIC_OBJECT_FIELD, STATIC_OBJECTARRAY_FIELD, STATIC_INT_FIELD, STATIC_BOOLEAN_FIELD, METHOD, CONSTRUCTOR)

src/hotspot/share/jvmci/jvmciEnv.hpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ class JVMCIEnv : public ResourceObj {
183183
// The translated exception is pending in hotspot_env upon returning.
184184
static void translate_from_jni_exception(JavaThread* THREAD, jthrowable throwable, JVMCIEnv* hotspot_env, JVMCIEnv* jni_env);
185185

186-
// Used by copy_saved_properties() to avoid OutOfMemoryErrors when
187-
// initializing a libjvmci runtime in low HotSpot heap conditions.
188-
// Must hold JVMCI_lock when initializing.
189-
static jbyte* _serialized_saved_properties;
190-
static int _serialized_saved_properties_len;
191-
192186
public:
193187
// Opens a JVMCIEnv scope for a Java to VM call (e.g., via CompilerToVM).
194188
// An exception occurring within the scope is left pending when the
@@ -237,14 +231,6 @@ class JVMCIEnv : public ResourceObj {
237231
return _runtime;
238232
}
239233

240-
// Gets the serialized saved properties from the HotSpot heap.
241-
// The length of the returned array is saved in `len`.
242-
jbyte* get_serialized_saved_properties(int& len, TRAPS);
243-
244-
// Initializes Services.savedProperties in the shared library from the given
245-
// properties in the format produced by `get_serialized_saved_properties`.
246-
void copy_saved_properties(jbyte* properties, int properties_len, JVMCI_TRAPS);
247-
248234
jboolean has_pending_exception();
249235
void clear_pending_exception();
250236

@@ -509,7 +495,7 @@ class JVMCIEnv : public ResourceObj {
509495
#define STATIC_BOOLEAN_FIELD(className, name) STATIC_FIELD(className, name, jboolean)
510496
#define STATIC_OBJECT_FIELD(className, name, signature) STATIC_OOPISH_FIELD(className, name, JVMCIObject, oop)
511497
#define STATIC_OBJECTARRAY_FIELD(className, name, signature) STATIC_OOPISH_FIELD(className, name, JVMCIObjectArray, objArrayOop)
512-
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName, args)
498+
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName)
513499
#define CONSTRUCTOR(className, signature)
514500

515501
JVMCI_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, FLOAT_FIELD, OBJECT_FIELD, PRIMARRAY_FIELD, OBJECTARRAY_FIELD, STATIC_OBJECT_FIELD, STATIC_OBJECTARRAY_FIELD, STATIC_INT_FIELD, STATIC_BOOLEAN_FIELD, METHOD, CONSTRUCTOR)

src/hotspot/share/jvmci/jvmciJavaClasses.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ jmethodID JNIJVMCI::_HotSpotResolvedPrimitiveType_fromMetaspace_method;
151151
#define STATIC_INT_FIELD(className, name) FIELD(className, name, "I", true)
152152
#define STATIC_BOOLEAN_FIELD(className, name) FIELD(className, name, "Z", true)
153153
#ifdef PRODUCT
154-
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName, args)
154+
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName)
155155
#define CONSTRUCTOR(className, signature)
156156
#else
157-
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName, args) \
157+
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName) \
158158
check_resolve_method(#hsCallType, k, vmSymbols::methodName##_name(), vmSymbols::signatureSymbolName(), CHECK);
159159
#define CONSTRUCTOR(className, signature) { \
160160
TempNewSymbol sig = SymbolTable::new_symbol(signature); \
@@ -254,7 +254,7 @@ void HotSpotJVMCI::compute_offsets(TRAPS) {
254254

255255
#define STATIC_INT_FIELD(className, name) STATIC_PRIMITIVE_FIELD(className, name, jint)
256256
#define STATIC_BOOLEAN_FIELD(className, name) STATIC_PRIMITIVE_FIELD(className, name, jboolean)
257-
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName, args)
257+
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName)
258258
#define CONSTRUCTOR(className, signature)
259259

260260
/**
@@ -393,7 +393,7 @@ void JNIJVMCI::initialize_field_id(JNIEnv* env, jfieldID &fieldid, jclass clazz,
393393
#define GET_JNI_CONSTRUCTOR(clazz, signature) \
394394
GET_JNI_METHOD(GetMethodID, JNIJVMCI::clazz::_constructor, clazz::_class, "<init>", signature) \
395395

396-
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName, args) \
396+
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName) \
397397
GET_JNI_METHOD(jniGetMethod, \
398398
className::_##methodName##_method, \
399399
className::clazz(), \
@@ -406,6 +406,7 @@ void JNIJVMCI::initialize_field_id(JNIEnv* env, jfieldID &fieldid, jclass clazz,
406406
extern "C" {
407407
void JNICALL JVM_RegisterJVMCINatives(JNIEnv *env, jclass compilerToVMClass);
408408
jobject JNICALL JVM_GetJVMCIRuntime(JNIEnv *env, jclass c);
409+
jlong JNICALL JVM_ReadSystemPropertiesInfo(JNIEnv *env, jclass c, jintArray offsets_handle);
409410
}
410411

411412
// Dumps symbols for public <init>() and <init>(String) methods of
@@ -565,10 +566,12 @@ static void register_natives_for_class(JNIEnv* env, jclass clazz, const char* na
565566
void JNIJVMCI::register_natives(JNIEnv* env) {
566567
if (env != JavaThread::current()->jni_environment()) {
567568
JNINativeMethod CompilerToVM_nmethods[] = {{ CC"registerNatives", CC"()V", FN_PTR(JVM_RegisterJVMCINatives) }};
568-
JNINativeMethod JVMCI_nmethods[] = {{ CC"initializeRuntime", CC"()Ljdk/vm/ci/runtime/JVMCIRuntime;", FN_PTR(JVM_GetJVMCIRuntime) }};
569+
JNINativeMethod JVMCI_nmethods[] = {{ CC"initializeRuntime", CC"()Ljdk/vm/ci/runtime/JVMCIRuntime;", FN_PTR(JVM_GetJVMCIRuntime) }};
570+
JNINativeMethod Services_nmethods[] = {{ CC"readSystemPropertiesInfo", CC"([I)J", FN_PTR(JVM_ReadSystemPropertiesInfo) }};
569571

570572
register_natives_for_class(env, nullptr, "jdk/vm/ci/hotspot/CompilerToVM", CompilerToVM_nmethods, 1);
571573
register_natives_for_class(env, JVMCI::clazz(), "jdk/vm/ci/runtime/JVMCI", JVMCI_nmethods, 1);
574+
register_natives_for_class(env, Services::clazz(), "jdk/vm/ci/services/Services", Services_nmethods, 1);
572575
}
573576
}
574577

@@ -583,7 +586,7 @@ void JNIJVMCI::register_natives(JNIEnv* env) {
583586
#define FIELD2(className, name) \
584587
jfieldID JNIJVMCI::className::_##name##_field_id = 0; \
585588
int HotSpotJVMCI::className::_##name##_offset = 0;
586-
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName, args)
589+
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName)
587590
#define CONSTRUCTOR(className, signature)
588591

589592
// Generates the definitions of static fields used by the accessors. For example:
@@ -689,7 +692,7 @@ JVMCI_CLASSES_DO(EMPTY2, EMPTY0, FIELD2, FIELD2, FIELD2, FIELD2, FIELD2, FIELD3,
689692

690693
#define STATIC_INT_FIELD(className, name) STATIC_PRIMITIVE_FIELD(className, name, jint, Int, EMPTY_CAST)
691694
#define STATIC_BOOLEAN_FIELD(className, name) STATIC_PRIMITIVE_FIELD(className, name, jboolean, Boolean, EMPTY_CAST)
692-
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName, args) \
695+
#define METHOD(jniCallType, jniGetMethod, hsCallType, returnType, className, methodName, signatureSymbolName) \
693696
jmethodID JNIJVMCI::className::_##methodName##_method;
694697

695698
#define CONSTRUCTOR(className, signature) \

0 commit comments

Comments
 (0)