Skip to content

Commit a891ee5

Browse files
Merge in jdk-23.0.2+7 (24.1)
PullRequest: labsjdk-ce/131
2 parents 0d9e1de + cc2aec4 commit a891ee5

File tree

5 files changed

+66
-43
lines changed

5 files changed

+66
-43
lines changed

src/hotspot/cpu/s390/c1_LIRAssembler_s390.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,19 @@ void LIR_Assembler::osr_entry() {
131131
// copied into place by code emitted in the IR.
132132

133133
Register OSR_buf = osrBufferPointer()->as_register();
134-
{ assert(frame::interpreter_frame_monitor_size() == BasicObjectLock::size(), "adjust code below");
135-
int monitor_offset = BytesPerWord * method()->max_locals() +
136-
(2 * BytesPerWord) * (number_of_locks - 1);
134+
{
135+
assert(frame::interpreter_frame_monitor_size() == BasicObjectLock::size(), "adjust code below");
136+
137+
const int locals_space = BytesPerWord * method() -> max_locals();
138+
int monitor_offset = locals_space + (2 * BytesPerWord) * (number_of_locks - 1);
139+
bool large_offset = !Immediate::is_simm20(monitor_offset + BytesPerWord) && number_of_locks > 0;
140+
141+
if (large_offset) {
142+
// z_lg can only handle displacement upto 20bit signed binary integer
143+
__ z_algfi(OSR_buf, locals_space);
144+
monitor_offset -= locals_space;
145+
}
146+
137147
// SharedRuntime::OSR_migration_begin() packs BasicObjectLocks in
138148
// the OSR buffer using 2 word entries: first the lock and then
139149
// the oop.
@@ -147,6 +157,10 @@ void LIR_Assembler::osr_entry() {
147157
__ z_lg(Z_R1_scratch, slot_offset + 1*BytesPerWord, OSR_buf);
148158
__ z_stg(Z_R1_scratch, frame_map()->address_for_monitor_object(i));
149159
}
160+
161+
if (large_offset) {
162+
__ z_slgfi(OSR_buf, locals_space);
163+
}
150164
}
151165
}
152166

src/hotspot/share/jfr/support/jfrJdkJfrEvent.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "oops/klass.inline.hpp"
3636
#include "runtime/handles.inline.hpp"
3737
#include "runtime/javaThread.hpp"
38+
#include "runtime/safepointVerifiers.hpp"
3839
#include "utilities/stack.inline.hpp"
3940

4041
static jobject empty_java_util_arraylist = nullptr;
@@ -80,30 +81,25 @@ static bool is_allowed(const Klass* k) {
8081
return !(k->is_abstract() || k->should_be_initialized());
8182
}
8283

83-
static void fill_klasses(GrowableArray<const void*>& event_subklasses, const InstanceKlass* event_klass, JavaThread* thread) {
84+
static void fill_klasses(GrowableArray<jclass>& event_subklasses, const InstanceKlass* event_klass, JavaThread* thread) {
8485
assert(event_subklasses.length() == 0, "invariant");
8586
assert(event_klass != nullptr, "invariant");
8687
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread));
88+
// Do not safepoint while walking the ClassHierarchy, keeping klasses alive and storing their mirrors in JNI handles.
89+
NoSafepointVerifier nsv;
8790

8891
for (ClassHierarchyIterator iter(const_cast<InstanceKlass*>(event_klass)); !iter.done(); iter.next()) {
8992
Klass* subk = iter.klass();
9093
if (is_allowed(subk)) {
91-
event_subklasses.append(subk);
94+
// We are walking the class hierarchy and saving the relevant klasses in JNI handles.
95+
// To be allowed to store the java mirror, we must ensure that the klass and its oops are kept alive,
96+
// and perform the store before the next safepoint.
97+
subk->keep_alive();
98+
event_subklasses.append((jclass)JfrJavaSupport::local_jni_handle(subk->java_mirror(), thread));
9299
}
93100
}
94101
}
95102

