Skip to content
Permalink
Browse files
8258625: [JVMCI] refactor and unify JVMCI readFieldValue path
Reviewed-by: kvn
  • Loading branch information
Tom Rodriguez committed Apr 26, 2021
1 parent b5c6351 commit 852a41d718bf94ea34f32e4ac71c95b7c082e45e
Showing with 270 additions and 629 deletions.
  1. +116 −144 src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
  2. +6 −52 src/hotspot/share/jvmci/jvmciEnv.cpp
  3. +1 −3 src/hotspot/share/jvmci/jvmciEnv.hpp
  4. +1 −3 src/hotspot/share/jvmci/jvmciJavaClasses.hpp
  5. +2 −6 src/hotspot/share/jvmci/vmSymbols_jvmci.hpp
  6. +8 −49 src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/CompilerToVM.java
  7. +8 −8 ...m.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java
  8. +2 −165 ...dk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJDKReflection.java
  9. +1 −18 ....internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIReflection.java
  10. +55 −117 ....vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotMemoryAccessProviderImpl.java
  11. +10 −1 ...ternal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotObjectConstantImpl.java
  12. +0 −4 ...al.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java
  13. +1 −2 ...nal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java
  14. +0 −54 ...nal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/SharedLibraryJVMCIReflection.java
  15. +23 −0 src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/JavaConstant.java
  16. +24 −1 ...eg/compiler/jvmci/jdk.vm.ci.hotspot.test/src/jdk/vm/ci/hotspot/test/MemoryAccessProviderData.java
  17. +12 −2 ...eg/compiler/jvmci/jdk.vm.ci.hotspot.test/src/jdk/vm/ci/hotspot/test/MemoryAccessProviderTest.java

Large diffs are not rendered by default.

@@ -801,69 +801,23 @@ JVMCIObject JVMCIEnv::call_HotSpotJVMCIRuntime_callToString(JVMCIObject object,
}


