Skip to content

Commit 5a7683e

Browse files
committed
Merge tag 'jdk-25.0.1+8' into sapmachine25
2 parents e8a5612 + 78770bf commit 5a7683e

File tree

28 files changed

+435
-105
lines changed

28 files changed

+435
-105
lines changed

src/hotspot/share/classfile/stackMapTable.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,16 @@ bool StackMapTable::match_stackmap(
132132
}
133133

134134
void StackMapTable::check_jump_target(
135-
StackMapFrame* frame, int32_t target, TRAPS) const {
135+
StackMapFrame* frame, int bci, int offset, TRAPS) const {
136136
ErrorContext ctx;
137+
// Jump targets must be within the method and the method size is limited. See JVMS 4.11
138+
int min_offset = -1 * max_method_code_size;
139+
if (offset < min_offset || offset > max_method_code_size) {
140+
frame->verifier()->verify_error(ErrorContext::bad_stackmap(bci, frame),
141+
"Illegal target of jump or branch (bci %d + offset %d)", bci, offset);
142+
return;
143+
}
144+
int target = bci + offset;
137145
bool match = match_stackmap(
138146
frame, target, true, false, &ctx, CHECK_VERIFY(frame->verifier()));
139147
if (!match || (target < 0 || target >= _code_length)) {

src/hotspot/share/classfile/stackMapTable.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class StackMapTable : public StackObj {
6767

6868
// Check jump instructions. Make sure there are no uninitialized
6969
// instances on backward branch.
70-
void check_jump_target(StackMapFrame* frame, int32_t target, TRAPS) const;
70+
void check_jump_target(StackMapFrame* frame, int bci, int offset, TRAPS) const;
7171

7272
// The following methods are only used inside this class.
7373

src/hotspot/share/classfile/verifier.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
781781

782782
// Merge with the next instruction
783783
{
784-
int target;
785784
VerificationType type, type2;
786785
VerificationType atype;
787786

@@ -1606,9 +1605,8 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
16061605
case Bytecodes::_ifle:
16071606
current_frame.pop_stack(
16081607
VerificationType::integer_type(), CHECK_VERIFY(this));
1609-
target = bcs.dest();
16101608
stackmap_table.check_jump_target(
1611-
&current_frame, target, CHECK_VERIFY(this));
1609+
&current_frame, bcs.bci(), bcs.get_offset_s2(), CHECK_VERIFY(this));
16121610
no_control_flow = false; break;
16131611
case Bytecodes::_if_acmpeq :
16141612
case Bytecodes::_if_acmpne :
@@ -1619,19 +1617,16 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
16191617
case Bytecodes::_ifnonnull :
16201618
current_frame.pop_stack(
16211619
VerificationType::reference_check(), CHECK_VERIFY(this));
1622-
target = bcs.dest();
16231620
stackmap_table.check_jump_target
1624-
(&current_frame, target, CHECK_VERIFY(this));
1621+
(&current_frame, bcs.bci(), bcs.get_offset_s2(), CHECK_VERIFY(this));
16251622
no_control_flow = false; break;
16261623
case Bytecodes::_goto :
1627-
target = bcs.dest();
16281624
stackmap_table.check_jump_target(
1629-
&current_frame, target, CHECK_VERIFY(this));
1625+
&current_frame, bcs.bci(), bcs.get_offset_s2(), CHECK_VERIFY(this));
16301626
no_control_flow = true; break;
16311627
case Bytecodes::_goto_w :
1632-
target = bcs.dest_w();
16331628
stackmap_table.check_jump_target(
1634-
&current_frame, target, CHECK_VERIFY(this));
1629+
&current_frame, bcs.bci(), bcs.get_offset_s4(), CHECK_VERIFY(this));
16351630
no_control_flow = true; break;
16361631
case Bytecodes::_tableswitch :
16371632
case Bytecodes::_lookupswitch :
@@ -2280,15 +2275,14 @@ void ClassVerifier::verify_switch(
22802275
}
22812276
}
22822277
}
2283-
int target = bci + default_offset;
2284-
stackmap_table->check_jump_target(current_frame, target, CHECK_VERIFY(this));
2278+
stackmap_table->check_jump_target(current_frame, bci, default_offset, CHECK_VERIFY(this));
22852279
for (int i = 0; i < keys; i++) {
22862280
// Because check_jump_target() may safepoint, the bytecode could have
22872281
// moved, which means 'aligned_bcp' is no good and needs to be recalculated.
22882282
aligned_bcp = align_up(bcs->bcp() + 1, jintSize);
2289-
target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize);
2283+
int offset = (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize);
22902284
stackmap_table->check_jump_target(
2291-
current_frame, target, CHECK_VERIFY(this));
2285+
current_frame, bci, offset, CHECK_VERIFY(this));
22922286
}
22932287
NOT_PRODUCT(aligned_bcp = nullptr); // no longer valid at this point
22942288
}
@@ -2549,7 +2543,12 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
25492543

