Skip to content

Commit 5c9449f

Browse files
author
Rob McKenna
committed
Merge
2 parents 78808b4 + 2b7f593 commit 5c9449f

File tree

27 files changed

+404
-294
lines changed

27 files changed

+404
-294
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#!/bin/sh
2-
31
#
4-
# Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
53
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
64
#
75
# This code is free software; you can redistribute it and/or modify it
86
# under the terms of the GNU General Public License version 2 only, as
9-
# published by the Free Software Foundation.
7+
# published by the Free Software Foundation. Oracle designates this
8+
# particular file as subject to the "Classpath" exception as provided
9+
# by Oracle in the LICENSE file that accompanied this code.
1010
#
1111
# This code is distributed in the hope that it will be useful, but WITHOUT
1212
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -23,44 +23,10 @@
2323
# questions.
2424
#
2525

26+
################################################################################
2627

27-
# @test
28-
# @bug 4944382
29-
# @summary make sure we do not deadlock loading signed JAR with getInstance()
30-
# @author Andreas Sterbenz
31-
# @build Deadlock
32-
# @run shell/timeout=30 Deadlock.sh
33-
34-
# set platform-dependent variables
35-
OS=`uname -s`
36-
case "$OS" in
37-
Linux )
38-
PATHSEP=":"
39-
FILESEP="/"
40-
;;
41-
Darwin )
42-
PATHSEP=":"
43-
FILESEP="/"
44-
;;
45-
AIX )
46-
PATHSEP=":"
47-
FILESEP="/"
48-
;;
49-
CYGWIN* )
50-
PATHSEP=";"
51-
FILESEP="/"
52-
;;
53-
Windows* )
54-
PATHSEP=";"
55-
FILESEP="\\"
56-
;;
57-
* )
58-
echo "Unrecognized system!"
59-
exit 1;
60-
;;
61-
esac
62-
63-
JAVA="${TESTJAVA}${FILESEP}bin${FILESEP}java"
64-
65-
${JAVA} ${TESTVMOPTS} ${TESTJAVAOPTS} -cp "${TESTCLASSES}${PATHSEP}${TESTSRC}${FILESEP}Deadlock.jar" Deadlock
28+
# Instruct SetupJavaCompilation for the jdk.jlink module to include
29+
# upgrade_files_<module-name>.conf files
30+
COPY += .conf
6631

32+
################################################################################

