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
19 changes: 2 additions & 17 deletions src/hotspot/share/classfile/javaClasses.cpp
Expand Up @@ -3622,21 +3622,6 @@ ConstantPool* reflect_ConstantPool::get_cp(oop reflect) {
return InstanceKlass::cast(k)->constants();
}

int reflect_UnsafeStaticFieldAccessorImpl::_base_offset;

#define UNSAFESTATICFIELDACCESSORIMPL_FIELDS_DO(macro) \
macro(_base_offset, k, "base", object_signature, false)

void reflect_UnsafeStaticFieldAccessorImpl::compute_offsets() {
InstanceKlass* k = vmClasses::reflect_UnsafeStaticFieldAccessorImpl_klass();
UNSAFESTATICFIELDACCESSORIMPL_FIELDS_DO(FIELD_COMPUTE_OFFSET);
}

#if INCLUDE_CDS
void reflect_UnsafeStaticFieldAccessorImpl::serialize_offsets(SerializeClosure* f) {
UNSAFESTATICFIELDACCESSORIMPL_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
}
#endif

// Support for java_lang_ref_Reference

Expand Down Expand Up @@ -4633,7 +4618,8 @@ bool java_lang_ClassLoader::is_trusted_loader(oop loader) {
}

// Return true if this is one of the class loaders associated with
// the generated bytecodes for reflection.
// the generated bytecodes for serialization constructor returned
// by sun.reflect.ReflectionFactory::newConstructorForSerialization
bool java_lang_ClassLoader::is_reflection_class_loader(oop loader) {
if (loader != nullptr) {
Klass* delegating_cl_class = vmClasses::reflect_DelegatingClassLoader_klass();
Expand Down Expand Up @@ -5223,7 +5209,6 @@ void java_lang_InternalError::serialize_offsets(SerializeClosure* f) {
f(java_lang_reflect_Field) \
f(java_lang_reflect_RecordComponent) \
f(reflect_ConstantPool) \
f(reflect_UnsafeStaticFieldAccessorImpl) \
f(java_lang_reflect_Parameter) \
f(java_lang_Module) \
f(java_lang_StackTraceElement) \
Expand Down
17 changes: 2 additions & 15 deletions src/hotspot/share/classfile/javaClasses.hpp
Expand Up @@ -884,20 +884,6 @@ class reflect_ConstantPool {
friend class JavaClasses;
};

// Interface to jdk.internal.reflect.UnsafeStaticFieldAccessorImpl objects
class reflect_UnsafeStaticFieldAccessorImpl {
private:
static int _base_offset;
static void compute_offsets();

public:
static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN;

static int base_offset() { CHECK_INIT(_base_offset); }

// Debugging
friend class JavaClasses;
};

// Interface to java.lang primitive type boxing objects:
// - java.lang.Boolean
Expand Down Expand Up @@ -1494,7 +1480,8 @@ class java_lang_ClassLoader : AllStatic {
static bool is_trusted_loader(oop loader);

// Return true if this is one of the class loaders associated with
// the generated bytecodes for reflection.
// the generated bytecodes for serialization constructor returned
// by sun.reflect.ReflectionFactory::newConstructorForSerialization
static bool is_reflection_class_loader(oop loader);

// Fix for 4474172
Expand Down
13 changes: 5 additions & 8 deletions src/hotspot/share/classfile/verifier.cpp
Expand Up @@ -268,9 +268,10 @@ bool Verifier::verify(InstanceKlass* klass, bool should_verify_class, TRAPS) {

bool Verifier::is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class) {
Symbol* name = klass->name();
Klass* refl_magic_klass = vmClasses::reflect_MagicAccessorImpl_klass();
Klass* refl_serialization_ctor_klass = vmClasses::reflect_SerializationConstructorAccessorImpl_klass();

bool is_reflect = refl_magic_klass != nullptr && klass->is_subtype_of(refl_magic_klass);
bool is_reflect_accessor = refl_serialization_ctor_klass != nullptr &&
klass->is_subtype_of(refl_serialization_ctor_klass);

return (should_verify_for(klass->class_loader(), should_verify_class) &&
// return if the class is a bootstrapping class
Expand All @@ -290,13 +291,9 @@ bool Verifier::is_eligible_for_verification(InstanceKlass* klass, bool should_ve
!(klass->is_shared() && klass->is_rewritten()) &&

// As of the fix for 4486457 we disable verification for all of the
// dynamically-generated bytecodes associated with the 1.4
// reflection implementation, not just those associated with
// 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));
(!is_reflect_accessor));
}

Symbol* Verifier::inference_verify(
Expand Down
8 changes: 3 additions & 5 deletions src/hotspot/share/classfile/vmClassMacros.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -105,14 +105,12 @@
do_klass(Continuation_klass, jdk_internal_vm_Continuation ) \
do_klass(StackChunk_klass, jdk_internal_vm_StackChunk ) \
\
do_klass(reflect_MagicAccessorImpl_klass, reflect_MagicAccessorImpl ) \
do_klass(reflect_MethodAccessorImpl_klass, reflect_MethodAccessorImpl ) \
do_klass(reflect_ConstructorAccessorImpl_klass, reflect_ConstructorAccessorImpl ) \
do_klass(reflect_DelegatingClassLoader_klass, reflect_DelegatingClassLoader ) \
do_klass(reflect_ConstantPool_klass, reflect_ConstantPool ) \
do_klass(reflect_UnsafeStaticFieldAccessorImpl_klass, reflect_UnsafeStaticFieldAccessorImpl ) \
do_klass(reflect_CallerSensitive_klass, reflect_CallerSensitive ) \
do_klass(reflect_NativeConstructorAccessorImpl_klass, reflect_NativeConstructorAccessorImpl ) \
do_klass(reflect_DirectConstructorHandleAccessor_NativeAccessor_klass, reflect_DirectConstructorHandleAccessor_NativeAccessor) \
do_klass(reflect_SerializationConstructorAccessorImpl_klass, reflect_SerializationConstructorAccessorImpl ) \
\
/* support for dynamic typing */ \
do_klass(DirectMethodHandle_klass, java_lang_invoke_DirectMethodHandle ) \
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/share/classfile/vmSymbols.hpp
Expand Up @@ -271,14 +271,13 @@
/* Support for reflection based on dynamic bytecode generation (JDK 1.4 and above) */ \
\
template(jdk_internal_reflect, "jdk/internal/reflect") \
template(reflect_MagicAccessorImpl, "jdk/internal/reflect/MagicAccessorImpl") \
template(reflect_MethodAccessorImpl, "jdk/internal/reflect/MethodAccessorImpl") \
template(reflect_ConstructorAccessorImpl, "jdk/internal/reflect/ConstructorAccessorImpl") \
template(reflect_DelegatingClassLoader, "jdk/internal/reflect/DelegatingClassLoader") \
template(reflect_Reflection, "jdk/internal/reflect/Reflection") \
template(reflect_CallerSensitive, "jdk/internal/reflect/CallerSensitive") \
template(reflect_CallerSensitive_signature, "Ljdk/internal/reflect/CallerSensitive;") \
template(reflect_NativeConstructorAccessorImpl, "jdk/internal/reflect/NativeConstructorAccessorImpl")\
template(reflect_DirectConstructorHandleAccessor_NativeAccessor, "jdk/internal/reflect/DirectConstructorHandleAccessor$NativeAccessor") \
template(reflect_SerializationConstructorAccessorImpl, "jdk/internal/reflect/SerializationConstructorAccessorImpl") \
template(checkedExceptions_name, "checkedExceptions") \
template(clazz_name, "clazz") \
template(exceptionTypes_name, "exceptionTypes") \
Expand Down Expand Up @@ -307,7 +306,6 @@
template(parameter_annotations_name, "parameterAnnotations") \
template(annotation_default_name, "annotationDefault") \
template(reflect_ConstantPool, "jdk/internal/reflect/ConstantPool") \
template(reflect_UnsafeStaticFieldAccessorImpl, "jdk/internal/reflect/UnsafeStaticFieldAccessorImpl")\
template(base_name, "base") \
/* Type Annotations (JDK 8 and above) */ \
template(type_annotations_name, "typeAnnotations") \
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/interpreter/bytecodeUtils.cpp
Expand Up @@ -1447,7 +1447,7 @@ bool BytecodeUtils::get_NPE_message_at(outputStream* ss, Method* method, int bci

// If this NPE was created via reflection, we have no real NPE.
if (method->method_holder() ==
vmClasses::reflect_NativeConstructorAccessorImpl_klass()) {
vmClasses::reflect_DirectConstructorHandleAccessor_NativeAccessor_klass()) {
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/share/interpreter/linkResolver.cpp
Expand Up @@ -1169,9 +1169,10 @@ Method* LinkResolver::linktime_resolve_special_method(const LinkInfo& link_info,
Klass* current_klass = link_info.current_klass();
if (current_klass != nullptr && resolved_klass->is_interface()) {
InstanceKlass* klass_to_check = InstanceKlass::cast(current_klass);
// Disable verification for the dynamically-generated reflection bytecodes.
// Disable verification for the dynamically-generated reflection bytecodes
// for serialization constructor accessor.
bool is_reflect = klass_to_check->is_subclass_of(
vmClasses::reflect_MagicAccessorImpl_klass());
vmClasses::reflect_SerializationConstructorAccessorImpl_klass());

if (!is_reflect &&
!klass_to_check->is_same_or_direct_interface(resolved_klass)) {
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/prims/jvm.cpp
Expand Up @@ -722,7 +722,7 @@ JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
//
// The call stack at this point looks something like this:
//
// [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ]
// [0] [ @CallerSensitive public jdk.internal.reflect.Reflection.getCallerClass ]
// [1] [ @CallerSensitive API.method ]
// [.] [ (skipped intermediate frames) ]
// [n] [ caller ]
Expand Down Expand Up @@ -3294,8 +3294,7 @@ JVM_ENTRY(jobject, JVM_LatestUserDefinedLoader(JNIEnv *env))
oop loader = ik->class_loader();
if (loader != nullptr && !SystemDictionary::is_platform_class_loader(loader)) {
// Skip reflection related frames
if (!ik->is_subclass_of(vmClasses::reflect_MethodAccessorImpl_klass()) &&
!ik->is_subclass_of(vmClasses::reflect_ConstructorAccessorImpl_klass())) {
if (!ik->is_subclass_of(vmClasses::reflect_SerializationConstructorAccessorImpl_klass())) {
return JNIHandles::make_local(THREAD, loader);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/share/runtime/reflection.cpp
Expand Up @@ -448,10 +448,10 @@ Reflection::VerifyClassAccessResults Reflection::verify_class_access(
is_same_class_package(current_class, new_class)) {
return ACCESS_OK;
}
// Allow all accesses from jdk/internal/reflect/MagicAccessorImpl subclasses to
// Allow all accesses from jdk/internal/reflect/SerializationConstructorAccessorImpl subclasses to
// succeed trivially.
if (vmClasses::reflect_MagicAccessorImpl_klass_is_loaded() &&
current_class->is_subclass_of(vmClasses::reflect_MagicAccessorImpl_klass())) {
if (vmClasses::reflect_SerializationConstructorAccessorImpl_klass_is_loaded() &&
current_class->is_subclass_of(vmClasses::reflect_SerializationConstructorAccessorImpl_klass())) {
return ACCESS_OK;
}

Expand Down Expand Up @@ -664,9 +664,9 @@ bool Reflection::verify_member_access(const Klass* current_class,
}
}

// Allow all accesses from jdk/internal/reflect/MagicAccessorImpl subclasses to
// Allow all accesses from jdk/internal/reflect/SerializationConstructorAccessorImpl subclasses to
// succeed trivially.
if (current_class->is_subclass_of(vmClasses::reflect_MagicAccessorImpl_klass())) {
if (current_class->is_subclass_of(vmClasses::reflect_SerializationConstructorAccessorImpl_klass())) {
return true;
}

Expand Down
2 changes: 0 additions & 2 deletions src/hotspot/share/runtime/reflectionUtils.cpp
Expand Up @@ -78,8 +78,6 @@ GrowableArray<FilteredField*> *FilteredFieldsMap::_filtered_fields =
void FilteredFieldsMap::initialize() {
int offset = reflect_ConstantPool::oop_offset();
_filtered_fields->append(new FilteredField(vmClasses::reflect_ConstantPool_klass(), offset));
offset = reflect_UnsafeStaticFieldAccessorImpl::base_offset();
_filtered_fields->append(new FilteredField(vmClasses::reflect_UnsafeStaticFieldAccessorImpl_klass(), offset));
}

int FilteredFieldStream::field_count() {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -43,8 +43,7 @@ class AccessorGenerator implements ClassFileConstants {
protected static final short S5 = (short) 5;
protected static final short S6 = (short) 6;

// Instance variables for shared functionality between
// FieldAccessorGenerator and MethodAccessorGenerator
// Instance variables for shared functionality
protected ClassFileAssembler asm;
protected int modifiers;
protected short thisClass;
Expand Down

This file was deleted.

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,8 +32,11 @@
import jdk.internal.access.SharedSecrets;

/** Utility class which assists in calling defineClass() by
creating a new class loader which delegates to the one needed in
order for proper resolution of the given bytecodes to occur. */
* creating a new class loader which delegates to the one needed in
* order for proper resolution of the given bytecodes to occur.
*
* This is only used to define SerializationConstructorAccessor.
*/

class ClassDefiner {
static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
Expand Down

This file was deleted.