25502544
case Bytecodes::_goto:
25512545
case Bytecodes::_goto_w: {
2552-
int target = (opcode == Bytecodes::_goto ? bcs.dest() : bcs.dest_w());
2546+
int offset = (opcode == Bytecodes::_goto ? bcs.get_offset_s2() : bcs.get_offset_s4());
2547+
int min_offset = -1 * max_method_code_size;
2548+
// Check offset for overflow
2549+
if (offset < min_offset || offset > max_method_code_size) return false;
2550+
2551+
int target = bci + offset;
25532552
if (visited_branches->contains(bci)) {
25542553
if (bci_stack->is_empty()) {
25552554
if (handler_stack->is_empty()) {
@@ -2607,7 +2606,10 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
26072606

26082607
// Push the switch alternatives onto the stack.
26092608
for (int i = 0; i < keys; i++) {
2610-
int target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize);
2609+
int min_offset = -1 * max_method_code_size;
2610+
int offset = (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize);
2611+
if (offset < min_offset || offset > max_method_code_size) return false;
2612+
int target = bci + offset;
26112613
if (target > code_length) return false;
26122614
bci_stack->push(target);
26132615
}

src/hotspot/share/gc/z/zPageAllocator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ void ZPageAllocator::cleanup_failed_commit_multi_partition(ZMultiPartitionAlloca
19361936
}
19371937

19381938
const size_t committed = allocation->committed_capacity();
1939-
const ZVirtualMemory non_harvested_vmem = vmem.last_part(allocation->harvested());
1939+
const ZVirtualMemory non_harvested_vmem = partial_vmem.last_part(allocation->harvested());
19401940
const ZVirtualMemory committed_vmem = non_harvested_vmem.first_part(committed);
19411941
const ZVirtualMemory non_committed_vmem = non_harvested_vmem.last_part(committed);
19421942

src/hotspot/share/gc/z/zPhysicalMemoryManager.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,20 @@ void ZPhysicalMemoryManager::free(const ZVirtualMemory& vmem, uint32_t numa_id)
214214
});
215215
}
216216