96-
static void transform_klasses_to_local_jni_handles(GrowableArray<const void*>& event_subklasses, JavaThread* thread) {
97-
assert(event_subklasses.is_nonempty(), "invariant");
98-
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread));
99-
100-
for (int i = 0; i < event_subklasses.length(); ++i) {
101-
const InstanceKlass* k = static_cast<const InstanceKlass*>(event_subklasses.at(i));
102-
assert(is_allowed(k), "invariant");
103-
event_subklasses.at_put(i, JfrJavaSupport::local_jni_handle(k->java_mirror(), thread));
104-
}
105-
}
106-
107103
jobject JdkJfrEvent::get_all_klasses(TRAPS) {
108104
DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
109105
initialize(THREAD);
@@ -126,15 +122,13 @@ jobject JdkJfrEvent::get_all_klasses(TRAPS) {
126122
}
127123

128124
ResourceMark rm(THREAD);
129-
GrowableArray<const void*> event_subklasses(initial_array_size);
125+
GrowableArray<jclass> event_subklasses(initial_array_size);
130126
fill_klasses(event_subklasses, InstanceKlass::cast(klass), THREAD);
131127

132128
if (event_subklasses.is_empty()) {
133129
return empty_java_util_arraylist;
134130
}
135131

136-
transform_klasses_to_local_jni_handles(event_subklasses, THREAD);
137-
138132
Handle h_array_list(THREAD, new_java_util_arraylist(THREAD));
139133
assert(h_array_list.not_null(), "invariant");
140134

@@ -150,7 +144,7 @@ jobject JdkJfrEvent::get_all_klasses(TRAPS) {
150144

151145
JavaValue result(T_BOOLEAN);
152146
for (int i = 0; i < event_subklasses.length(); ++i) {
153-
const jclass clazz = (jclass)event_subklasses.at(i);
147+
const jclass clazz = event_subklasses.at(i);
154148
assert(JdkJfrEvent::is_subklass(clazz), "invariant");
155149
JfrJavaArguments args(&result, array_list_klass, add_method_sym, add_method_sig_sym);
156150
args.set_receiver(h_array_list());

src/hotspot/share/oops/klass.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ class Klass : public Metadata {
582582

583583
inline oop klass_holder() const;
584584

585+
inline void keep_alive() const;
586+
585587
protected:
586588

587589
// Error handling when length > max_length or length < 0

src/hotspot/share/oops/klass.inline.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ inline oop Klass::klass_holder() const {
3636
return class_loader_data()->holder();
3737
}
3838

39+
inline void Klass::keep_alive() const {
40+
// Resolving the holder (a WeakHandle) will keep the klass alive until the next safepoint.
41+
// Making the klass's CLD handle oops (e.g. the java_mirror), safe to store in the object
42+
// graph and its roots (e.g. Handles).
43+
static_cast<void>(klass_holder());
44+
}
45+
3946
inline bool Klass::is_non_strong_hidden() const {
4047
return access_flags().is_hidden_class() &&
4148
class_loader_data()->has_class_mirror_holder();
@@ -52,6 +59,7 @@ inline bool Klass::is_loader_alive() const {
5259
return class_loader_data()->is_alive();
5360
}
5461

62+
// Loading the java_mirror does not keep its holder alive. See Klass::keep_alive().
5563
inline oop Klass::java_mirror() const {
5664
return _java_mirror.resolve();
5765
}

test/hotspot/jtreg/compiler/c2/irTests/TestVectorizationMismatchedAccess.java

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ public class TestVectorizationMismatchedAccess {
5050
private final static WhiteBox wb = WhiteBox.getWhiteBox();
5151

5252
public static void main(String[] args) {
53-
if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
54-
throw new RuntimeException("fix test that was written for a little endian platform");
55-
}
5653
TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED");
5754
}
5855

@@ -77,6 +74,14 @@ public static void main(String[] args) {
7774
}
7875
}
7976

77+
// Method to adjust the value for the native byte order
78+
static private long handleByteOrder(long value) {
79+
if (ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN) {
80+
value = Long.reverseBytes(value);
81+
}
82+
return value;
83+
}
84+
8085
static private void runAndVerify(Runnable test, int offset) {
8186
System.arraycopy(verifyLongArray, 0, longArray, 0, longArray.length);
8287
Arrays.fill(byteArray, (byte)0);
@@ -154,7 +159,7 @@ static private void runAndVerify3(Runnable test, int offset) {
154159
// might get fixed with JDK-8325155.
155160
public static void testByteLong1a(byte[] dest, long[] src) {
156161
for (int i = 0; i < src.length; i++) {
157-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i, src[i]);
162+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * i, handleByteOrder(src[i]));
158163
}
159164
}
160165

@@ -165,7 +170,7 @@ public static void testByteLong1a(byte[] dest, long[] src) {
165170
// 32-bit: address has ConvL2I for cast of long to address, not supported.
166171
public static void testByteLong1b(byte[] dest, long[] src) {
167172
for (int i = 0; i < src.length; i++) {
168-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i, src[i]);
173+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * i, handleByteOrder(src[i]));
169174
}
170175
}
171176

@@ -175,7 +180,7 @@ public static void testByteLong1b(byte[] dest, long[] src) {
175180
public static void testByteLong1c(byte[] dest, long[] src) {
176181
long base = 64; // make sure it is big enough and 8 byte aligned (required for 32-bit)
177182
for (int i = 0; i < src.length - 8; i++) {
178-
UNSAFE.putLongUnaligned(dest, base + 8 * i, src[i]);
183+
UNSAFE.putLongUnaligned(dest, base + 8 * i, handleByteOrder(src[i]));
179184
}
180185
}
181186

@@ -187,7 +192,7 @@ public static void testByteLong1c(byte[] dest, long[] src) {
187192
public static void testByteLong1d(byte[] dest, long[] src) {
188193
long base = 64; // make sure it is big enough and 8 byte aligned (required for 32-bit)
189194
for (int i = 0; i < src.length - 8; i++) {
190-
UNSAFE.putLongUnaligned(dest, base + 8L * i, src[i]);
195+
UNSAFE.putLongUnaligned(dest, base + 8L * i, handleByteOrder(src[i]));
191196
}
192197
}
193198

@@ -207,7 +212,7 @@ public static void testByteLong1_runner() {
207212
// might get fixed with JDK-8325155.
208213
public static void testByteLong2a(byte[] dest, long[] src) {
209214
for (int i = 1; i < src.length; i++) {
210-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i - 1), src[i]);
215+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i - 1), handleByteOrder(src[i]));
211216
}
212217
}
213218

@@ -218,7 +223,7 @@ public static void testByteLong2a(byte[] dest, long[] src) {
218223
// 32-bit: address has ConvL2I for cast of long to address, not supported.
219224
public static void testByteLong2b(byte[] dest, long[] src) {
220225
for (int i = 1; i < src.length; i++) {
221-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i - 1), src[i]);
226+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i - 1), handleByteOrder(src[i]));
222227
}
223228
}
224229

