Skip to content

Commit

Permalink
Merge branch 'openjdk:master' into jbs8334441
Browse files Browse the repository at this point in the history
  • Loading branch information
sendaoYan authored Jun 24, 2024
2 parents 763f9d7 + aa47dc7 commit 7e9d03f
Show file tree
Hide file tree
Showing 19 changed files with 927 additions and 186 deletions.
9 changes: 3 additions & 6 deletions test/hotspot/jtreg/compiler/c2/Test7190310.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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 @@ -39,17 +39,13 @@
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.lang.ref.Cleaner;

public class Test7190310 {
private static Object str = new Object() {
public String toString() {
return "The Object";
}

protected void finalize() throws Throwable {
System.out.println("The Object is being finalized");
super.finalize();
}
};
private final static ReferenceQueue<Object> rq =
new ReferenceQueue<Object>();
Expand All @@ -58,6 +54,7 @@ protected void finalize() throws Throwable {

public static void main(String[] args)
throws InterruptedException {
Cleaner.create().register(str, () -> System.out.println("The Object is being finalized"));
Thread reader = new Thread() {
public void run() {
while (wr.get() != null) {
Expand Down
129 changes: 129 additions & 0 deletions test/hotspot/jtreg/compiler/codecache/CodeCacheFullCountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (c) 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
* 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.
*/

import java.net.URL;
import java.net.URLClassLoader;
import java.lang.reflect.Field;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

/*
* @test
* @bug 8276036 8277213 8277441
* @summary test for the value of full_count in the message of insufficient codecache
* @library /test/lib
*/
public class CodeCacheFullCountTest {
public static void main(String args[]) throws Throwable {
if (args.length == 1) {
wasteCodeCache();
} else {
runTest();
}
}

public static void wasteCodeCache() throws Exception {
URL url = CodeCacheFullCountTest.class.getProtectionDomain().getCodeSource().getLocation();

for (int i = 0; i < 500; i++) {
ClassLoader cl = new MyClassLoader(url);
refClass(cl.loadClass("SomeClass"));
}
}

public static void runTest() throws Throwable {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-XX:ReservedCodeCacheSize=2496k", "-XX:-UseCodeCacheFlushing", "CodeCacheFullCountTest", "WasteCodeCache");
OutputAnalyzer oa = ProcessTools.executeProcess(pb);
oa.shouldHaveExitValue(0);
String stdout = oa.getStdout();

Pattern pattern = Pattern.compile("full_count=(\\d)");
Matcher stdoutMatcher = pattern.matcher(stdout);
if (stdoutMatcher.find()) {
int fullCount = Integer.parseInt(stdoutMatcher.group(1));
if (fullCount != 1) {
throw new RuntimeException("the value of full_count is wrong.");
}
} else {
throw new RuntimeException("codecache shortage did not occur.");
}
}

private static void refClass(Class clazz) throws Exception {
Field name = clazz.getDeclaredField("NAME");
name.setAccessible(true);
name.get(null);
}

private static class MyClassLoader extends URLClassLoader {
public MyClassLoader(URL url) {
super(new URL[]{url}, null);
}
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
try {
return super.loadClass(name, resolve);
} catch (ClassNotFoundException e) {
return Class.forName(name, resolve, CodeCacheFullCountTest.class.getClassLoader());
}
}
}
}

abstract class Foo {
public abstract int foo();
}

class Foo1 extends Foo {
private int a;
public int foo() { return a; }
}

class Foo2 extends Foo {
private int a;
public int foo() { return a; }
}

class Foo3 extends Foo {
private int a;
public int foo() { return a; }
}

class Foo4 extends Foo {
private int a;
public int foo() { return a; }
}

class SomeClass {
static final String NAME = "name";

static {
int res =0;
Foo[] foos = new Foo[] { new Foo1(), new Foo2(), new Foo3(), new Foo4() };
for (int i = 0; i < 100000; i++) {
res = foos[i % foos.length].foo();
}
}
}
15 changes: 13 additions & 2 deletions test/hotspot/jtreg/compiler/runtime/Test8168712.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 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 @@ -48,20 +48,31 @@
*/
package compiler.runtime;

import java.lang.ref.Cleaner;
import java.util.*;

public class Test8168712 {
static HashSet<Test8168712> m = new HashSet<>();

// One cleaner thread for cleaning all the instances. Otherwise, we get OOME.
static Cleaner cleaner = Cleaner.create();

public Test8168712() {
cleaner.register(this, () -> cleanup());
}

public static void main(String args[]) {
int i = 0;
while (i++<15000) {
test();
}
}

static Test8168712 test() {
return new Test8168712();
}
protected void finalize() {

public void cleanup() {
m.add(this);
}
}
59 changes: 31 additions & 28 deletions test/hotspot/jtreg/runtime/Thread/ThreadCountLimit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022, 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 All @@ -25,7 +25,7 @@
* @test
* @summary Stress test that reaches the process limit for thread count, or time limit.
* @key stress
* @run main ThreadCountLimit
* @run main/othervm -Xmx1g ThreadCountLimit
*/

import java.util.concurrent.CountDownLatch;
Expand All @@ -36,36 +36,18 @@ public class ThreadCountLimit {
static final int TIME_LIMIT_MS = 5000; // Create as many threads as possible in 5 sec

static class Worker extends Thread {
private final int index;
private final CountDownLatch startSignal;

Worker(int index, CountDownLatch startSignal) {
this.index = index;
Worker(CountDownLatch startSignal) {
this.startSignal = startSignal;
}

@Override
public void run() {
if ((index % 250) == 0) {
System.out.println("INFO: thread " + index + " waiting to start");
}

try {
startSignal.await();
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
}

setName(String.valueOf(index));

Thread.yield();

if (index != Integer.parseInt(getName())) {
throw new Error("setName/getName failed!");
}

if ((index % 250) == 0) {
System.out.println("INFO: thread " + getName() + " working");
throw new Error("Unexpected", e);
}
}
}
Expand All @@ -74,27 +56,37 @@ public static void main(String[] args) {
CountDownLatch startSignal = new CountDownLatch(1);
ArrayList<Worker> workers = new ArrayList<Worker>();

boolean reachedTimeLimit = false;
boolean reachedNativeOOM = false;
int countAtTimeLimit = -1;
int countAtNativeOOM = -1;

// This is dangerous loop: it depletes system resources,
// so doing additional things there that may end up allocating
// Java/native memory risks failing the VM prematurely.
// Avoid doing unnecessary calls, printouts, etc.

int count = 1;
long start = System.currentTimeMillis();
try {
while (true) {
Worker w = new Worker(count, startSignal);
Worker w = new Worker(startSignal);
w.start();
workers.add(w);
count++;

long end = System.currentTimeMillis();
if ((end - start) > TIME_LIMIT_MS) {
// Windows path or a system with very large ulimit
System.out.println("INFO: reached the time limit " + TIME_LIMIT_MS + " ms, with " + count + " threads created");
reachedTimeLimit = true;
countAtTimeLimit = count;
break;
}
}
} catch (OutOfMemoryError e) {
if (e.getMessage().contains("unable to create native thread")) {
// Linux, macOS path
long end = System.currentTimeMillis();
System.out.println("INFO: reached this process thread count limit at " + count + " [" + (end - start) + " ms]");
reachedNativeOOM = true;
countAtNativeOOM = count;
} else {
throw e;
}
Expand All @@ -107,7 +99,18 @@ public static void main(String[] args) {
w.join();
}
} catch (InterruptedException e) {
throw new Error("Unexpected: " + e);
throw new Error("Unexpected", e);
}

// Now that all threads have joined, we are away from dangerous
// VM state and have enough memory to perform any other things.
if (reachedTimeLimit) {
// Windows path or a system with very large ulimit
System.out.println("INFO: reached the time limit " + TIME_LIMIT_MS +
" ms, with " + countAtTimeLimit + " threads created");
} else if (reachedNativeOOM) {
System.out.println("INFO: reached this process thread count limit with " +
countAtNativeOOM + " threads created");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @requires vm.gc != null | !vm.opt.final.ClassUnloadingWithConcurrentMark
* @requires vm.gc != "G1" | !vm.opt.final.ClassUnloadingWithConcurrentMark
* @requires vm.gc != "Z"
* @requires vm.compMode != "Xcomp"
* @library /vmTestbase /test/lib
* @run main/othervm
* -Xmx1g
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @requires vm.gc != null | !vm.opt.final.ClassUnloadingWithConcurrentMark
* @requires vm.gc != "G1" | !vm.opt.final.ClassUnloadingWithConcurrentMark
* @requires vm.gc != "Z"
* @requires vm.compMode != "Xcomp"
* @library /vmTestbase /test/lib
* @run main/othervm
* -Xmx1g
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @requires vm.gc != null | !vm.opt.final.ClassUnloadingWithConcurrentMark
* @requires vm.gc != "G1" | !vm.opt.final.ClassUnloadingWithConcurrentMark
* @requires vm.gc != "Z"
* @requires vm.compMode != "Xcomp"
* @library /vmTestbase /test/lib
* @run main/othervm
* -Xmx1g
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @requires vm.gc != null | !vm.opt.final.ClassUnloadingWithConcurrentMark
* @requires vm.gc != "G1" | !vm.opt.final.ClassUnloadingWithConcurrentMark
* @requires vm.gc != "Z"
* @requires vm.compMode != "Xcomp"
* @library /vmTestbase /test/lib
* @run main/othervm
* -Xmx1g
Expand Down
6 changes: 3 additions & 3 deletions test/jdk/TEST.groups
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,12 @@ jdk_core_manual_no_input_security = \
sun/security/smartcardio/TestMultiplePresent.java \
sun/security/smartcardio/TestPresent.java \
sun/security/smartcardio/TestTransmit.java \
sun/security/tools/jarsigner/compatibility/Compatibility.java \
sun/security/tools/keytool/i18n.java
sun/security/tools/jarsigner/compatibility/Compatibility.java

jdk_core_manual_requires_human_input = \
com/sun/jndi/dns/Test6991580.java \
java/util/TimeZone/DefaultTimeZoneTest.java
java/util/TimeZone/DefaultTimeZoneTest.java \
sun/security/tools/keytool/i18n.java


# Test sets for running inside container environment
Expand Down
Loading

0 comments on commit 7e9d03f

Please sign in to comment.