Skip to content
Permalink
Browse files
8272348: Update CDS tests in anticipation of JDK-8270489
Reviewed-by: ccheung, minqi
  • Loading branch information
iklam committed Aug 16, 2021
1 parent 3f38a50 commit 36e2ddad4d2ef3ce27475af6244d0246a8315c0c
Showing 23 changed files with 85 additions and 56 deletions.
@@ -1936,12 +1936,20 @@ WB_ENTRY(jboolean, WB_IsShared(JNIEnv* env, jobject wb, jobject obj))
return Universe::heap()->is_archived_object(obj_oop);
WB_END

WB_ENTRY(jboolean, WB_IsSharedInternedString(JNIEnv* env, jobject wb, jobject str))
ResourceMark rm(THREAD);
oop str_oop = JNIHandles::resolve(str);
int length;
jchar* chars = java_lang_String::as_unicode_string(str_oop, length, CHECK_(false));
return StringTable::lookup_shared(chars, length) == str_oop;
WB_END

WB_ENTRY(jboolean, WB_IsSharedClass(JNIEnv* env, jobject wb, jclass clazz))
return (jboolean)MetaspaceShared::is_in_shared_metaspace(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
WB_END

WB_ENTRY(jboolean, WB_AreSharedStringsIgnored(JNIEnv* env))
return !HeapShared::closed_regions_mapped();
WB_ENTRY(jboolean, WB_AreSharedStringsMapped(JNIEnv* env))
return HeapShared::closed_regions_mapped();
WB_END

WB_ENTRY(jobject, WB_GetResolvedReferences(JNIEnv* env, jobject wb, jclass clazz))
@@ -2625,8 +2633,9 @@ static JNINativeMethod methods[] = {
(void*)&WB_GetDefaultArchivePath},
{CC"isSharingEnabled", CC"()Z", (void*)&WB_IsSharingEnabled},
{CC"isShared", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
{CC"isSharedInternedString", CC"(Ljava/lang/String;)Z", (void*)&WB_IsSharedInternedString },
{CC"isSharedClass", CC"(Ljava/lang/Class;)Z", (void*)&WB_IsSharedClass },
{CC"areSharedStringsIgnored", CC"()Z", (void*)&WB_AreSharedStringsIgnored },
{CC"areSharedStringsMapped", CC"()Z", (void*)&WB_AreSharedStringsMapped },
{CC"getResolvedReferences", CC"(Ljava/lang/Class;)Ljava/lang/Object;", (void*)&WB_GetResolvedReferences},
{CC"linkClass", CC"(Ljava/lang/Class;)V", (void*)&WB_LinkClass},
{CC"areOpenArchiveHeapObjectsMapped", CC"()Z", (void*)&WB_AreOpenArchiveHeapObjectsMapped},
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, 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
@@ -49,9 +49,9 @@ public static void main(String[] args) throws Exception {
CDSTestUtils.createArchiveAndCheck(opts);

// Some mach5 tiers run with -vmoptions:-Xlog:cds=debug. This would cause the outputs to mismatch.
// Force -Xlog:cds=warning to supress the CDS logs.
// Force the log level to warning for all tags to supressed the CDS logs. Also disable the timestamp.
opts.setUseVersion(false);
opts.addSuffix("-showversion", "-Xlog:cds=warning", "ServiceLoaderApp");
opts.addSuffix("-showversion", "-Xlog:all=warning::level,tags", "ServiceLoaderApp");
OutputAnalyzer out1 = CDSTestUtils.runWithArchive(opts);

opts.setXShareMode("off");
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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
@@ -29,8 +29,8 @@ public class SharedStringsWb {
public static void main(String[] args) throws Exception {
WhiteBox wb = WhiteBox.getWhiteBox();

if (wb.areSharedStringsIgnored()) {
System.out.println("Shared strings are ignored, assuming PASS");
if (!wb.areSharedStringsMapped()) {
System.out.println("Shared strings are not mapped, assuming PASS");
return;
}

@@ -43,7 +43,7 @@ public static void main(String[] args) throws Exception {
throw new RuntimeException("Shared string is not a valid String: FAIL");
}

if (wb.isShared(internedS)) {
if (wb.isSharedInternedString(internedS)) {
System.out.println("Found shared string, result: PASS");
} else {
throw new RuntimeException("String is not shared, result: FAIL");
@@ -97,8 +97,8 @@ public static void main(String[] args) throws Exception {
.shouldNotContain("Preload Warning: Cannot find java/lang/invoke/LambdaForm")
.shouldNotContain("Preload Warning: Cannot find boot/append/Foo")
.shouldNotContain("Preload Warning: Cannot find jdk/jfr/NewClass")
.shouldMatch(".info..class,load *. boot.append.Foo") // from -Xlog:class+load
.shouldMatch("cds,class.*boot boot.append.Foo") // from -Xlog:cds+class
.shouldNotMatch(".info..class,load *. jdk.jfr.NewClass"); // from -Xlog:class+load
.shouldMatch("class,load *. boot.append.Foo") // from -Xlog:class+load
.shouldMatch("cds,class.*boot boot.append.Foo") // from -Xlog:cds+class
.shouldNotMatch("class,load *. jdk.jfr.NewClass"); // from -Xlog:class+load
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, 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
@@ -62,8 +62,8 @@ public static void main(String args[]) throws Exception {
return;
}

if (wb.areSharedStringsIgnored()) {
System.out.println("Shared strings are ignored.");
if (!wb.areSharedStringsMapped()) {
System.out.println("Shared strings are not mapped.");
return;
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, 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
@@ -55,7 +55,7 @@ public String get() {
static Instrumentation instrumentation;

public static void main(String args[]) throws Throwable {
if (wb.areSharedStringsIgnored()) {
if (!wb.areSharedStringsMapped()) {
System.out.println("Shared strings are ignored.");
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, 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
@@ -38,7 +38,7 @@ public static void main(String[] args) throws Exception {
}

public static void CheckString(WhiteBox wb, String s) {
if (!wb.areSharedStringsIgnored() && !wb.isShared(s)) {
if (wb.areSharedStringsMapped() && !wb.isSharedInternedString(s)) {
throw new RuntimeException("String is not shared.");
}
}
@@ -26,6 +26,7 @@
* @test
* @summary Exercise GC with shared strings
* @requires vm.cds.archived.java.heap
* @requires vm.gc == null
* @library /test/hotspot/jtreg/runtime/cds/appcds /test/lib
* @build HelloStringGC sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
@@ -26,6 +26,7 @@
* @test
* @summary Test relevant combinations of command line flags with shared strings
* @requires vm.cds.archived.java.heap & vm.hasJFR
* @requires vm.gc == null
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @build HelloString
* @run driver FlagCombo
@@ -36,6 +37,7 @@
* @summary Test relevant combinations of command line flags with shared strings
* @comment A special test excluding the case that requires JFR
* @requires vm.cds.archived.java.heap & !vm.hasJFR
* @requires vm.gc == null
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @build HelloString
* @run driver FlagCombo noJfr
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@@ -33,7 +33,7 @@ public static void main(String args[]) throws RuntimeException {
String testString2 = "test123";

WhiteBox wb = WhiteBox.getWhiteBox();
if (!wb.isShared(testString1) && !wb.areSharedStringsIgnored()) {
if (wb.areSharedStringsMapped() && !wb.isSharedInternedString(testString1)) {
throw new RuntimeException("testString1 is not shared");
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@@ -34,7 +34,7 @@ public static void main(String args[]) {
System.out.println("Hello String: " + testString1);

WhiteBox wb = WhiteBox.getWhiteBox();
if (!wb.isShared(testString1) && !wb.areSharedStringsIgnored()) {
if (wb.areSharedStringsMapped() && !wb.isSharedInternedString(testString1)) {
throw new RuntimeException("testString1 is not shared");
}

@@ -66,7 +66,7 @@ public static void main(String args[]) {
// Check intern() method for "" string
String empty = "";
String empty_interned = empty.intern();
if (!wb.isShared(empty)) {
if (wb.areSharedStringsMapped() && !wb.isSharedInternedString(empty)) {
throw new RuntimeException("Empty string should be shared");
}
if (empty_interned != empty) {
@@ -26,6 +26,7 @@
* @test
* @summary Test shared strings together with string intern operation
* @requires vm.cds.archived.java.heap
* @requires vm.gc == null
* @library /test/hotspot/jtreg/runtime/cds/appcds /test/lib
* @compile InternStringTest.java
* @build sun.hotspot.WhiteBox
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@@ -38,10 +38,12 @@ public static void main(String[] args) throws Exception {
// All string literals are shared.
String shared1 = "LiveOak";
String interned1 = shared1.intern();
if (wb.areSharedStringsIgnored() || wb.isShared(interned1)) {
System.out.println(passed_output1);
} else {
throw new RuntimeException("Failed: String is not shared.");
if (wb.areSharedStringsMapped()) {
if (wb.isSharedInternedString(interned1)) {
System.out.println(passed_output1);
} else {
throw new RuntimeException("Failed: String is not shared.");
}
}

// Test 2: shared_string1.intern() == shared_string2.intern()
@@ -58,21 +60,25 @@ public static void main(String[] args) throws Exception {
String a = "X" + latin1Sup.substring(1);
String b = a.intern();

if (wb.areSharedStringsIgnored() || wb.isShared(b)) {
System.out.println(passed_output3);
} else {
throw new RuntimeException("Failed: expected shared string with latin1-supplement chars.");
if (wb.areSharedStringsMapped()) {
if (wb.isSharedInternedString(b)) {
System.out.println(passed_output3);
} else {
throw new RuntimeException("Failed: expected shared string with latin1-supplement chars.");
}
}
}

// Test 5: interned strings with non-western characters
{
String a = "X" + nonWestern.substring(1);
String b = a.intern();
if (wb.areSharedStringsIgnored() || wb.isShared(b)) {
System.out.println(passed_output4);
} else {
throw new RuntimeException("Failed: expected shared string with non-western chars.");
if (wb.areSharedStringsMapped()) {
if (wb.isSharedInternedString(b)) {
System.out.println(passed_output4);
} else {
throw new RuntimeException("Failed: expected shared string with non-western chars.");
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@@ -26,6 +26,7 @@
* @test
* @summary Basic shared string test with large pages
* @requires vm.cds.archived.java.heap
* @requires vm.gc == null
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @build HelloString
* @run driver LargePages
@@ -26,6 +26,7 @@
* @test
* @summary Test locking on shared strings
* @requires vm.cds.archived.java.heap
* @requires vm.gc == null
* @library /test/hotspot/jtreg/runtime/cds/appcds /test/lib
* @compile LockStringTest.java LockStringValueTest.java
* @build sun.hotspot.WhiteBox
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@@ -31,13 +31,13 @@ public class LockStringTest extends Thread {

public static void main(String[] args) throws Exception {

if (wb.areSharedStringsIgnored()) {
System.out.println("The shared strings are ignored");
if (!wb.areSharedStringsMapped()) {
System.out.println("The shared strings are not mapped");
System.out.println("LockStringTest: PASS");
return;
}

if (!wb.isShared(LockStringTest.class)) {
if (!wb.isSharedClass(LockStringTest.class)) {
throw new RuntimeException("Failed: LockStringTest class is not shared.");
}

@@ -57,7 +57,7 @@ private static void doTest(String s, boolean hasZeroHashCode) throws Exception {
lock = s;
done = false;

if (!wb.isShared(lock)) {
if (!wb.isSharedInternedString(lock)) {
throw new RuntimeException("Failed: String \"" + lock + "\" is not shared.");
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@@ -33,13 +33,13 @@ public static void main(String args[]) {
String s = "LiveOak";
WhiteBox wb = WhiteBox.getWhiteBox();

if (wb.areSharedStringsIgnored()) {
System.out.println("The shared strings are ignored");
if (!wb.areSharedStringsMapped()) {
System.out.println("The shared strings are not mapped");
System.out.println("LockStringValueTest: PASS");
return;
}

if (!wb.isShared(s)) {
if (!wb.isSharedInternedString(s)) {
throw new RuntimeException("LockStringValueTest Failed: String is not shared.");
}

@@ -26,6 +26,7 @@
* @test
* @summary Basic plus test for shared strings
* @requires vm.cds.archived.java.heap
* @requires vm.gc == null
* @library /test/hotspot/jtreg/runtime/cds/appcds /test/lib
* @build HelloStringPlus sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, 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
@@ -29,10 +29,12 @@ public static void main(String[] args) throws Exception {
WhiteBox wb = WhiteBox.getWhiteBox();
String s = "shared_test_string_unique_14325";
s = s.intern();
if (wb.areSharedStringsIgnored() || wb.isShared(s)) {
System.out.println("Found shared string.");
} else {
throw new RuntimeException("String is not shared.");
if (wb.areSharedStringsMapped()) {
if (wb.isSharedInternedString(s)) {
System.out.println("Found shared string.");
} else {
throw new RuntimeException("String is not shared.");
}
}
}
}
@@ -26,6 +26,7 @@
* @test
* @summary White box test for shared strings
* @requires vm.cds.archived.java.heap
* @requires vm.gc == null
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
* @build sun.hotspot.WhiteBox SharedStringsWb
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox

1 comment on commit 36e2dda

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 36e2dda Aug 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.