Skip to content

Commit 211a455

Browse files
authored
Merge branch 'openjdk:master' into goetz_backport_8342075
2 parents 25f2f0b + 4b2d777 commit 211a455

File tree

17 files changed

+1241
-388
lines changed

17 files changed

+1241
-388
lines changed

make/RunTestsPrebuilt.gmk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ else ifeq ($(OPENJDK_TARGET_OS), macosx)
216216
else ifeq ($(OPENJDK_TARGET_OS), windows)
217217
NUM_CORES := $(NUMBER_OF_PROCESSORS)
218218
MEMORY_SIZE := $(shell \
219-
$(EXPR) `wmic computersystem get totalphysicalmemory -value \
220-
| $(GREP) = | $(SED) 's/\\r//g' \
221-
| $(CUT) -d "=" -f 2-` / 1024 / 1024 \
219+
$(EXPR) `powershell -Command \
220+
"(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory" \
221+
| $(SED) 's/\\r//g' ` / 1024 / 1024 \
222222
)
223223
endif
224224
ifeq ($(NUM_CORES), )

make/autoconf/build-performance.m4

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2020, 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
@@ -85,7 +85,8 @@ AC_DEFUN([BPERF_CHECK_MEMORY_SIZE],
8585
FOUND_MEM=yes
8686
elif test "x$OPENJDK_BUILD_OS" = xwindows; then
8787
# Windows, but without cygwin
88-
MEMORY_SIZE=`wmic computersystem get totalphysicalmemory -value | grep = | cut -d "=" -f 2-`
88+
MEMORY_SIZE=`powershell -Command \
89+
"(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory" | $SED 's/\\r//g' `
8990
MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024`
9091
FOUND_MEM=yes
9192
fi

src/java.base/share/classes/java/math/BigInteger.java

Lines changed: 160 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,18 @@ public BigInteger(byte[] val, int off, int len) {
312312
throw new NumberFormatException("Zero length BigInteger");
313313
}
314314
Objects.checkFromIndexSize(off, len, val.length);
315+
if (len == 0) {
316+
mag = ZERO.mag;
317+
signum = ZERO.signum;
318+
return;
319+
}
315320

316-
if (val[off] < 0) {
317-
mag = makePositive(val, off, len);
321+
int b = val[off];
322+
if (b < 0) {
323+
mag = makePositive(b, val, off, len);
318324
signum = -1;
319325
} else {
320-
mag = stripLeadingZeroBytes(val, off, len);
326+
mag = stripLeadingZeroBytes(b, val, off, len);
321327
signum = (mag.length == 0 ? 0 : 1);
322328
}
323329
if (mag.length >= MAX_MAG_LENGTH) {
@@ -4438,77 +4444,168 @@ private static int[] trustedStripLeadingZeroInts(int val[]) {
44384444
return keep == 0 ? val : java.util.Arrays.copyOfRange(val, keep, vlen);
44394445
}
44404446

4441-
/**
4447+
private static int[] stripLeadingZeroBytes(byte[] a, int from, int len) {
4448+
return stripLeadingZeroBytes(Integer.MIN_VALUE, a, from, len);
4449+
}
4450+
4451+
/*
44424452
* Returns a copy of the input array stripped of any leading zero bytes.
4453+
* The returned array is either empty, or its 0-th element is non-zero,
4454+
* meeting the "minimal" requirement for field mag (see comment on mag).
4455+
*
4456+
* The range [from, from + len) must be well-formed w.r.t. array a.
4457+
*
4458+
* b < -128 means that a[from] has not yet been read.
4459+
* Otherwise, b must be a[from], have been read only once before invoking
4460+
* this method, and len > 0 must hold.
44434461
*/
4444-
private static int[] stripLeadingZeroBytes(byte a[], int off, int len) {
4445-
int indexBound = off + len;
4446-
int keep;
44474462

4448-
// Find first nonzero byte
4449-
for (keep = off; keep < indexBound && a[keep] == 0; keep++)
4450-
;
4451-
4452-
// Allocate new array and copy relevant part of input array
4453-
int intLength = ((indexBound - keep) + 3) >>> 2;
4454-
int[] result = new int[intLength];
4455-
int b = indexBound - 1;
4456-
for (int i = intLength-1; i >= 0; i--) {
4457-
result[i] = a[b--] & 0xff;
4458-
int bytesRemaining = b - keep + 1;
4459-
int bytesToTransfer = Math.min(3, bytesRemaining);
4460-
for (int j=8; j <= (bytesToTransfer << 3); j += 8)
4461-
result[i] |= ((a[b--] & 0xff) << j);
4463+
private static int[] stripLeadingZeroBytes(int b, byte[] a, int from, int len) {
4464+
/*
4465+
* Except for the first byte, each read access to the input array a
4466+
* is of the form a[from++].
4467+
* The index from is never otherwise altered, except right below,
4468+
* and only increases in steps of 1, always up to index to.
4469+
* Hence, each byte in the array is read exactly once, from lower to
4470+
* higher indices (from most to least significant byte).
4471+
*/
4472+
if (len == 0) {
4473+
return ZERO.mag;
44624474
}
4463-
return result;
4475+
int to = from + len;
4476+
if (b < -128) {
4477+
b = a[from];
4478+
}
4479+
/* Either way, a[from] has now been read exactly once, skip to next. */
4480+
++from;
4481+
/*
4482+
* Set up the shortest int[] for the sequence of the bytes
4483+
* b, a[from+1], ..., a[to-1] (len > 0)
4484+
* Shortest means first skipping leading zeros.
4485+
*/
4486+
for (; b == 0 && from < to; b = a[from++])
4487+
; //empty body
4488+
if (b == 0) {
4489+
/* Here, from == to as well. All bytes are zeros. */
4490+
return ZERO.mag;
4491+
}
4492+
/*
4493+
* Allocate just enough ints to hold (to - from + 1) bytes, that is
4494+
* ((to - from + 1) + 3) / 4 = (to - from) / 4 + 1
4495+
*/
4496+
int[] res = new int[((to - from) >> 2) + 1];
4497+
/*
4498+
* A "digit" is a group of 4 adjacent bytes aligned w.r.t. index to.
4499+
* (Implied 0 bytes are prepended as needed.)
4500+
* b is the most significant byte not 0.
4501+
* Digit d0 spans the range of indices that includes current (from - 1).
4502+
*/
4503+
int d0 = b & 0xFF;
4504+
while (((to - from) & 0x3) != 0) {
4505+
d0 = d0 << 8 | a[from++] & 0xFF;
4506+
}
4507+
res[0] = d0;
4508+
/*
4509+
* Prepare the remaining digits.
4510+
* (to - from) is a multiple of 4, so prepare an int for every 4 bytes.
4511+
* This is a candidate for Unsafe.copy[Swap]Memory().
4512+
*/
4513+
int i = 1;
4514+
while (from < to) {
4515+
res[i++] = a[from++] << 24 | (a[from++] & 0xFF) << 16
4516+
| (a[from++] & 0xFF) << 8 | (a[from++] & 0xFF);
4517+
}
4518+
return res;
44644519
}
44654520

4466-
/**
4521+
/*
44674522
* Takes an array a representing a negative 2's-complement number and
44684523
* returns the minimal (no leading zero bytes) unsigned whose value is -a.
4524+
*
4525+
* len > 0 must hold.
4526+
* The range [from, from + len) must be well-formed w.r.t. array a.
4527+
* b is assumed to be the result of reading a[from] and to meet b < 0.
44694528
*/
4470-
private static int[] makePositive(byte a[], int off, int len) {
4471-
int keep, k;
4472-
int indexBound = off + len;
4473-
4474-
// Find first non-sign (0xff) byte of input
4475-
for (keep=off; keep < indexBound && a[keep] == -1; keep++)
4476-
;
4477-
4478-
4479-
/* Allocate output array. If all non-sign bytes are 0x00, we must
4480-
* allocate space for one extra output byte. */
4481-
for (k=keep; k < indexBound && a[k] == 0; k++)
4482-
;
4483-
4484-
int extraByte = (k == indexBound) ? 1 : 0;
4485-
int intLength = ((indexBound - keep + extraByte) + 3) >>> 2;
4486-
int result[] = new int[intLength];
4487-
4488-
/* Copy one's complement of input into output, leaving extra
4489-
* byte (if it exists) == 0x00 */
4490-
int b = indexBound - 1;
4491-
for (int i = intLength-1; i >= 0; i--) {
4492-
result[i] = a[b--] & 0xff;
4493-
int numBytesToTransfer = Math.min(3, b-keep+1);
4494-
if (numBytesToTransfer < 0)
4495-
numBytesToTransfer = 0;
4496-
for (int j=8; j <= 8*numBytesToTransfer; j += 8)
4497-
result[i] |= ((a[b--] & 0xff) << j);
4498-
4499-
// Mask indicates which bits must be complemented
4500-
int mask = -1 >>> (8*(3-numBytesToTransfer));
4501-
result[i] = ~result[i] & mask;
4529+
private static int[] makePositive(int b, byte[] a, int from, int len) {
4530+
/*
4531+
* By assumption, b == a[from] < 0 and len > 0.
4532+
*
4533+
* First collect the bytes into the resulting array res.
4534+
* Then convert res to two's complement.
4535+
*
4536+
* Except for b == a[from], each read access to the input array a
4537+
* is of the form a[from++].
4538+
* The index from is never otherwise altered, except right below,
4539+
* and only increases in steps of 1, always up to index to.
4540+
* Hence, each byte in the array is read exactly once, from lower to
4541+
* higher indices (from most to least significant byte).
4542+
*/
4543+
int to = from + len;
4544+
/* b == a[from] has been read exactly once, skip to next index. */
4545+
++from;
4546+
/* Skip leading -1 bytes. */
4547+
for (; b == -1 && from < to; b = a[from++])
4548+
; //empty body
4549+
/*
4550+
* A "digit" is a group of 4 adjacent bytes aligned w.r.t. index to.
4551+
* b is the most significant byte not -1, or -1 only if from == to.
4552+
* Digit d0 spans the range of indices that includes current (from - 1).
4553+
* (Implied -1 bytes are prepended to array a as needed.)
4554+
* It usually corresponds to res[0], except for the special case below.
4555+
*/
4556+
int d0 = -1 << 8 | b & 0xFF;
4557+
while (((to - from) & 0x3) != 0) {
4558+
d0 = d0 << 8 | (b = a[from++]) & 0xFF;
4559+
}
4560+
int f = from; // keeps the current from for sizing purposes later
4561+
/* Skip zeros adjacent to d0, if at all. */
4562+
for (; b == 0 && from < to; b = a[from++])
4563+
; //empty body
4564+
/*
4565+
* b is the most significant non-zero byte at or after (f - 1),
4566+
* or 0 only if from == to.
4567+
* Digit d spans the range of indices that includes (f - 1).
4568+
*/
4569+
int d = b & 0xFF;
4570+
while (((to - from) & 0x3) != 0) {
4571+
d = d << 8 | a[from++] & 0xFF;
45024572
}
4503-
4504-
// Add one to one's complement to generate two's complement
4505-
for (int i=result.length-1; i >= 0; i--) {
4506-
result[i] = (int)((result[i] & LONG_MASK) + 1);
4507-
if (result[i] != 0)
4508-
break;
4573+
/*
4574+
* If the situation here is like this:
4575+
* index: f to == from
4576+
* ..., -1,-1, 0,0,0,0, 0,0,0,0, ..., 0,0,0,0
4577+
* digit: d0 d
4578+
* then, as shown, the number of zeros is a positive multiple of 4.
4579+
* The array res needs a minimal length of (1 + 1 + (to - f) / 4)
4580+
* to accommodate the two's complement, including a leading 1.
4581+
* In any other case, there is at least one byte that is non-zero.
4582+
* The array for the two's complement has length (0 + 1 + (to - f) / 4).
4583+
* c is 1, resp., 0 for the two situations.
4584+
*/
4585+
int c = (to - from | d0 | d) == 0 ? 1 : 0;
4586+
int[] res = new int[c + 1 + ((to - f) >> 2)];
4587+
res[0] = c == 0 ? d0 : -1;
4588+
int i = res.length - ((to - from) >> 2);
4589+
if (i > 1) {
4590+
res[i - 1] = d;
45094591
}
4510-
4511-
return result;
4592+
/*
4593+
* Prepare the remaining digits.
4594+
* (to - from) is a multiple of 4, so prepare an int for every 4 bytes.
4595+
* This is a candidate for Unsafe.copy[Swap]Memory().
4596+
*/
4597+
while (from < to) {
4598+
res[i++] = a[from++] << 24 | (a[from++] & 0xFF) << 16
4599+
| (a[from++] & 0xFF) << 8 | (a[from++] & 0xFF);
4600+
}
4601+
/* Convert to two's complement. Here, i == res.length */
4602+
while (--i >= 0 && res[i] == 0)
4603+
; // empty body
4604+
res[i] = -res[i];
4605+
while (--i >= 0) {
4606+
res[i] = ~res[i];
4607+
}
4608+
return res;
45124609
}
45134610

45144611
/**

src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2024, 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
@@ -42,22 +42,22 @@
4242
import java.security.spec.PSSParameterSpec;
4343
import java.time.DateTimeException;
4444
import java.time.Instant;
45-
import java.time.ZonedDateTime;
4645
import java.time.ZoneId;
46+
import java.time.ZonedDateTime;
4747
import java.util.ArrayList;
4848
import java.util.Arrays;
49+
import java.util.Collection;
4950
import java.util.Date;
5051
import java.util.HashMap;
5152
import java.util.HashSet;
5253
import java.util.List;
5354
import java.util.Locale;
5455
import java.util.Map;
5556
import java.util.Set;
56-
import java.util.Collection;
5757
import java.util.StringTokenizer;
5858
import java.util.concurrent.ConcurrentHashMap;
59-
import java.util.regex.Pattern;
6059
import java.util.regex.Matcher;
60+
import java.util.regex.Pattern;
6161

6262
/**
6363
* Algorithm constraints for disabled algorithms property
@@ -102,6 +102,7 @@ private static class JarHolder {
102102
}
103103

104104
private final Set<String> disabledAlgorithms;
105+
private final List<Pattern> disabledPatterns;
105106
private final Constraints algorithmConstraints;
106107
private volatile SoftReference<Map<String, Boolean>> cacheRef =
107108
new SoftReference<>(null);
@@ -137,6 +138,13 @@ public DisabledAlgorithmConstraints(String propertyName,
137138
super(decomposer);
138139
disabledAlgorithms = getAlgorithms(propertyName);
139140

141+
// Support patterns only for jdk.tls.disabledAlgorithms
142+
if (PROPERTY_TLS_DISABLED_ALGS.equals(propertyName)) {
143+
disabledPatterns = getDisabledPatterns();
144+
} else {
145+
disabledPatterns = null;
146+
}
147+
140148
// Check for alias
141149
for (String s : disabledAlgorithms) {
142150
Matcher matcher = INCLUDE_PATTERN.matcher(s);
@@ -976,11 +984,48 @@ private boolean cachedCheckAlgorithm(String algorithm) {
976984
if (result != null) {
977985
return result;
978986
}
979-
result = checkAlgorithm(disabledAlgorithms, algorithm, decomposer);
987+
// We won't check patterns if algorithm check fails.
988+
result = checkAlgorithm(disabledAlgorithms, algorithm, decomposer)
989+
&& checkDisabledPatterns(algorithm);
980990
cache.put(algorithm, result);
981991
return result;
982992
}
983993

994+
private boolean checkDisabledPatterns(final String algorithm) {
995+
return disabledPatterns == null || disabledPatterns.stream().noneMatch(
996+
p -> p.matcher(algorithm).matches());
997+
}
998+
999+
private List<Pattern> getDisabledPatterns() {
1000+
List<Pattern> ret = null;
1001+
List<String> patternStrings = new ArrayList<>(4);
1002+
1003+
for (String p : disabledAlgorithms) {
1004+
if (p.contains("*")) {
1005+
if (!p.startsWith("TLS_")) {
1006+
throw new IllegalArgumentException(
1007+
"Wildcard pattern must start with \"TLS_\"");
1008+
}
1009+
patternStrings.add(p);
1010+
}
1011+
}
1012+
1013+
if (!patternStrings.isEmpty()) {
1014+
ret = new ArrayList<>(patternStrings.size());
1015+
1016+
for (String p : patternStrings) {
1017+
// Exclude patterns from algorithm code flow.
1018+
disabledAlgorithms.remove(p);
1019+
1020+
// Ignore all regex characters but asterisk.
1021+
ret.add(Pattern.compile(
1022+
"^\\Q" + p.replace("*", "\\E.*\\Q") + "\\E$"));
1023+
}
1024+
}
1025+
1026+
return ret;
1027+
}
1028+
9841029
/*
9851030
* This constraint is used for the complete disabling of the algorithm.
9861031
*/

0 commit comments

Comments
 (0)