217+
static size_t inject_commit_limit(const ZVirtualMemory& vmem) {
218+
// To facilitate easier interoperability with multi partition allocations we
219+
// divide by ZNUMA::count(). Users of ZFailLargerCommits need to be aware of
220+
// this when writing tests. In the future we could probe the VirtualMemoryManager
221+
// and condition this division on whether the vmem is in the multi partition
222+
// address space.
223+
return align_up(MIN2(ZFailLargerCommits / ZNUMA::count(), vmem.size()), ZGranuleSize);
224+
}
225+
217226
size_t ZPhysicalMemoryManager::commit(const ZVirtualMemory& vmem, uint32_t numa_id) {
218227
zbacking_index* const pmem = _physical_mappings.addr(vmem.start());
219-
const size_t size = vmem.size();
228+
const size_t size = ZFailLargerCommits > 0
229+
? inject_commit_limit(vmem)
230+
: vmem.size();
220231

221232
size_t total_committed = 0;
222233

src/hotspot/share/gc/z/z_globals.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@
118118
develop(bool, ZVerifyOops, false, \
119119
"Verify accessed oops") \
120120
\
121+
develop(size_t, ZFailLargerCommits, 0, \
122+
"Commits larger than ZFailLargerCommits will be truncated, " \
123+
"used to stress page allocation commit failure paths " \
124+
"(0: Disabled)") \
125+
\
121126
develop(uint, ZFakeNUMA, 1, \
122127
"ZFakeNUMA is used to test the internal NUMA memory support " \
123128
"without the need for UseNUMA") \

src/hotspot/share/interpreter/bytecodeStream.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,23 @@ class BaseBytecodeStream: StackObj {
100100
void set_next_bci(int bci) { assert(0 <= bci && bci <= method()->code_size(), "illegal bci"); _next_bci = bci; }
101101

102102
// Bytecode-specific attributes
103-
int dest() const { return bci() + bytecode().get_offset_s2(raw_code()); }
104-
int dest_w() const { return bci() + bytecode().get_offset_s4(raw_code()); }
103+
int get_offset_s2() const { return bytecode().get_offset_s2(raw_code()); }
104+
int get_offset_s4() const { return bytecode().get_offset_s4(raw_code()); }
105+
106+
// These methods are not safe to use before or during verification as they may
107+
// have large offsets and cause overflows
108+
int dest() const {
109+
int min_offset = -1 * max_method_code_size;
110+
int offset = bytecode().get_offset_s2(raw_code());
111+
guarantee(offset >= min_offset && offset <= max_method_code_size, "must be");
112+
return bci() + offset;
113+
}
114+
int dest_w() const {
115+
int min_offset = -1 * max_method_code_size;
116+
int offset = bytecode().get_offset_s4(raw_code());
117+
guarantee(offset >= min_offset && offset <= max_method_code_size, "must be");
118+
return bci() + offset;
119+
}
105120

106121
// One-byte indices.
107122
u1 get_index_u1() const { assert_raw_index_size(1); return *(jubyte*)(bcp()+1); }

src/java.base/share/classes/java/lang/AbstractStringBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,8 @@ public AbstractStringBuilder insert(int dstOffset, CharSequence s,
14481448
shift(currValue, coder, count, dstOffset, len);
14491449
count += len;
14501450
// Coder of CharSequence may be a mismatch, requiring the value array to be inflated
1451-
byte[] newValue = (s instanceof String str)
1452-
? putStringAt(currValue, coder, count, dstOffset, str, start, end)
1451+
byte[] newValue = (s instanceof String str && str.length() == len)
1452+
? putStringAt(currValue, coder, count, dstOffset, str)
14531453
: putCharsAt(currValue, coder, count, dstOffset, s, start, end);
14541454
if (currValue != newValue) {
14551455
this.coder = UTF16;
@@ -1928,10 +1928,10 @@ private static byte[] inflateIfNeededFor(byte[] value, int count, byte coder, by
19281928
* @param index the index to insert the string
19291929
* @param str the string
19301930
*/
1931-
private static byte[] putStringAt(byte[] value, byte coder, int count, int index, String str, int off, int end) {
1931+
private static byte[] putStringAt(byte[] value, byte coder, int count, int index, String str) {
19321932
byte[] newValue = inflateIfNeededFor(value, count, coder, str.coder());
19331933
coder = (newValue == value) ? coder : UTF16;
1934-
str.getBytes(newValue, off, index, coder, end - off);
1934+
str.getBytes(newValue, 0, index, coder, str.length());
19351935
return newValue;
19361936
}
19371937

src/java.base/share/classes/java/time/LocalDate.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ public final class LocalDate
182182
/**
183183
* @serial The month-of-year.
184184
*/
185-
private final byte month;
185+
private final short month;
186186
/**
187187
* @serial The day-of-month.
188188
*/
189-
private final byte day;
189+
private final short day;
190190

191191
//-----------------------------------------------------------------------
192192
/**
@@ -490,8 +490,8 @@ private static LocalDate resolvePreviousValid(int year, int month, int day) {
490490
*/
491491
private LocalDate(int year, int month, int dayOfMonth) {
492492
this.year = year;
493-
this.month = (byte) month;
494-
this.day = (byte) dayOfMonth;
493+
this.month = (short) month;
494+
this.day = (short) dayOfMonth;
495495
}
496496

497497
//-----------------------------------------------------------------------

src/java.base/share/classes/java/time/MonthDay.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ public final class MonthDay
146146
/**
147147
* @serial The month-of-year, not null.
148148
*/
149-
private final byte month;
149+
private final int month;
150150
/**
151151
* @serial The day-of-month.
152152
*/
153-
private final byte day;
153+
private final int day;
154154

155155
//-----------------------------------------------------------------------
156156
/**
@@ -319,8 +319,8 @@ public static MonthDay parse(CharSequence text, DateTimeFormatter formatter) {
319319
* @param dayOfMonth the day-of-month to represent, validated from 1 to 29-31
320320
*/
321321
private MonthDay(int month, int dayOfMonth) {
322-
this.month = (byte) month;
323-
this.day = (byte) dayOfMonth;
322+
this.month = month;
323+
this.day = dayOfMonth;
324324
}
325325

326326
//-----------------------------------------------------------------------

0 commit comments

Comments
 (0)