Skip to content

Commit b75e35c

Browse files
Arrayingcoleenp
authored andcommitted
8365858: FilteredJavaFieldStream is unnecessary
Reviewed-by: liach, jsjolen, coleenp, amenkov
1 parent e883dec commit b75e35c

File tree

9 files changed

+28
-185
lines changed

9 files changed

+28
-185
lines changed

src/hotspot/share/classfile/javaClasses.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
#include "runtime/javaCalls.hpp"
8080
#include "runtime/javaThread.hpp"
8181
#include "runtime/jniHandles.inline.hpp"
82-
#include "runtime/reflectionUtils.hpp"
82+
#include "runtime/reflection.hpp"
8383
#include "runtime/safepoint.hpp"
8484
#include "runtime/safepointVerifiers.hpp"
8585
#include "runtime/threadSMR.hpp"
@@ -3741,20 +3741,17 @@ oop java_lang_reflect_RecordComponent::create(InstanceKlass* holder, RecordCompo
37413741
return element();
37423742
}
37433743

3744-
int reflect_ConstantPool::_oop_offset;
3745-
3746-
#define CONSTANTPOOL_FIELDS_DO(macro) \
3747-
macro(_oop_offset, k, "constantPoolOop", object_signature, false)
3744+
int reflect_ConstantPool::_vmholder_offset;
37483745

37493746
void reflect_ConstantPool::compute_offsets() {
37503747
InstanceKlass* k = vmClasses::reflect_ConstantPool_klass();
3751-
// The field is called ConstantPool* in the sun.reflect.ConstantPool class.
3752-
CONSTANTPOOL_FIELDS_DO(FIELD_COMPUTE_OFFSET);
3748+
// The field is injected and called Object vmholder in the jdk.internal.reflect.ConstantPool class.
3749+
CONSTANTPOOL_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
37533750
}
37543751

37553752
#if INCLUDE_CDS
37563753
void reflect_ConstantPool::serialize_offsets(SerializeClosure* f) {
3757-
CONSTANTPOOL_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
3754+
CONSTANTPOOL_INJECTED_FIELDS(INJECTED_FIELD_SERIALIZE_OFFSET);
37583755
}
37593756
#endif
37603757

