Skip to content

Commit

Permalink
Fix: gauss-mix and als benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jovanstevanovic authored and vjovanov committed Jul 22, 2021
1 parent b62f483 commit d2544ab
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;

import com.oracle.svm.core.jdk.Package_jdk_internal_reflect;
import org.graalvm.compiler.core.common.NumUtil;
import org.graalvm.nativeimage.StackValue;
import org.graalvm.nativeimage.UnmanagedMemory;
Expand Down Expand Up @@ -943,6 +944,46 @@ private static boolean objectStreamClassConstructor(JNIEnvironment jni, Breakpoi
return true;
}

/**
* In rare occasions, the application can demand custom target constructor for serialization,
* using
* {@link sun.reflect.ReflectionFactory#newConstructorForSerialization(java.lang.Class, java.lang.reflect.Constructor)}
* on JDK8 or
* {@link jdk.internal.reflect.ReflectionFactory#newConstructorForSerialization(java.lang.Class, java.lang.reflect.Constructor)}
* on JDK11. We need to catch constructor class and create entry for that pair (serialization
* class, custom class constructor) in serialization configuration.
*/
private static boolean customTargetConstructorSerialization(JNIEnvironment jni, @SuppressWarnings("unused") Breakpoint bp, InterceptedState state) {
JNIObjectHandle serializeTargetClass = getObjectArgument(1);
String serializeTargetClassName = getClassNameOrNull(jni, serializeTargetClass);

// Skip Lambda class serialization.
if (serializeTargetClassName.contains("$$Lambda$")) {
return true;
}

JNIObjectHandle customConstructorObj = getObjectArgument(2);
JNIObjectHandle customConstructorClass = jniFunctions().getGetObjectClass().invoke(jni, customConstructorObj);
JNIMethodId getDeclaringClassNameMethodID = agent.handles().getJavaLangReflectConstructorDeclaringClassName(jni, customConstructorClass);
JNIObjectHandle declaredClassNameObj = callObjectMethod(jni, customConstructorObj, getDeclaringClassNameMethodID);
String customConstructorClassName = fromJniString(jni, declaredClassNameObj);

if (tracer != null) {
tracer.traceCall("serialization",
"ObjectStreamClass.<init>",
null,
null,
null,
true,
state.getFullStackTraceOrNull(),
/*- String serializationTargetClass, String customTargetConstructorClass */
serializeTargetClassName, customConstructorClassName);

guarantee(!testException(jni));
}
return true;
}

@CEntryPoint
@CEntryPointOptions(prologue = AgentIsolate.Prologue.class)
private static void onBreakpoint(@SuppressWarnings("unused") JvmtiEnv jvmti, JNIEnvironment jni,
Expand Down Expand Up @@ -1241,6 +1282,9 @@ private interface BreakpointHandler {
"(Ljava/lang/ClassLoader;[Ljava/lang/Class;Ljava/lang/reflect/InvocationHandler;)Ljava/lang/Object;", BreakpointInterceptor::newProxyInstance),

brk("java/io/ObjectStreamClass", "<init>", "(Ljava/lang/Class;)V", BreakpointInterceptor::objectStreamClassConstructor),
brk(Package_jdk_internal_reflect.getQualifiedName().replace(".", "/") + "/ReflectionFactory",
"newConstructorForSerialization",
"(Ljava/lang/Class;Ljava/lang/reflect/Constructor;)Ljava/lang/reflect/Constructor;", BreakpointInterceptor::customTargetConstructorSerialization),
optionalBrk("java/util/ResourceBundle",
"getBundleImpl",
"(Ljava/lang/String;Ljava/util/Locale;Ljava/lang/ClassLoader;Ljava/util/ResourceBundle$Control;)Ljava/util/ResourceBundle;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class NativeImageAgentJNIHandleSet extends JNIHandleSet {
private JNIFieldId javaIOObjectStreamClassClassDataSlotDesc;
private JNIFieldId javaIOObjectStreamClassClassDataSlotHasData;

private JNIMethodId javaLangReflectConstructorDeclaringClassName;

NativeImageAgentJNIHandleSet(JNIEnvironment env) {
super(env);
javaLangClass = newClassGlobalRef(env, "java/lang/Class");
Expand Down Expand Up @@ -157,4 +159,11 @@ JNIFieldId getJavaIOObjectStreamClassClassDataSlotHasData(JNIEnvironment env) {
}
return javaIOObjectStreamClassClassDataSlotHasData;
}

JNIMethodId getJavaLangReflectConstructorDeclaringClassName(JNIEnvironment env, JNIObjectHandle customSerializationConstructorClass) {
if (javaLangReflectConstructorDeclaringClassName.equal(nullHandle())) {
javaLangReflectConstructorDeclaringClassName = getMethodId(env, customSerializationConstructorClass, "getName", "()Ljava/lang/String;", false);
}
return javaLangReflectConstructorDeclaringClassName;
}
}

0 comments on commit d2544ab

Please sign in to comment.