src/hotspot/share/runtime/os.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,7 @@ char* os::build_agent_function_name(const char *sym_name, const char *lib_name,
25322532
if ((start = strrchr(lib_name, *os::file_separator())) != nullptr) {
25332533
lib_name = ++start;
25342534
}
2535-
#ifdef WINDOWS
2535+
#ifdef _WINDOWS
25362536
else { // Need to check for drive prefix e.g. C:L.dll
25372537
if ((start = strchr(lib_name, ':')) != nullptr) {
25382538
lib_name = ++start;

src/hotspot/share/runtime/safepoint.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ void SafepointSynchronize::disarm_safepoint() {
472472
// operation has been carried out
473473
void SafepointSynchronize::end() {
474474
assert(Threads_lock->owned_by_self(), "must hold Threads_lock");
475+
SafepointTracing::leave();
476+
475477
EventSafepointEnd event;
476478
assert(Thread::current()->is_VM_thread(), "Only VM thread can execute a safepoint");
477479

@@ -866,6 +868,7 @@ void ThreadSafepointState::handle_polling_page_exception() {
866868

867869
jlong SafepointTracing::_last_safepoint_begin_time_ns = 0;
868870
jlong SafepointTracing::_last_safepoint_sync_time_ns = 0;
871+
jlong SafepointTracing::_last_safepoint_leave_time_ns = 0;
869872
jlong SafepointTracing::_last_safepoint_end_time_ns = 0;
870873
jlong SafepointTracing::_last_app_time_ns = 0;
871874
int SafepointTracing::_nof_threads = 0;
@@ -967,6 +970,10 @@ void SafepointTracing::synchronized(int nof_threads, int nof_running, int traps)
967970
RuntimeService::record_safepoint_synchronized(_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns);
968971
}
969972

973+
void SafepointTracing::leave() {
974+
_last_safepoint_leave_time_ns = os::javaTimeNanos();
975+
}
976+
970977
void SafepointTracing::end() {
971978
_last_safepoint_end_time_ns = os::javaTimeNanos();
972979

@@ -985,12 +992,14 @@ void SafepointTracing::end() {
985992
"Time since last: " JLONG_FORMAT " ns, "
986993
"Reaching safepoint: " JLONG_FORMAT " ns, "
987994
"At safepoint: " JLONG_FORMAT " ns, "
995+
"Leaving safepoint: " JLONG_FORMAT " ns, "
988996
"Total: " JLONG_FORMAT " ns",
989997
VM_Operation::name(_current_type),
990998
_last_app_time_ns,
991-
_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns,
992-
_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns,
993-
_last_safepoint_end_time_ns - _last_safepoint_begin_time_ns
999+
_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns,
1000+
_last_safepoint_leave_time_ns - _last_safepoint_sync_time_ns,
1001+
_last_safepoint_end_time_ns - _last_safepoint_leave_time_ns,
1002+
_last_safepoint_end_time_ns - _last_safepoint_begin_time_ns
9941003
);
9951004

9961005
RuntimeService::record_safepoint_end(_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns);

src/hotspot/share/runtime/safepoint.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ class SafepointTracing : public AllStatic {
230230
// Absolute
231231
static jlong _last_safepoint_begin_time_ns;
232232
static jlong _last_safepoint_sync_time_ns;
233+
static jlong _last_safepoint_leave_time_ns;
233234
static jlong _last_safepoint_end_time_ns;
234235

235236
// Relative
@@ -251,6 +252,7 @@ class SafepointTracing : public AllStatic {
251252

252253
static void begin(VM_Operation::VMOp_Type type);
253254
static void synchronized(int nof_threads, int nof_running, int traps);
255+
static void leave();
254256
static void end();
255257

256258
static void statistics_exit_log();

src/hotspot/share/utilities/growableArray.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ void* GrowableArrayArenaAllocator::allocate(int max, int element_size, Arena* ar
4444

4545
void* GrowableArrayCHeapAllocator::allocate(int max, int element_size, MemTag mem_tag) {
4646
assert(max >= 0, "integer overflow");
47+
48+
if (max == 0) {
49+
return nullptr;
50+
}
51+
4752
size_t byte_size = element_size * (size_t) max;
4853

4954
// memory tag has to be specified for C heap allocation

src/hotspot/share/utilities/growableArray.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 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
@@ -811,10 +811,6 @@ class GrowableArrayCHeap : public GrowableArrayWithAllocator<E, GrowableArrayCHe
811811
STATIC_ASSERT(MT != mtNone);
812812

813813
static E* allocate(int max, MemTag mem_tag) {
814-
if (max == 0) {
815-
return nullptr;
816-
}
817-
818814
return (E*)GrowableArrayCHeapAllocator::allocate(max, sizeof(E), mem_tag);
819815
}
820816

src/java.base/share/classes/java/util/jar/Attributes.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 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
@@ -727,6 +727,7 @@ private static void addName(Map<String, Name> names, Name name) {
727727
addName(names, new Name("Created-By"));
728728
addName(names, new Name("SHA1-Digest"));
729729
addName(names, new Name("SHA-256-Digest"));
730+
addName(names, new Name("SHA-384-Digest"));
730731
KNOWN_NAMES = Map.copyOf(names);
731732
} else {
732733
// Even if KNOWN_NAMES was read from archive, we still need

src/java.desktop/share/classes/com/sun/beans/finder/MethodFinder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 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
@@ -77,8 +77,7 @@ public static Method findMethod(Class<?> type, String name, Class<?>...args) thr
7777
Signature signature = new Signature(type, name, args);
7878

7979
try {
80-
Method method = CACHE.get(signature);
81-
return (method == null) ? method : CACHE.create(signature);
80+
return CACHE.get(signature);
8281
}
8382
catch (SignatureException exception) {
8483
throw exception.toNoSuchMethodException("Method '" + name + "' is not found");

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JRTArchive.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.List;
4646
import java.util.Map;
4747
import java.util.Objects;
48+
import java.util.Set;
4849
import java.util.function.Function;
4950
import java.util.function.Predicate;
5051
import java.util.stream.Collectors;
@@ -76,6 +77,7 @@ public class JRTArchive implements Archive {
7677
private final Map<String, ResourceDiff> resDiff;
7778
private final boolean errorOnModifiedFile;
7879
private final TaskHelper taskHelper;
80+
private final Set<String> upgradeableFiles;
7981

8082
/**
8183
* JRTArchive constructor
@@ -86,12 +88,15 @@ public class JRTArchive implements Archive {
8688
* install aborts the link.
8789
* @param perModDiff The lib/modules (a.k.a jimage) diff for this module,
8890
* possibly an empty list if there are no differences.
91+
* @param taskHelper The task helper instance.
92+
* @param upgradeableFiles The set of files that are allowed for upgrades.
8993
*/
9094
JRTArchive(String module,
9195
Path path,
9296
boolean errorOnModifiedFile,
9397
List<ResourceDiff> perModDiff,
94-
TaskHelper taskHelper) {
98+
TaskHelper taskHelper,
99+
Set<String> upgradeableFiles) {
95100
this.module = module;
96101
this.path = path;
97102
this.ref = ModuleFinder.ofSystem()
@@ -105,6 +110,7 @@ public class JRTArchive implements Archive {
105110
this.resDiff = Objects.requireNonNull(perModDiff).stream()
106111
.collect(Collectors.toMap(ResourceDiff::getName, Function.identity()));
107112
this.taskHelper = taskHelper;
113+
this.upgradeableFiles = upgradeableFiles;
108114
}
109115

110116
@Override
@@ -217,7 +223,8 @@ private void addNonClassResources() {
217223

218224
// Read from the base JDK image.
219225
Path path = BASE.resolve(m.resPath);
220-
if (shaSumMismatch(path, m.hashOrTarget, m.symlink)) {
226+
if (!isUpgradeableFile(m.resPath) &&
227+
shaSumMismatch(path, m.hashOrTarget, m.symlink)) {
221228
if (errorOnModifiedFile) {
222229
String msg = taskHelper.getMessage("err.runtime.link.modified.file", path.toString());
223230
IOException cause = new IOException(msg);
@@ -239,6 +246,17 @@ private void addNonClassResources() {
239246
}
240247
}
241248

249+
/**
250+
* Certain files in a module are considered upgradeable. That is,
251+
* their hash sums aren't checked.
252+
*
253+
* @param resPath The resource path of the file to check for upgradeability.
254+
* @return {@code true} if the file is upgradeable. {@code false} otherwise.
255+
*/
256+
private boolean isUpgradeableFile(String resPath) {
257+
return upgradeableFiles.contains(resPath);
258+
}
259+
242260
static boolean shaSumMismatch(Path res, String expectedSha, boolean isSymlink) {
243261
if (isSymlink) {
244262
return false;

src/jdk.jlink/share/classes/jdk/tools/jlink/internal/LinkableRuntimeImage.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
import java.io.IOException;
2929
import java.io.InputStream;
3030
import java.nio.file.Path;
31+
import java.util.HashSet;
3132
import java.util.List;
33+
import java.util.Scanner;
34+
import java.util.Set;
3235

3336
import jdk.tools.jlink.internal.runtimelink.ResourceDiff;
3437

@@ -42,6 +45,9 @@ public class LinkableRuntimeImage {
4245
public static final String RESPATH_PATTERN = "jdk/tools/jlink/internal/runtimelink/fs_%s_files";
4346
// The diff files per module for supporting linking from the run-time image
4447
public static final String DIFF_PATTERN = "jdk/tools/jlink/internal/runtimelink/diff_%s";
48+
// meta data for upgradable files
49+
private static final String UPGRADEABLE_FILES_PATTERN = "jdk/tools/jlink/internal/runtimelink/upgrade_files_%s.conf";
50+
private static final Module JDK_JLINK_MOD = LinkableRuntimeImage.class.getModule();
4551

4652
/**
4753
* In order to be able to show whether or not a runtime is capable of
@@ -62,7 +68,38 @@ public static boolean isLinkableRuntime() {
6268

6369
private static InputStream getDiffInputStream(String module) throws IOException {
6470
String resourceName = String.format(DIFF_PATTERN, module);
65-
return LinkableRuntimeImage.class.getModule().getResourceAsStream(resourceName);
71+
return JDK_JLINK_MOD.getResourceAsStream(resourceName);
72+
}
73+
74+
private static Set<String> upgradeableFiles(String module) {
75+
String resourceName = String.format(UPGRADEABLE_FILES_PATTERN, module);
76+
InputStream filesIn = null;
77+
try {
78+
filesIn = JDK_JLINK_MOD.getResourceAsStream(resourceName);
79+
} catch (IOException e) {
80+
throw new AssertionError("Unexpected IO error getting res stream");
81+
}
82+
if (filesIn == null) {
83+
// no upgradeable files
84+
return Set.of();
85+
}
86+
Set<String> upgradeableFiles = new HashSet<>();
87+
final InputStream in = filesIn;
88+
try (in;
89+
Scanner scanner = new Scanner(filesIn)) {
90+
while (scanner.hasNextLine()) {
91+
String line = scanner.nextLine();
92+
if (line.trim().startsWith("#")) {
93+
// Skip comments
94+
continue;
95+
}
96+
upgradeableFiles.add(scanner.nextLine());
97+
}
98+
} catch (IOException e) {
99+
throw new AssertionError("Failure to retrieve upgradeable files for " +
100+
"module " + module, e);
101+
}
102+
return upgradeableFiles;
66103
}
67104

68105
public static Archive newArchive(String module,
@@ -81,7 +118,13 @@ public static Archive newArchive(String module,
81118
throw new AssertionError("Failure to retrieve resource diff for " +
82119
"module " + module, e);
83120
}
84-
return new JRTArchive(module, path, !ignoreModifiedRuntime, perModuleDiff, taskHelper);
121+
Set<String> upgradeableFiles = upgradeableFiles(module);
122+
return new JRTArchive(module,
123+
path,
124+
!ignoreModifiedRuntime,
125+
perModuleDiff,
126+
taskHelper,
127+
upgradeableFiles);
85128
}
86129

87130

0 commit comments

Comments
 (0)