@@ -3907,13 +3904,15 @@ Handle reflect_ConstantPool::create(TRAPS) {
39073904

39083905

39093906
void reflect_ConstantPool::set_cp(oop reflect, ConstantPool* value) {
3907+
assert(_vmholder_offset != 0, "Uninitialized vmholder");
39103908
oop mirror = value->pool_holder()->java_mirror();
39113909
// Save the mirror to get back the constant pool.
3912-
reflect->obj_field_put(_oop_offset, mirror);
3910+
reflect->obj_field_put(_vmholder_offset, mirror);
39133911
}
39143912

39153913
ConstantPool* reflect_ConstantPool::get_cp(oop reflect) {
3916-
oop mirror = reflect->obj_field(_oop_offset);
3914+
assert(_vmholder_offset != 0, "Uninitialized vmholder");
3915+
oop mirror = reflect->obj_field(_vmholder_offset);
39173916
InstanceKlass* ik = java_lang_Class::as_InstanceKlass(mirror);
39183917

39193918
// Get the constant pool back from the klass. Since class redefinition
@@ -5554,5 +5553,4 @@ int InjectedField::compute_offset() {
55545553
void javaClasses_init() {
55555554
JavaClasses::compute_offsets();
55565555
JavaClasses::check_offsets();
5557-
FilteredFieldsMap::initialize(); // must be done after computing offsets.
55585556
}

src/hotspot/share/classfile/javaClasses.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,12 +936,16 @@ class java_lang_Module {
936936
friend class JavaClasses;
937937
};
938938

939+
#define CONSTANTPOOL_INJECTED_FIELDS(macro) \
940+
macro(reflect_ConstantPool, vmholder, object_signature, false)
941+
939942
// Interface to jdk.internal.reflect.ConstantPool objects
940943
class reflect_ConstantPool {
941944
private:
942945
// Note that to reduce dependencies on the JDK we compute these
943-
// offsets at run-time.
944-
static int _oop_offset;
946+
// offsets at run-time. This field is the oop offset for the
947+
// actual constant pool, previously called constantPoolOop.
948+
static int _vmholder_offset;
945949

946950
static void compute_offsets();
947951

@@ -953,7 +957,6 @@ class reflect_ConstantPool {
953957

954958
// Accessors
955959
static void set_cp(oop reflect, ConstantPool* value);
956-
static int oop_offset() { CHECK_INIT(_oop_offset); }
957960

958961
static ConstantPool* get_cp(oop reflect);
959962

src/hotspot/share/classfile/javaClassesImpl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
THREAD_INJECTED_FIELDS(macro) \
4343
VTHREAD_INJECTED_FIELDS(macro) \
4444
INTERNALERROR_INJECTED_FIELDS(macro) \
45-
STACKCHUNK_INJECTED_FIELDS(macro)
45+
STACKCHUNK_INJECTED_FIELDS(macro) \
46+
CONSTANTPOOL_INJECTED_FIELDS(macro)
4647

4748
#define INJECTED_FIELD_COMPUTE_OFFSET(klass, name, signature, may_be_java) \
4849
klass::_##name##_offset = JavaClasses::compute_injected_offset(InjectedFieldID::klass##_##name##_enum);

src/hotspot/share/prims/jvmtiEnv.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "memory/allocation.hpp"
3939
#include "memory/resourceArea.hpp"
4040
#include "memory/universe.hpp"
41+
#include "oops/fieldStreams.inline.hpp"
4142
#include "oops/instanceKlass.hpp"
4243
#include "oops/klass.inline.hpp"
4344
#include "oops/objArrayOop.inline.hpp"
@@ -68,7 +69,6 @@
6869
#include "runtime/objectMonitor.inline.hpp"
6970
#include "runtime/os.hpp"
7071
#include "runtime/osThread.hpp"
71-
#include "runtime/reflectionUtils.hpp"
7272
#include "runtime/signature.hpp"
7373
#include "runtime/threadHeapSampler.hpp"
7474
#include "runtime/threads.hpp"
@@ -2841,9 +2841,9 @@ JvmtiEnv::GetClassFields(oop k_mirror, jint* field_count_ptr, jfieldID** fields_
28412841

28422842
InstanceKlass* ik = InstanceKlass::cast(k);
28432843

2844-
FilteredJavaFieldStream flds(ik);
2844+
JavaFieldStream flds(ik);
28452845

2846-
int result_count = flds.field_count();
2846+
int result_count = ik->java_fields_count();
28472847

28482848
// Allocate the result and fill it in.
28492849
jfieldID* result_list = (jfieldID*)jvmtiMalloc(result_count * sizeof(jfieldID));

src/hotspot/share/prims/jvmtiTagMap.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "oops/access.inline.hpp"
3737
#include "oops/arrayOop.hpp"
3838
#include "oops/constantPool.inline.hpp"
39+
#include "oops/fieldStreams.inline.hpp"
3940
#include "oops/instanceMirrorKlass.hpp"
4041
#include "oops/klass.inline.hpp"
4142
#include "oops/objArrayKlass.hpp"
@@ -58,7 +59,6 @@
5859
#include "runtime/jniHandles.inline.hpp"
5960
#include "runtime/mutex.hpp"
6061
#include "runtime/mutexLocker.hpp"
61-
#include "runtime/reflectionUtils.hpp"
6262
#include "runtime/safepoint.hpp"
6363
#include "runtime/threadSMR.hpp"
6464
#include "runtime/timerTrace.hpp"
@@ -429,8 +429,8 @@ int ClassFieldMap::interfaces_field_count(InstanceKlass* ik) {
429429
const Array<InstanceKlass*>* interfaces = ik->transitive_interfaces();
430430
int count = 0;
431431
for (int i = 0; i < interfaces->length(); i++) {
432-
FilteredJavaFieldStream fld(interfaces->at(i));
433-
count += fld.field_count();
432+
count += interfaces->at(i)->java_fields_count();
433+
434434
}
435435
return count;
436436
}
@@ -452,11 +452,10 @@ ClassFieldMap* ClassFieldMap::create_map_of_static_fields(Klass* k) {
452452
// Need to calculate start index of this class fields: number of fields in all interfaces and superclasses.
453453
int index = interfaces_field_count(ik);
454454
for (InstanceKlass* super_klass = ik->super(); super_klass != nullptr; super_klass = super_klass->super()) {
455-
FilteredJavaFieldStream super_fld(super_klass);
456-
index += super_fld.field_count();
455+
index += super_klass->java_fields_count();
457456
}
458457

459-
for (FilteredJavaFieldStream fld(ik); !fld.done(); fld.next(), index++) {
458+
for (JavaFieldStream fld(ik); !fld.done(); fld.next(), index++) {
460459
// ignore instance fields
461460
if (!fld.access_flags().is_static()) {
462461
continue;
@@ -479,13 +478,12 @@ ClassFieldMap* ClassFieldMap::create_map_of_instance_fields(oop obj) {
479478
// fields of the superclasses are reported first, so need to know total field number to calculate field indices
480479
int total_field_number = interfaces_field_count(ik);
481480
for (InstanceKlass* klass = ik; klass != nullptr; klass = klass->super()) {
482-
FilteredJavaFieldStream fld(klass);
483-
total_field_number += fld.field_count();
481+
total_field_number += klass->java_fields_count();
484482
}
485483

486484
for (InstanceKlass* klass = ik; klass != nullptr; klass = klass->super()) {
487-
FilteredJavaFieldStream fld(klass);
488-
int start_index = total_field_number - fld.field_count();
485+
JavaFieldStream fld(klass);
486+
int start_index = total_field_number - klass->java_fields_count();
489487
for (int index = 0; !fld.done(); fld.next(), index++) {
490488
// ignore static fields
491489
if (fld.access_flags().is_static()) {

src/hotspot/share/runtime/reflectionUtils.cpp

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/hotspot/share/runtime/reflectionUtils.hpp

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/java.base/share/classes/jdk/internal/reflect/ConstantPool.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@ private static Tag valueOf(byte v) {
106106
// Internals only below this point
107107
//
108108

109-
static {
110-
Reflection.registerFieldsToFilter(ConstantPool.class, Set.of("constantPoolOop"));
111-
}
112-
113-
// HotSpot-internal constant pool object (set by the VM, name known to the VM)
114-
private Object constantPoolOop;
115-
116109
private native int getSize0 ();
117110
private native Class<?> getClassAt0 (int index);
118111
private native Class<?> getClassAtIfLoaded0 (int index);

test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.runtime.test/src/jdk/vm/ci/runtime/test/TestResolvedJavaType.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,6 @@ public Field lookupField(Collection<Field> fields, ResolvedJavaField key) {
949949
* Replicates the semantics of jdk.internal.reflect.Reflection#fieldFilterMap.
950950
*/
951951
private static boolean isHiddenFromReflection(ResolvedJavaField f) {
952-
if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(ConstantPool.class)) && f.getName().equals("constantPoolOop")) {
953-
return true;
954-
}
955952
if (f.getDeclaringClass().equals(metaAccess.lookupJavaType(Class.class))) {
956953
String name = f.getName();
957954
return name.equals("classLoader") ||

0 commit comments

Comments
 (0)