Skip to content

Commit

Permalink
Merge upstream-jdk
Browse files Browse the repository at this point in the history
  • Loading branch information
corretto-github-robot committed Nov 4, 2023
2 parents 444395e + 504f4a0 commit cc24328
Show file tree
Hide file tree
Showing 48 changed files with 128 additions and 889 deletions.
6 changes: 4 additions & 2 deletions make/JrtfsJar.gmk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -46,8 +46,10 @@ JIMAGE_PKGS := \
jdk/internal/jrtfs \
#

# Compile jrt-fs.jar with the interim compiler, as it
# ends up in the image, this will ensure reproducible classes
$(eval $(call SetupJavaCompilation, BUILD_JRTFS, \
COMPILER := bootjdk, \
COMPILER := interim, \
DISABLED_WARNINGS := options, \
TARGET_RELEASE := $(TARGET_RELEASE_JDK8), \
SRC := $(TOPDIR)/src/java.base/share/classes, \
Expand Down
1 change: 1 addition & 0 deletions make/autoconf/flags-cflags.m4
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_CPU_DEP],
REPRODUCIBLE_CFLAGS=
]
)
AC_SUBST(REPRODUCIBLE_CFLAGS)
fi
# Prevent the __FILE__ macro from generating absolute paths into the built
Expand Down
1 change: 1 addition & 0 deletions make/autoconf/spec.gmk.in
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ LIBFFI_CFLAGS:=@LIBFFI_CFLAGS@
ENABLE_LIBFFI_BUNDLING:=@ENABLE_LIBFFI_BUNDLING@
LIBFFI_LIB_FILE:=@LIBFFI_LIB_FILE@
FILE_MACRO_CFLAGS := @FILE_MACRO_CFLAGS@
REPRODUCIBLE_CFLAGS := @REPRODUCIBLE_CFLAGS@
BRANCH_PROTECTION_CFLAGS := @BRANCH_PROTECTION_CFLAGS@

STATIC_LIBS_CFLAGS := @STATIC_LIBS_CFLAGS@
Expand Down
2 changes: 1 addition & 1 deletion make/hotspot/gensrc/GensrcAdlc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ifeq ($(call check-jvm-feature, compiler2), true)
ADLC_CFLAGS += -I$(TOPDIR)/src/hotspot/share

# Add file macro mappings
ADLC_CFLAGS += $(FILE_MACRO_CFLAGS)
ADLC_CFLAGS += $(FILE_MACRO_CFLAGS) $(REPRODUCIBLE_CFLAGS)

ifeq ($(UBSAN_ENABLED), true)
ADLC_CFLAGS += $(UBSAN_CFLAGS)
Expand Down
11 changes: 4 additions & 7 deletions src/hotspot/cpu/ppc/sharedRuntime_ppc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,6 @@ nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
// --------------------------------------------------------------------------

