Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: gauss-mix and als benchmarks. #3581

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,45 @@ private static boolean objectStreamClassConstructor(JNIEnvironment jni, Breakpoi
return true;
}

/*
* In rare occasions, the application can demand custom target constructor for serialization,
* using (see sun.reflect.ReflectionFactory#newConstructorForSerialization(java.lang.Class,
* java.lang.reflect.Constructor)) on JDK8 or (see
* 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a comment here explaining what we catch and what we output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provided a short description.

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 +1281,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;
}
}