JVMCIObject JVMCIEnv::call_PrimitiveConstant_forTypeChar(jchar kind, jlong value, JVMCI_TRAPS) {
JVMCIObject JVMCIEnv::call_JavaConstant_forPrimitive(JVMCIObject kind, jlong value, JVMCI_TRAPS) {
JavaThread* THREAD = JVMCI::compilation_tick(JavaThread::current());
if (is_hotspot()) {
JavaCallArguments jargs;
jargs.push_int(kind);
jargs.push_oop(Handle(THREAD, HotSpotJVMCI::resolve(kind)));
jargs.push_long(value);
JavaValue result(T_OBJECT);
JavaCalls::call_static(&result,
HotSpotJVMCI::PrimitiveConstant::klass(),
vmSymbols::forTypeChar_name(),
vmSymbols::forTypeChar_signature(), &jargs, CHECK_(JVMCIObject()));
return wrap(result.get_oop());
} else {
JNIAccessMark jni(this, THREAD);
jobject result = (jstring) jni()->CallStaticObjectMethod(JNIJVMCI::PrimitiveConstant::clazz(),
JNIJVMCI::PrimitiveConstant::forTypeChar_method(),
kind, value);
if (jni()->ExceptionCheck()) {
return JVMCIObject();
}
return wrap(result);
}
}

JVMCIObject JVMCIEnv::call_JavaConstant_forFloat(float value, JVMCI_TRAPS) {
JavaThread* THREAD = JVMCI::compilation_tick(JavaThread::current());
if (is_hotspot()) {
JavaCallArguments jargs;
jargs.push_float(value);
JavaValue result(T_OBJECT);
JavaCalls::call_static(&result,
HotSpotJVMCI::JavaConstant::klass(),
vmSymbols::forFloat_name(),
vmSymbols::forFloat_signature(), &jargs, CHECK_(JVMCIObject()));
return wrap(result.get_oop());
} else {
JNIAccessMark jni(this, THREAD);
jobject result = (jstring) jni()->CallStaticObjectMethod(JNIJVMCI::JavaConstant::clazz(),
JNIJVMCI::JavaConstant::forFloat_method(),
value);
if (jni()->ExceptionCheck()) {
return JVMCIObject();
}
return wrap(result);
}
}

JVMCIObject JVMCIEnv::call_JavaConstant_forDouble(double value, JVMCI_TRAPS) {
JavaThread* THREAD = JVMCI::compilation_tick(JavaThread::current());
if (is_hotspot()) {
JavaCallArguments jargs;
jargs.push_double(value);
JavaValue result(T_OBJECT);
JavaCalls::call_static(&result,
HotSpotJVMCI::JavaConstant::klass(),
vmSymbols::forDouble_name(),
vmSymbols::forDouble_signature(), &jargs, CHECK_(JVMCIObject()));
vmSymbols::forPrimitive_name(),
vmSymbols::forPrimitive_signature(), &jargs, CHECK_(JVMCIObject()));
return wrap(result.get_oop());
} else {
JNIAccessMark jni(this, THREAD);
jobject result = (jstring) jni()->CallStaticObjectMethod(JNIJVMCI::JavaConstant::clazz(),
JNIJVMCI::JavaConstant::forDouble_method(),
value);
JNIJVMCI::JavaConstant::forPrimitive_method(),
kind.as_jobject(), value);
if (jni()->ExceptionCheck()) {
return JVMCIObject();
}
@@ -307,9 +307,7 @@ class JVMCIEnv : public ResourceObj {

JVMCIObject call_HotSpotJVMCIRuntime_callToString(JVMCIObject object, JVMCI_TRAPS);

JVMCIObject call_PrimitiveConstant_forTypeChar(jchar kind, jlong value, JVMCI_TRAPS);
JVMCIObject call_JavaConstant_forFloat(float value, JVMCI_TRAPS);
JVMCIObject call_JavaConstant_forDouble(double value, JVMCI_TRAPS);
JVMCIObject call_JavaConstant_forPrimitive(JVMCIObject kind, jlong value, JVMCI_TRAPS);

jboolean call_HotSpotJVMCIRuntime_isGCSupported(JVMCIObject runtime, jint gcIdentifier);

@@ -247,15 +247,13 @@
start_class(JavaConstant, jdk_vm_ci_meta_JavaConstant) \
static_object_field(JavaConstant, ILLEGAL, "Ljdk/vm/ci/meta/PrimitiveConstant;") \
static_object_field(JavaConstant, NULL_POINTER, "Ljdk/vm/ci/meta/JavaConstant;") \
jvmci_method(CallStaticObjectMethod, GetStaticMethodID, call_static, JVMCIObject, JavaConstant, forFloat, forFloat_signature, (JVMCIObject kind, jlong value, JVMCI_TRAPS)) \
jvmci_method(CallStaticObjectMethod, GetStaticMethodID, call_static, JVMCIObject, JavaConstant, forDouble, forDouble_signature, (JVMCIObject kind, jlong value, JVMCI_TRAPS)) \
jvmci_method(CallStaticObjectMethod, GetStaticMethodID, call_static, JVMCIObject, JavaConstant, forPrimitive, forPrimitive_signature, (JVMCIObject kind, jlong value, JVMCI_TRAPS)) \
end_class \
start_class(ResolvedJavaMethod, jdk_vm_ci_meta_ResolvedJavaMethod) \
end_class \
start_class(PrimitiveConstant, jdk_vm_ci_meta_PrimitiveConstant) \
object_field(PrimitiveConstant, kind, "Ljdk/vm/ci/meta/JavaKind;") \
long_field(PrimitiveConstant, primitive) \
jvmci_method(CallStaticObjectMethod, GetStaticMethodID, call_static, JVMCIObject, PrimitiveConstant, forTypeChar, forTypeChar_signature, (JVMCIObject kind, jlong value, JVMCI_TRAPS)) \
end_class \
start_class(RawConstant, jdk_vm_ci_meta_RawConstant) \
end_class \
@@ -125,12 +125,8 @@
template(callToString_signature, "(Ljava/lang/Object;)Ljava/lang/String;") \
template(getName_name, "getName") \
template(bootstrapFinished_name, "bootstrapFinished") \
template(forTypeChar_name, "forTypeChar") \
template(forTypeChar_signature, "(CJ)Ljdk/vm/ci/meta/PrimitiveConstant;") \
template(forFloat_name, "forFloat") \
template(forFloat_signature, "(F)Ljdk/vm/ci/meta/PrimitiveConstant;") \
template(forDouble_name, "forDouble") \
template(forDouble_signature, "(D)Ljdk/vm/ci/meta/PrimitiveConstant;") \
template(forPrimitive_name, "forPrimitive") \
template(forPrimitive_signature, "(Ljdk/vm/ci/meta/JavaKind;J)Ljdk/vm/ci/meta/PrimitiveConstant;") \
template(method_string_bool_long_signature, "(Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;Ljava/lang/String;ZJ)V") \
template(initializeSavedProperties_name, "initializeSavedProperties") \

@@ -512,19 +512,6 @@ public static CompilerToVM compilerToVM() {
*/
native long getLocalVariableTableStart(HotSpotResolvedJavaMethodImpl method);

/**
* Reads an object pointer within a VM data structure. That is, any {@link VMField} whose
* {@link VMField#type type} is {@code "oop"} (e.g., {@code Klass::_java_mirror},
* {@code JavaThread::_threadObj}).
*
* Note that {@code Unsafe.getObject(Object, long)} cannot be used for this since it does a
* {@code narrowOop} read if the VM is using compressed oops whereas oops within VM data
* structures are (currently) always uncompressed.
*
* @param address address of an oop field within a VM data structure
*/
native HotSpotObjectConstantImpl readUncompressedOop(long address);

/**
* Sets flags on {@code method} indicating that it should never be inlined or compiled by the
* VM.
@@ -741,13 +728,6 @@ HotSpotResolvedObjectTypeImpl getResolvedJavaType(long displacement, boolean com
*/
native HotSpotResolvedObjectTypeImpl getHostClass(HotSpotResolvedObjectTypeImpl type);

/**
* Gets the object at the address {@code oopAddress}.
*
* @param oopAddress a valid {@code oopDesc**} value
*/
native Object getObjectAtAddress(long oopAddress);

/**
* @see ResolvedJavaType#getInterfaces()
*/
@@ -807,14 +787,18 @@ HotSpotResolvedObjectTypeImpl getResolvedJavaType(long displacement, boolean com
native ResolvedJavaMethod[] getDeclaredMethods(HotSpotResolvedObjectTypeImpl holder);

/**
* Reads the current value of a static field.
* Reads the current value of a static field. If {@code expectedType} is non-null, then the
* object is exptected to be a subtype of {@code expectedType} and extra sanity checking is
* performed on the offset and kind of the read being performed.
*/
native JavaConstant readFieldValue(HotSpotResolvedObjectTypeImpl resolvedObjectType, HotSpotResolvedJavaField field, boolean isVolatile);
native JavaConstant readFieldValue(HotSpotResolvedObjectTypeImpl object, HotSpotResolvedObjectTypeImpl expectedType, long offset, boolean isVolatile, JavaKind kind);

/**
* Reads the current value of an instance field.
* Reads the current value of an instance field. If {@code expectedType} is non-null, then the
* object is exptected to be a subtype of {@code expectedType} and extra sanity checking is
* performed on the offset and kind of the read being performed.
*/
native JavaConstant readFieldValue(HotSpotObjectConstantImpl object, HotSpotResolvedJavaField field, boolean isVolatile);
native JavaConstant readFieldValue(HotSpotObjectConstantImpl object, HotSpotResolvedObjectTypeImpl expectedType, long offset, boolean isVolatile, JavaKind kind);

/**
* @see ResolvedJavaType#isInstance(JavaConstant)
@@ -858,31 +842,6 @@ HotSpotResolvedObjectTypeImpl getResolvedJavaType(long displacement, boolean com
*/
native Object readArrayElement(HotSpotObjectConstantImpl object, int index);

/**
* Reads a byte sized value from {@code displacement} in {@code object}.
*/
native byte getByte(HotSpotObjectConstantImpl object, long displacement);

/**
* Reads a short sized value from {@code displacement} in {@code object}.
*/
native short getShort(HotSpotObjectConstantImpl object, long displacement);

/**
* Reads an int sized value from {@code displacement} in {@code object}.
*/
native int getInt(HotSpotObjectConstantImpl object, long displacement);

/**
* Reads a long sized value from {@code displacement} in {@code object}.
*/
native long getLong(HotSpotObjectConstantImpl object, long displacement);

/**
* Reads a Java object from {@code displacement} in {@code object}.
*/
native HotSpotObjectConstantImpl getObject(HotSpotObjectConstantImpl object, long displacement);

/**
* @see HotSpotJVMCIRuntime#registerNativeMethods
*/
@@ -22,6 +22,8 @@
*/
package jdk.vm.ci.hotspot;

import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;

import java.util.Objects;

import jdk.vm.ci.common.JVMCIError;
@@ -164,15 +166,13 @@ public JavaConstant readFieldValue(ResolvedJavaField field, JavaConstant receive
if (hotspotField.isStatic()) {
HotSpotResolvedObjectTypeImpl holder = (HotSpotResolvedObjectTypeImpl) hotspotField.getDeclaringClass();
if (holder.isInitialized()) {
return holder.readFieldValue(hotspotField, field.isVolatile());
}
} else {
if (receiver.isNonNull() && receiver instanceof HotSpotObjectConstantImpl) {
HotSpotObjectConstantImpl object = ((HotSpotObjectConstantImpl) receiver);
if (hotspotField.isInObject(receiver)) {
return object.readFieldValue(hotspotField, field.isVolatile());
}
return runtime().compilerToVm.readFieldValue(holder, (HotSpotResolvedObjectTypeImpl) hotspotField.getDeclaringClass(), hotspotField.getOffset(), field.isVolatile(),
hotspotField.getType().getJavaKind());
}
} else if (receiver instanceof HotSpotObjectConstantImpl) {
return ((HotSpotObjectConstantImpl) receiver).readFieldValue(hotspotField, field.isVolatile());
} else if (receiver == null) {
throw new NullPointerException("receiver is null");
}
return null;
}

1 comment on commit 852a41d

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 852a41d Apr 26, 2021

Please sign in to comment.