Skip to content

Commit e06115c

Browse files
committed
Merge
2 parents d35cb91 + c5c90ff commit e06115c

File tree

4 files changed

+82
-34
lines changed

4 files changed

+82
-34
lines changed

make/conf/version-numbers.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it

src/hotspot/share/opto/subnode.cpp

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,44 +1483,86 @@ Node *BoolNode::Ideal(PhaseGVN *phase, bool can_reshape) {
14831483
return new BoolNode( ncmp, _test.negate() );
14841484
}
14851485

1486-
// Change ((x & m) u<= m) or ((m & x) u<= m) to always true
1487-
// Same with ((x & m) u< m+1) and ((m & x) u< m+1)
1486+
// We use the following Lemmas/insights for the following two transformations (1) and (2):
1487+
// x & y <=u y, for any x and y (Lemma 1, masking always results in a smaller unsigned number)
1488+
// y <u y + 1 is always true if y != -1 (Lemma 2, (uint)(-1 + 1) == (uint)(UINT_MAX + 1) which overflows)
1489+
// y <u 0 is always false for any y (Lemma 3, 0 == UINT_MIN and nothing can be smaller than that)
1490+
//
1491+
// (1a) Always: Change ((x & m) <=u m ) or ((m & x) <=u m ) to always true (true by Lemma 1)
1492+
// (1b) If m != -1: Change ((x & m) <u m + 1) or ((m & x) <u m + 1) to always true:
1493+
// x & m <=u m is always true // (Lemma 1)
1494+
// x & m <=u m <u m + 1 is always true // (Lemma 2: m <u m + 1, if m != -1)
1495+
//
1496+
// A counter example for (1b), if we allowed m == -1:
1497+
// (x & m) <u m + 1
1498+
// (x & -1) <u 0
1499+
// x <u 0
1500+
// which is false for any x (Lemma 3)
14881501
if (cop == Op_CmpU &&
14891502
cmp1_op == Op_AndI) {
1490-
Node* bound = nullptr;
1503+
Node* m = nullptr;
14911504
if (_test._test == BoolTest::le) {
1492-
bound = cmp2;
1505+
// (1a) "((x & m) <=u m)", cmp2 = m
1506+
m = cmp2;
14931507
} else if (_test._test == BoolTest::lt &&
14941508
cmp2->Opcode() == Op_AddI &&
14951509
cmp2->in(2)->find_int_con(0) == 1) {
1496-
bound = cmp2->in(1);
1510+
// (1b) "(x & m) <u m + 1" and "(m & x) <u m + 1", cmp2 = m + 1
1511+
Node* rhs_m = cmp2->in(1);
1512+
const TypeInt* rhs_m_type = phase->type(rhs_m)->isa_int();
1513+
if (rhs_m_type->_lo > -1 || rhs_m_type->_hi < -1) {
1514+
// Exclude any case where m == -1 is possible.
1515+
m = rhs_m;
1516+
}
14971517
}
1498-
if (cmp1->in(2) == bound || cmp1->in(1) == bound) {
1518+
if (cmp1->in(2) == m || cmp1->in(1) == m) {
14991519
return ConINode::make(1);
15001520
}
15011521
}
15021522

1503-
// Change ((x & (m - 1)) u< m) into (m > 0)
1504-
// This is the off-by-one variant of the above
1523+
// (2) Change ((x & (m - 1)) <u m) or (((m - 1) & x) <u m) to (m >u 0)
1524+
// This is the off-by-one variant of the above.
1525+
//
1526+
// We now prove that this replacement is correct. This is the same as proving
1527+
// "m >u 0" if and only if "x & (m - 1) <u m", i.e. "m >u 0 <=> x & (m - 1) <u m"
1528+
//
1529+
// We use (Lemma 1) and (Lemma 3) from above.
1530+
//
1531+
// Case "x & (m - 1) <u m => m >u 0":
1532+
// We prove this by contradiction:
1533+
// Assume m <=u 0 which is equivalent to m == 0:
1534+
// and thus
1535+
// x & (m - 1) <u m = 0 // m == 0
1536+
// y <u 0 // y = x & (m - 1)
1537+
// by Lemma 3, this is always false, i.e. a contradiction to our assumption.
1538+
//
1539+
// Case "m >u 0 => x & (m - 1) <u m":
1540+
// x & (m - 1) <=u (m - 1) // (Lemma 1)
1541+
// x & (m - 1) <=u (m - 1) <u m // Using assumption m >u 0, no underflow of "m - 1"
1542+
//
1543+
//
1544+
// Note that the signed version of "m > 0":
1545+
// m > 0 <=> x & (m - 1) <u m
1546+
// does not hold:
1547+
// Assume m == -1 and x == -1:
1548+
// x & (m - 1) <u m
1549+
// -1 & -2 <u -1
1550+
// -2 <u -1
1551+
// UINT_MAX - 1 <u UINT_MAX // Signed to unsigned numbers
1552+
// which is true while
1553+
// m > 0
1554+
// is false which is a contradiction.
15051555
if (cop == Op_CmpU &&
15061556
_test._test == BoolTest::lt &&
15071557
cmp1_op == Op_AndI) {
1508-
Node* l = cmp1->in(1);
1509-
Node* r = cmp1->in(2);
1510-
for (int repeat = 0; repeat < 2; repeat++) {
1511-
bool match = r->Opcode() == Op_AddI && r->in(2)->find_int_con(0) == -1 &&
1512-
r->in(1) == cmp2;
1513-
if (match) {
1514-
// arraylength known to be non-negative, so a (arraylength != 0) is sufficient,
1515-
// but to be compatible with the array range check pattern, use (arraylength u> 0)
1516-
Node* ncmp = cmp2->Opcode() == Op_LoadRange
1517-
? phase->transform(new CmpUNode(cmp2, phase->intcon(0)))
1518-
: phase->transform(new CmpINode(cmp2, phase->intcon(0)));
1519-
return new BoolNode(ncmp, BoolTest::gt);
1520-
} else {
1521-
// commute and try again
1522-
l = cmp1->in(2);
1523-
r = cmp1->in(1);
1558+
Node* m = cmp2; // RHS: m
1559+
for (int add_idx = 1; add_idx <= 2; add_idx++) { // LHS: "(m + (-1)) & x" or "x & (m + (-1))"?
1560+
Node* maybe_m_minus_1 = cmp1->in(add_idx);
1561+
if (maybe_m_minus_1->Opcode() == Op_AddI &&
1562+
maybe_m_minus_1->in(2)->find_int_con(0) == -1 &&
1563+
maybe_m_minus_1->in(1) == m) {
1564+
Node* m_cmpu_0 = phase->transform(new CmpUNode(m, phase->intcon(0)));
1565+
return new BoolNode(m_cmpu_0, BoolTest::gt);
15241566
}
15251567
}
15261568
}

src/java.base/windows/classes/java/lang/ProcessImpl.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,14 @@ private static String[] getTokensFromCommand(String command) {
216216
private static final int VERIFICATION_LEGACY = 3;
217217
// See Command shell overview for documentation of special characters.
218218
// https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490954(v=technet.10)
219-
private static final char ESCAPE_VERIFICATION[][] = {
219+
private static final String ESCAPE_VERIFICATION[] = {
220220
// We guarantee the only command file execution for implicit [cmd.exe] run.
221221
// http://technet.microsoft.com/en-us/library/bb490954.aspx
222-
{' ', '\t', '\"', '<', '>', '&', '|', '^'},
223-
{' ', '\t', '\"', '<', '>'},
224-
{' ', '\t', '\"', '<', '>'},
225-
{' ', '\t'}
222+
// All space characters require quoting are checked in needsEscaping().
223+
"\"<>&|^",
224+
"\"<>",
225+
"\"<>",
226+
""
226227
};
227228

228229
private static String createCommandLine(int verificationType,
@@ -337,9 +338,14 @@ private static boolean needsEscaping(int verificationType, String arg) {
337338
}
338339

339340
if (!argIsQuoted) {
340-
char testEscape[] = ESCAPE_VERIFICATION[verificationType];
341-
for (int i = 0; i < testEscape.length; ++i) {
342-
if (arg.indexOf(testEscape[i]) >= 0) {
341+
for (int i = 0; i < arg.length(); i++) {
342+
char ch = arg.charAt(i);
343+
if (Character.isLetterOrDigit(ch))
344+
continue; // skip over common characters
345+
// All space chars require quotes and other mode specific characters
346+
if (Character.isSpaceChar(ch) ||
347+
Character.isWhitespace(ch) ||
348+
ESCAPE_VERIFICATION[verificationType].indexOf(ch) >= 0) {
343349
return true;
344350
}
345351
}

src/java.desktop/share/native/libawt/java2d/SurfaceData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef struct {
6060

6161
#define UNSAFE_TO_SUB(a, b) \
6262
(((b >= 0) && (a < 0) && (a < (INT_MIN + b))) || \
63-
((b < 0) && (a >= 0) && (-b > (INT_MAX - a)))) \
63+
((b < 0) && (a >= 0) && (a > (INT_MAX + b)))) \
6464

6565
/*
6666
* The SurfaceDataRasInfo structure is used to pass in and return various

0 commit comments

Comments
 (0)