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

8305104: Remove the old core reflection implementation #14371

Closed
wants to merge 12 commits into from
3 changes: 0 additions & 3 deletions src/hotspot/share/classfile/verifier.cpp
Original file line number Diff line number Diff line change
@@ -293,9 +293,6 @@ bool Verifier::is_eligible_for_verification(InstanceKlass* klass, bool should_ve
// As of the fix for 4486457 we disable verification for all of the
// dynamically-generated bytecodes associated with
// jdk/internal/reflect/SerializationConstructorAccessor.
// NOTE: this is called too early in the bootstrapping process to be
// guarded by Universe::is_gte_jdk14x_version().
// Also for lambda generated code, gte jdk8
(!is_reflect_accessor));
}

Original file line number Diff line number Diff line change
@@ -303,6 +303,17 @@ static void ensureClassInitialized(Class<?> defc) {

/*
* Returns true if NativeAccessor should be used.
*
* Native accessor, i.e. VM reflection implementation, is used if one of
* the following conditions is met:
* 1. during VM early startup and method handle support is fully initialized
* 2. a Java native method
* 3. -Djdk.reflect.useNativeAccessorOnly=true is set
* 4. the member takes a variable number of arguments and the last parameter
* is an array (see details below)
* 5. the member's method type has an arity >= 255

Choose a reason for hiding this comment

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

Suggested change
* 1. during VM early startup and method handle support is fully initialized
* 2. a Java native method
* 3. -Djdk.reflect.useNativeAccessorOnly=true is set
* 4. the member takes a variable number of arguments and the last parameter
* is an array (see details below)
* 5. the member's method type has an arity >= 255
* 1. during VM early startup before method handle support is fully initialized
* 2. a Java native method
* 3. -Djdk.reflect.useNativeAccessorOnly=true is set
* 4. the member takes a variable number of arguments and the last parameter
* is not an array (see details below)
* 5. the member's method type has an arity >= 255

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. Thanks.

*
* Otherwise, direct invocation of method handles is used.
*/
private static boolean useNativeAccessor(Executable member) {
if (!VM.isJavaLangInvokeInited())
Original file line number Diff line number Diff line change
@@ -540,6 +540,10 @@ public final Constructor<OptionalDataException> newOptionalDataExceptionForSeria
// Internals only below this point
//

/*
* If -Djdk.reflect.useNativeAccessorOnly is set, use the native accessor only.
* For testing purpose only.
*/
static boolean useNativeAccessorOnly() {
return config().useNativeAccessorOnly;
}
@@ -548,11 +552,6 @@ private static boolean disableSerialConstructorChecks() {
return config().disableSerialConstructorChecks;
}

// New implementation uses direct invocation of method handles
private static final int METHOD_MH_ACCESSOR = 0x1;
private static final int FIELD_MH_ACCESSOR = 0x2;
private static final int ALL_MH_ACCESSORS = METHOD_MH_ACCESSOR | FIELD_MH_ACCESSOR;

/**
* The configuration is lazily initialized after the module system is initialized. The
* default config would be used before the proper config is loaded.
@@ -564,17 +563,6 @@ private static boolean disableSerialConstructorChecks() {
*/
private static @Stable Config config;

// "Inflation" mechanism. Loading bytecodes to implement
// Method.invoke() and Constructor.newInstance() currently costs
// 3-4x more than an invocation via native code for the first
// invocation (though subsequent invocations have been benchmarked
// to be over 20x faster). Unfortunately this cost increases
// startup time for certain applications that use reflection
// intensively (but only once per class) to bootstrap themselves.
// To avoid this penalty we reuse the existing JVM entry points
// for the first few invocations of Methods and Constructors and
// then switch to the bytecode-based implementations.

private static final Config DEFAULT_CONFIG = new Config(false, // useNativeAccessorOnly
false); // disableSerialConstructorChecks

@@ -599,9 +587,7 @@ private static Config config() {
return c;
}

// Defer initialization until module system is initialized so as
// to avoid inflation and spinning bytecode in unnamed modules
// during early startup.
// Always use the default configuration until the module system is initialized.
if (!VM.isModuleSystemInited()) {
return DEFAULT_CONFIG;
}
@@ -612,20 +598,13 @@ private static Config config() {
private static Config loadConfig() {
assert VM.isModuleSystemInited();

boolean useNativeAccessorOnly = DEFAULT_CONFIG.useNativeAccessorOnly;
boolean disableSerialConstructorChecks = DEFAULT_CONFIG.disableSerialConstructorChecks;

Properties props = GetPropertyAction.privilegedGetProperties();
String val = props.getProperty("jdk.reflect.useNativeAccessorOnly");
if (val != null && val.equals("true")) {
useNativeAccessorOnly = true;
}

disableSerialConstructorChecks =
boolean useNativeAccessorOnly =
"true".equals(props.getProperty("jdk.reflect.useNativeAccessorOnly"));
boolean disableSerialConstructorChecks =
"true".equals(props.getProperty("jdk.disableSerialConstructorChecks"));

return new Config(useNativeAccessorOnly,
disableSerialConstructorChecks);
return new Config(useNativeAccessorOnly, disableSerialConstructorChecks);
}

/**
2 changes: 1 addition & 1 deletion test/jdk/java/lang/reflect/Field/NegativeTest.java
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
/**
* @test
* @bug 8277451
* @run testng/othervm NegativeTest
* @run testng NegativeTest
* @summary Test exception thrown due to bad receiver and bad value on
* Field with and without setAccessible(true)
*/