Skip to content

Commit 450a14d

Browse files
committed
runtime: update jdk.internal.reflect.ConstantPool
ConstantPool#constantPoolOop is now an injected field in OpenJDK.
1 parent 805d462 commit 450a14d

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

runtime/src/classes/jdk/internal/reflect/ConstantPool.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ crate::classes::field_module! {
4444
@CLASS jdk_internal_reflect_ConstantPool;
4545

4646
@FIELDSTART
47-
/// `jdk.internal.reflect.ConstantPool#constantPoolOop` field offset
48-
///
49-
/// Expected type: `Reference`
50-
@FIELD constantPoolOop: ty @ FieldType::Object(_) if ty.is_class(b"java/lang/Object"),
47+
/// Injected mirror for the target class
48+
@INJECTED constantPoolOop: FieldType::Object((*b"java/lang/Object").into()) => jni::sys::jobject,
5149
}

runtime/src/classes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ macro_rules! instance_field_count {
6262
(
6363
$(#[$meta:meta])*
6464
$([sym: $specified_sym_name:ident])?
65-
@INJECTED $field_name:ident: $_descriptor:pat => $field_ty:ty, $($rest:tt)*
65+
@INJECTED $field_name:ident: $_descriptor:expr => $field_ty:ty, $($rest:tt)*
6666
) => {
6767
0 + crate::classes::instance_field_count!($($rest)*)
6868
};

runtime/src/initialization.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ fn init_field_offsets() {
299299
unsafe {
300300
classes::java::lang::reflect::Constructor::init_offsets();
301301
}
302+
303+
// java.lang.reflect.Constructor
304+
unsafe {
305+
classes::jdk::internal::reflect::ConstantPool::init_offsets();
306+
}
302307
}
303308
}
304309

runtime/src/objects/class/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ impl Class {
699699
old_fields.assume_init()
700700
};
701701

702+
let has_instance_fields = old_fields.len() > 0;
703+
702704
let max_instance_index = old_fields
703705
.iter()
704706
.fold(0, |a, b| if b.is_static() { a } else { a.max(b.index()) });
@@ -711,10 +713,19 @@ impl Class {
711713
let mut new_fields = Vec::with_capacity(expected_len);
712714
new_fields.extend(old_fields);
713715

716+
let injected_field_start_index;
717+
if has_instance_fields {
718+
// + 1 as `max_instance_index` is the index of the *last* instance field, not of the first
719+
// field we inject.
720+
injected_field_start_index = max_instance_index + 1;
721+
} else {
722+
injected_field_start_index = 0;
723+
}
724+
714725
for (idx, field) in fields.into_iter().enumerate() {
715726
assert!(!field.is_static());
716727
unsafe {
717-
field.set_index(max_instance_index + idx + 1);
728+
field.set_index(injected_field_start_index + idx);
718729
field.set_offset(offset);
719730
}
720731
offset = field.offset() + field.descriptor.size();
@@ -729,10 +740,8 @@ impl Class {
729740
std::ptr::write(old_fields_ptr, new_fields);
730741
}
731742

732-
// + 1 as `max_instance_index` is the index of the *last* instance field, not of the first
733-
// field we inject.
734743
self.field_container
735-
.set_instance_field_count((max_instance_index + 1 + field_count) as u32);
744+
.set_instance_field_count((injected_field_start_index + field_count) as u32);
736745
}
737746

738747
/// Set the nest host for this class

0 commit comments

Comments
 (0)