@@ -236,7 +241,7 @@ public static void testByteLong2_runner() {
236241
// might get fixed with JDK-8325155.
237242
public static void testByteLong3a(byte[] dest, long[] src) {
238243
for (int i = 0; i < src.length - 1; i++) {
239-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + 1), src[i]);
244+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + 1), handleByteOrder(src[i]));
240245
}
241246
}
242247

@@ -247,7 +252,7 @@ public static void testByteLong3a(byte[] dest, long[] src) {
247252
// 32-bit: address has ConvL2I for cast of long to address, not supported.
248253
public static void testByteLong3b(byte[] dest, long[] src) {
249254
for (int i = 0; i < src.length - 1; i++) {
250-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + 1), src[i]);
255+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + 1), handleByteOrder(src[i]));
251256
}
252257
}
253258

@@ -267,7 +272,7 @@ public static void testByteLong3_runner() {
267272
// AlignVector cannot guarantee that invar is aligned.
268273
public static void testByteLong4a(byte[] dest, long[] src, int start, int stop) {
269274
for (int i = start; i < stop; i++) {
270-
UNSAFE.putLongUnaligned(dest, 8 * i + baseOffset, src[i]);
275+
UNSAFE.putLongUnaligned(dest, 8 * i + baseOffset, handleByteOrder(src[i]));
271276
}
272277
}
273278

@@ -280,7 +285,7 @@ public static void testByteLong4a(byte[] dest, long[] src, int start, int stop)
280285
// AlignVector cannot guarantee that invar is aligned.
281286
public static void testByteLong4b(byte[] dest, long[] src, int start, int stop) {
282287
for (int i = start; i < stop; i++) {
283-
UNSAFE.putLongUnaligned(dest, 8L * i + baseOffset, src[i]);
288+
UNSAFE.putLongUnaligned(dest, 8L * i + baseOffset, handleByteOrder(src[i]));
284289
}
285290
}
286291

@@ -299,7 +304,7 @@ public static void testByteLong4_runner() {
299304
// might get fixed with JDK-8325155.
300305
public static void testByteLong5a(byte[] dest, long[] src, int start, int stop) {
301306
for (int i = start; i < stop; i++) {
302-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + baseOffset), src[i]);
307+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8 * (i + baseOffset), handleByteOrder(src[i]));
303308
}
304309
}
305310