if (method->is_synchronized()) {
ConditionRegister r_flag = CCR1;
Register r_oop = r_temp_4;
const Register r_box = r_temp_5;
Label done, locked;
Expand All @@ -2472,8 +2471,8 @@ nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,

// Try fastpath for locking.
// fast_lock kills r_temp_1, r_temp_2, r_temp_3.
__ compiler_fast_lock_object(r_flag, r_oop, r_box, r_temp_1, r_temp_2, r_temp_3);
__ beq(r_flag, locked);
__ compiler_fast_lock_object(CCR0, r_oop, r_box, r_temp_1, r_temp_2, r_temp_3);
__ beq(CCR0, locked);

// None of the above fast optimizations worked so we have to get into the
// slow case of monitor enter. Inline a special case of call_VM that
Expand Down Expand Up @@ -2666,8 +2665,6 @@ nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
// --------------------------------------------------------------------------

if (method->is_synchronized()) {

ConditionRegister r_flag = CCR1;
const Register r_oop = r_temp_4;
const Register r_box = r_temp_5;
const Register r_exception = r_temp_6;
Expand All @@ -2684,8 +2681,8 @@ nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
__ addi(r_box, R1_SP, lock_offset);

// Try fastpath for unlocking.
__ compiler_fast_unlock_object(r_flag, r_oop, r_box, r_temp_1, r_temp_2, r_temp_3);
__ beq(r_flag, done);
__ compiler_fast_unlock_object(CCR0, r_oop, r_box, r_temp_1, r_temp_2, r_temp_3);
__ beq(CCR0, done);

// Save and restore any potential method result value around the unlocking operation.
save_native_result(masm, ret_type, workspace_slot_offset);
Expand Down
45 changes: 9 additions & 36 deletions src/hotspot/share/cds/filemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void SharedClassPathEntry::copy_from(SharedClassPathEntry* ent, ClassLoaderData*
_from_class_path_attr = ent->_from_class_path_attr;
set_name(ent->name(), CHECK);

if (ent->is_jar() && !ent->is_signed() && ent->manifest() != nullptr) {
if (ent->is_jar() && ent->manifest() != nullptr) {
Array<u1>* buf = MetadataFactory::new_array<u1>(loader_data,
ent->manifest_size(),
CHECK);
Expand Down Expand Up @@ -622,29 +622,6 @@ class ManifestStream: public ResourceObj {
buf[len] = 0;
return buf;
}

// The return value indicates if the JAR is signed or not
bool check_is_signed() {
u1* attr = _current;
bool isSigned = false;
while (_current < _buffer_end) {
if (*_current == '\n') {
*_current = '\0';
u1* value = (u1*)strchr((char*)attr, ':');
if (value != nullptr) {
assert(*(value+1) == ' ', "Unrecognized format" );
if (strstr((char*)attr, "-Digest") != nullptr) {
isSigned = true;
break;
}
}
*_current = '\n'; // restore
attr = _current + 1;
}
_current ++;
}
return isSigned;
}
};

void FileMapInfo::update_jar_manifest(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS) {
Expand All @@ -657,18 +634,14 @@ void FileMapInfo::update_jar_manifest(ClassPathEntry *cpe, SharedClassPathEntry*
if (manifest != nullptr) {
ManifestStream* stream = new ManifestStream((u1*)manifest,
manifest_size);
if (stream->check_is_signed()) {
ent->set_is_signed();
} else {
// Copy the manifest into the shared archive
manifest = ClassLoaderExt::read_raw_manifest(THREAD, cpe, &manifest_size);
Array<u1>* buf = MetadataFactory::new_array<u1>(loader_data,
manifest_size,
CHECK);
char* p = (char*)(buf->data());
memcpy(p, manifest, manifest_size);
ent->set_manifest(buf);
}
// Copy the manifest into the shared archive
manifest = ClassLoaderExt::read_raw_manifest(THREAD, cpe, &manifest_size);
Array<u1>* buf = MetadataFactory::new_array<u1>(loader_data,
manifest_size,
CHECK);
char* p = (char*)(buf->data());
memcpy(p, manifest, manifest_size);
ent->set_manifest(buf);
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/hotspot/share/cds/filemap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class SharedClassPathEntry : public MetaspaceObj {
enum {
modules_image_entry,
jar_entry,
signed_jar_entry,
dir_entry,
non_existent_entry,
unknown_entry
Expand Down Expand Up @@ -90,10 +89,6 @@ class SharedClassPathEntry : public MetaspaceObj {
bool is_dir() const { return _type == dir_entry; }
bool is_modules_image() const { return _type == modules_image_entry; }
bool is_jar() const { return _type == jar_entry; }
bool is_signed() const { return _type == signed_jar_entry; }
void set_is_signed() {
_type = signed_jar_entry;
}
bool from_class_path_attr() { return _from_class_path_attr; }
time_t timestamp() const { return _timestamp; }
const char* name() const;
Expand Down
8 changes: 6 additions & 2 deletions src/hotspot/share/opto/loopnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4448,6 +4448,7 @@ void PhaseIdealLoop::build_and_optimize() {
NOT_PRODUCT( C->verify_graph_edges(); )
worklist.push(C->top());
build_loop_late( visited, worklist, nstack );
if (C->failing()) { return; }

if (_verify_only) {
C->restore_major_progress(old_progress);
Expand Down Expand Up @@ -5954,6 +5955,7 @@ void PhaseIdealLoop::build_loop_late( VectorSet &visited, Node_List &worklist, N
} else {
// All of n's children have been processed, complete post-processing.
build_loop_late_post(n);
if (C->failing()) { return; }
if (nstack.is_empty()) {
// Finished all nodes on stack.
// Process next node on the worklist.
Expand Down Expand Up @@ -6100,13 +6102,15 @@ void PhaseIdealLoop::build_loop_late_post_work(Node *n, bool pinned) {
Node *legal = LCA; // Walk 'legal' up the IDOM chain
Node *least = legal; // Best legal position so far
while( early != legal ) { // While not at earliest legal
#ifdef ASSERT
if (legal->is_Start() && !early->is_Root()) {
#ifdef ASSERT
// Bad graph. Print idom path and fail.
dump_bad_graph("Bad graph detected in build_loop_late", n, early, LCA);
assert(false, "Bad graph detected in build_loop_late");
}
#endif
C->record_method_not_compilable("Bad graph detected in build_loop_late");
return;
}
// Find least loop nesting depth
legal = idom(legal); // Bump up the IDOM tree
// Check for lower nesting depth
Expand Down
29 changes: 22 additions & 7 deletions test/hotspot/jtreg/runtime/cds/appcds/JarBuilder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -259,21 +259,36 @@ public static void compileModule(Path src,
}
}

static final String keyTool = JDKToolFinder.getJDKTool("keytool");
static final String jarSigner = JDKToolFinder.getJDKTool("jarsigner");

public static void signJar() throws Exception {
String keyTool = JDKToolFinder.getJDKTool("keytool");
String jarSigner = JDKToolFinder.getJDKTool("jarsigner");
public static void signJarWithDisabledAlgorithm(String jarName) throws Exception {
String keyName = "key_with_disabled_alg";
executeProcess(keyTool,
"-genkey", "-keystore", "./keystore", "-alias", keyName,
"-storepass", "abc123", "-keypass", "abc123", "-keyalg", "dsa",
"-sigalg", "SHA1withDSA", "-keysize", "512", "-dname", "CN=jvmtest2")
.shouldHaveExitValue(0);

doSigning(jarName, keyName);
}

public static void signJar(String jarName) throws Exception {
String keyName = "mykey";
executeProcess(keyTool,
"-genkey", "-keystore", "./keystore", "-alias", "mykey",
"-genkey", "-keystore", "./keystore", "-alias", keyName,
"-storepass", "abc123", "-keypass", "abc123", "-keyalg", "dsa",
"-dname", "CN=jvmtest")
.shouldHaveExitValue(0);

doSigning(jarName, keyName);
}

private static void doSigning(String jarName, String keyName) throws Exception {
executeProcess(jarSigner,
"-keystore", "./keystore", "-storepass", "abc123", "-keypass",
"abc123", "-signedjar", getJarFilePath("signed_hello"),
getJarFilePath("hello"), "mykey")
"abc123", "-signedjar", getJarFilePath("signed_" + jarName),
getJarFilePath(jarName), keyName)
.shouldHaveExitValue(0);
}

Expand Down
73 changes: 73 additions & 0 deletions test/hotspot/jtreg/runtime/cds/appcds/SealingViolation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

/*
* @test
* @bug 8312434
* @summary A jar file containing classes in the same package. Sign the jar file with
* a disabled algorithm. The jar will be treated as unsigned.
* Dump only one class into the CDS archive. During runtime, load the class
* stored in the archive and then load another class not from the archive
* but from the same pacakge. Loading of the second class should not result
* in sealing violation.
*
* @requires vm.cds
* @library /test/lib
* @compile test-classes/GenericTestApp.java test-classes/pkg/ClassInPackage.java test-classes/C2.java
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar WhiteBox.jar jdk.test.whitebox.WhiteBox
* @run driver SealingViolation
*/

import jdk.test.lib.helpers.ClassFileInstaller;
import jdk.test.lib.process.OutputAnalyzer;

public class SealingViolation {
public static void main(String[] args) throws Exception {
String[] classList = {"pkg/ClassInPackage"};
String appJar = ClassFileInstaller.writeJar("pkg-classes-sealed.jar",
ClassFileInstaller.Manifest.fromSourceFile("test-classes/pkg/package_seal.mf"),
"GenericTestApp", "pkg/ClassInPackage", "pkg/C2");

JarBuilder.signJarWithDisabledAlgorithm("pkg-classes-sealed");
String signedJar = TestCommon.getTestJar("pkg-classes-sealed.jar");

// GenericTestApp requires WhiteBox
String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar");
String bootclasspath = "-Xbootclasspath/a:" + wbJar;

OutputAnalyzer output = TestCommon.dump(signedJar, classList, bootclasspath,
"-Xlog:cds+class=debug");
output.shouldMatch("cds.class.*klasses.*app pkg.ClassInPackage")
.shouldHaveExitValue(0);

output = TestCommon.exec(signedJar, "-Xlog:cds=debug,class+load",
bootclasspath,
"-XX:+UnlockDiagnosticVMOptions",
"-XX:+WhiteBoxAPI",
"GenericTestApp",
"assertShared:pkg.ClassInPackage",
"assertNotShared:pkg.C2");
output.shouldHaveExitValue(0);
}
}
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/runtime/cds/appcds/SignedJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class SignedJar {
public static void main(String[] args) throws Exception {
String unsignedJar = JarBuilder.getOrCreateHelloJar();
JarBuilder.signJar();
JarBuilder.signJar("hello");

// Test class exists in signed JAR
String signedJar = TestCommon.getTestJar("signed_hello.jar");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Created-By: 1.9.0-internal (Oracle Corporation)

Name: pkg/
Sealed: true

This file was deleted.

This file was deleted.

Loading

0 comments on commit cc24328

Please sign in to comment.