@@ -310,7 +315,7 @@ public static void testByteLong5a(byte[] dest, long[] src, int start, int stop)
310315
// 32-bit: address has ConvL2I for cast of long to address, not supported.
311316
public static void testByteLong5b(byte[] dest, long[] src, int start, int stop) {
312317
for (int i = start; i < stop; i++) {
313-
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + baseOffset), src[i]);
318+
UNSAFE.putLongUnaligned(dest, UNSAFE.ARRAY_BYTE_BASE_OFFSET + 8L * (i + baseOffset), handleByteOrder(src[i]));
314319
}
315320
}
316321

@@ -454,7 +459,7 @@ public static void testByteByte5_runner() {
454459
// See: JDK-8331576
455460
public static void testOffHeapLong1a(long dest, long[] src) {
456461
for (int i = 0; i < src.length; i++) {
457-
UNSAFE.putLongUnaligned(null, dest + 8 * i, src[i]);
462+
UNSAFE.putLongUnaligned(null, dest + 8 * i, handleByteOrder(src[i]));
458463
}
459464
}
460465

@@ -465,7 +470,7 @@ public static void testOffHeapLong1a(long dest, long[] src) {
465470
// See: JDK-8331576
466471
public static void testOffHeapLong1b(long dest, long[] src) {
467472
for (int i = 0; i < src.length; i++) {
468-
UNSAFE.putLongUnaligned(null, dest + 8L * i, src[i]);
473+
UNSAFE.putLongUnaligned(null, dest + 8L * i, handleByteOrder(src[i]));
469474
}
470475
}
471476

@@ -482,7 +487,7 @@ public static void testOffHeapLong1_runner() {
482487
// See: JDK-8331576
483488
public static void testOffHeapLong2a(long dest, long[] src) {
484489
for (int i = 1; i < src.length; i++) {
485-
UNSAFE.putLongUnaligned(null, dest + 8 * (i - 1), src[i]);
490+
UNSAFE.putLongUnaligned(null, dest + 8 * (i - 1), handleByteOrder(src[i]));
486491
}
487492
}
488493

@@ -493,7 +498,7 @@ public static void testOffHeapLong2a(long dest, long[] src) {
493498
// See: JDK-8331576
494499
public static void testOffHeapLong2b(long dest, long[] src) {
495500
for (int i = 1; i < src.length; i++) {
496-
UNSAFE.putLongUnaligned(null, dest + 8L * (i - 1), src[i]);
501+
UNSAFE.putLongUnaligned(null, dest + 8L * (i - 1), handleByteOrder(src[i]));
497502
}
498503
}
499504

@@ -510,7 +515,7 @@ public static void testOffHeapLong2_runner() {
510515
// See: JDK-8331576
511516
public static void testOffHeapLong3a(long dest, long[] src) {
512517
for (int i = 0; i < src.length - 1; i++) {
513-
UNSAFE.putLongUnaligned(null, dest + 8 * (i + 1), src[i]);
518+
UNSAFE.putLongUnaligned(null, dest + 8 * (i + 1), handleByteOrder(src[i]));
514519
}
515520
}
516521

@@ -521,7 +526,7 @@ public static void testOffHeapLong3a(long dest, long[] src) {
521526
// See: JDK-8331576
522527
public static void testOffHeapLong3b(long dest, long[] src) {
523528
for (int i = 0; i < src.length - 1; i++) {
524-
UNSAFE.putLongUnaligned(null, dest + 8L * (i + 1), src[i]);
529+
UNSAFE.putLongUnaligned(null, dest + 8L * (i + 1), handleByteOrder(src[i]));
525530
}
526531
}
527532

@@ -540,7 +545,7 @@ public static void testOffHeapLong3_runner() {
540545
// AlignVector cannot guarantee that invar is aligned.
541546
public static void testOffHeapLong4a(long dest, long[] src, int start, int stop) {
542547
for (int i = start; i < stop; i++) {
543-
UNSAFE.putLongUnaligned(null, dest + 8 * i + baseOffset, src[i]);
548+
UNSAFE.putLongUnaligned(null, dest + 8 * i + baseOffset, handleByteOrder(src[i]));
544549
}
545550
}
546551

@@ -553,7 +558,7 @@ public static void testOffHeapLong4a(long dest, long[] src, int start, int stop)
553558
// AlignVector cannot guarantee that invar is aligned.
554559
public static void testOffHeapLong4b(long dest, long[] src, int start, int stop) {
555560
for (int i = start; i < stop; i++) {
556-
UNSAFE.putLongUnaligned(null, dest + 8L * i + baseOffset, src[i]);
561+
UNSAFE.putLongUnaligned(null, dest + 8L * i + baseOffset, handleByteOrder(src[i]));
557562
}
558563
}
559564

0 commit comments

Comments
 (0)