8326611: Clean up vmTestbase/nsk/stress/stack tests

Reviewed-by: coleenp, mseledtsov
This commit is contained in:
Leonid Mesnik 2024-03-07 20:09:13 +00:00
parent 5aae80304c
commit 972e81d1ad
22 changed files with 362 additions and 928 deletions

View File

@ -415,7 +415,8 @@ tier1_runtime = \
-runtime/Unsafe/RangeCheck.java \
sanity/ \
-:tier1_runtime_appcds_exclude \
-runtime/signal
-runtime/signal \
-runtime/stack
hotspot_cds = \
runtime/cds/ \

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -52,25 +52,14 @@
* 4302288 the second stack overflow causes Classic VM to exit on win32
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack001
* @run main/othervm/timeout=900 Stack001
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack001 {
public class Stack001 {
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
stack001 test = new stack001();
Stack001 test = new Stack001();
test.recurse(0);
out.println("Maximal depth: " + test.maxdepth);
return 0;
System.out.println("Maximal depth: " + test.maxdepth);
}
private int maxdepth;
@ -79,13 +68,10 @@ public class stack001 {
maxdepth = depth;
try {
recurse(depth + 1);
} catch (Error error) {
if (!(error instanceof StackOverflowError) &&
!(error instanceof OutOfMemoryError))
throw error;
if (maxdepth == depth)
} catch (StackOverflowError | OutOfMemoryError e) {
if (maxdepth == depth) {
recurse(depth + 1);
}
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -53,24 +53,14 @@
* 4302288 the second stack overflow causes Classic VM to exit on win32
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack002
* @run main/othervm/timeout=900 Stack002
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack002 {
public class Stack002 {
static final long timeout = 10000; // 10 seconds
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
Tester tester = new Tester(out);
Tester tester = new Tester();
Timer timer = new Timer(tester);
timer.start();
tester.start();
@ -78,21 +68,18 @@ public class stack002 {
try {
timer.join();
} catch (InterruptedException e) {
e.printStackTrace(out);
return 2;
e.printStackTrace();
throw new RuntimeException(e);
}
}
out.println("Maximal depth: " + tester.maxdepth);
return 0;
System.out.println("Maximal depth: " + tester.maxdepth);
}
private static class Tester extends Thread {
int maxdepth;
PrintStream out;
public volatile boolean stop;
public Tester(PrintStream out) {
this.out = out;
public Tester() {
maxdepth = 0;
stop = false;
}
@ -108,10 +95,7 @@ public class stack002 {
return;
}
recurse(depth + 1);
} catch (Error error) {
if (!(error instanceof StackOverflowError) &&
!(error instanceof OutOfMemoryError))
throw error;
} catch (StackOverflowError | OutOfMemoryError e) {
recurse(depth + 1);
}
}
@ -129,9 +113,9 @@ public class stack002 {
started = System.currentTimeMillis();
while (System.currentTimeMillis() - started < timeout) {
try {
this.sleep(1000);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace(tester.out);
e.printStackTrace();
return;
};
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -47,48 +47,37 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack003
* @run main/othervm/timeout=900 Stack003
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack003 {
public class Stack003 {
final static int ITERATIONS = 100;
final static int INCREMENT = 100;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
int depth;
for (depth = 1; ; depth += INCREMENT)
for (depth = 1; ; depth += INCREMENT) {
try {
recurse(depth);
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
break;
}
out.println("Max. depth: " + depth);
for (int i = 0; i < ITERATIONS; i++)
}
System.out.println("Max. depth: " + depth);
for (int i = 0; i < ITERATIONS; i++) {
try {
recurse(2 * depth);
out.println("?");
} catch (StackOverflowError soe) {
System.out.println("?");
} catch (StackOverflowError | OutOfMemoryError err) {
// OK.
} catch (OutOfMemoryError oome) {
// Also OK.
}
return 0;
}
}
static void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}

View File

@ -47,51 +47,38 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack004
* @run main/othervm/timeout=900 Stack004
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack004 {
public class Stack004 {
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
Stack004 test = new Stack004();
test.doRun();
}
public static int run(String args[], PrintStream out) {
stack004 test = new stack004();
int exitCode = test.doRun(args, out);
return exitCode;
}
public int doRun(String args[], PrintStream out) {
public void doRun() {
int depth;
for (depth = 100; ; depth += 100)
for (depth = 100; ; depth += 100) {
try {
recurse(depth);
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
break;
}
out.println("Max. depth: " + depth);
for (int i = 0; i < 100; i++)
}
System.out.println("Max. depth: " + depth);
for (int i = 0; i < 100; i++) {
try {
recurse(2 * depth);
out.println("?");
} catch (StackOverflowError soe) {
System.out.println("?");
} catch (StackOverflowError | OutOfMemoryError err) {
// OK.
} catch (OutOfMemoryError oome) {
// Also OK.
}
return 0;
}
}
final static void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -47,46 +47,34 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack005
* @run main/othervm/timeout=900 Stack005
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack005 {
public class Stack005 {
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
stack005 test = new stack005();
Stack005 test = new Stack005();
int depth;
for (depth = 100; ; depth += 100)
for (depth = 100; ; depth += 100) {
try {
test.recurse(depth);
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError soe) {
break;
}
out.println("Max. depth: " + depth);
for (int i = 0; i < 100; i++)
}
System.out.println("Max. depth: " + depth);
for (int i = 0; i < 100; i++) {
try {
test.recurse(2 * depth);
out.println("?");
} catch (StackOverflowError soe) {
System.out.println("?");
} catch (StackOverflowError | OutOfMemoryError err) {
// OK.
} catch (OutOfMemoryError oome) {
// Also OK.
}
return 0;
}
}
final void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -47,50 +47,38 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack006
* @run main/othervm/timeout=900 Stack006
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack006 implements stack006i {
public class Stack006 implements Stack006i {
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
stack006i test = new stack006();
Stack006i test = new Stack006();
int depth;
for (depth = 100; ; depth += 100)
for (depth = 100; ; depth += 100) {
try {
test.recurse(depth);
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
break;
}
out.println("Max. depth: " + depth);
for (int i = 0; i < 100; i++)
}
System.out.println("Max. depth: " + depth);
for (int i = 0; i < 100; i++) {
try {
test.recurse(2 * depth);
out.println("?");
} catch (StackOverflowError soe) {
System.out.println("?");
} catch (StackOverflowError | OutOfMemoryError err) {
// OK.
} catch (OutOfMemoryError oome) {
// Also OK.
}
return 0;
}
}
public void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}
interface stack006i {
interface Stack006i {
void recurse(int depth);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -46,53 +46,41 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack007
* @run main/othervm/timeout=900 Stack007
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack007 implements stack007i {
public class Stack007 implements Stack007i {
final static int ITERATIONS = 1000;
final static int INCREMENT = 100;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
stack007i test = new stack007();
Stack007i test = new Stack007();
int depth;
for (depth = 100; ; depth += INCREMENT)
for (depth = 100; ; depth += INCREMENT) {
try {
test.recurse(depth);
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
break;
}
out.println("Max. depth: " + depth);
for (int i = 0; i < ITERATIONS; i++)
}
System.out.println("Max. depth: " + depth);
for (int i = 0; i < ITERATIONS; i++) {
try {
test.recurse(10 * depth);
out.println("?");
} catch (StackOverflowError soe) {
System.out.println("?");
} catch (StackOverflowError | OutOfMemoryError err) {
// OK.
} catch (OutOfMemoryError oome) {
// Also OK.
}
return 0;
}
}
public synchronized void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}
interface stack007i {
interface Stack007i {
void recurse(int depth);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -48,28 +48,19 @@
* Making it bigger could cause timeouts on other platform.
*
* @requires (vm.opt.DeoptimizeALot != true & vm.compMode != "Xcomp" & vm.pageSize == 4096)
* @run main/othervm/timeout=900 -Xss200K nsk.stress.stack.stack008
* @run main/othervm/timeout=900 -Xss200K Stack008
*/
package nsk.stress.stack;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class stack008 {
public class Stack008 {
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
int depth;
//
// Measure maximal recursion depth until stack overflow:
//
for (depth = 100; ; depth += 100)
for (depth = 100; ; depth += 100) {
try {
invokeRecurse(depth);
} catch (Throwable exception) {
@ -77,30 +68,27 @@ public class stack008 {
if ((target instanceof StackOverflowError) ||
(target instanceof OutOfMemoryError))
break; // OK.
target.printStackTrace(out);
if (target instanceof ThreadDeath)
throw (ThreadDeath) target;
return 2;
target.printStackTrace();
throw new RuntimeException(exception);
}
out.println("Max. depth: " + depth);
}
System.out.println("Max. depth: " + depth);
//
// Provoke stack overflow multiple times:
//
for (int i = 0; i < 100; i++)
for (int i = 0; i < 100; i++) {
try {
invokeRecurse(2 * depth);
// out.println("?");
// System.out.println("?");
} catch (Throwable exception) {
Throwable target = getTargetException(exception);
if ((target instanceof StackOverflowError) ||
(target instanceof OutOfMemoryError))
continue; // OK.
target.printStackTrace(out);
if (target instanceof ThreadDeath)
throw (ThreadDeath) target;
return 2;
target.printStackTrace();
throw new RuntimeException(exception);
}
return 0;
}
}
private static Throwable getTargetException(Throwable exception) {
@ -118,7 +106,7 @@ public class stack008 {
}
static Method method = null;
static stack008 instance = null;
static Stack008 instance = null;
static Object params[] = null;
private static void invokeRecurse(int depth) throws Exception {
@ -126,8 +114,8 @@ public class stack008 {
//
// Optimization trick: allocate once, use everywhere.
//
instance = new stack008();
method = stack008.class.getMethod("recurse");
instance = new Stack008();
method = Stack008.class.getMethod("recurse");
params = new Object[]{};
}
//
@ -140,10 +128,11 @@ public class stack008 {
int depth = 0;
public void recurse() throws Exception {
if (depth > 0)
if (depth > 0) {
//
// Self-invoke via reflection:
//
invokeRecurse(depth - 1);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -47,49 +47,32 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack009
* @run main/othervm/timeout=900 Stack009
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack009 {
public class Stack009 {
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
for (int depth = 100; ; depth += 100)
for (int depth = 100; ; depth += 100) {
try {
recurse(depth);
} catch (Error error1) {
if (!(error1 instanceof StackOverflowError) &&
!(error1 instanceof OutOfMemoryError))
throw error1;
} catch (StackOverflowError | OutOfMemoryError error1) {
out.println("Max. depth: " + depth);
System.out.println("Max. depth: " + depth);
try {
recurse(10 * depth);
out.println("?");
} catch (Error error2) {
if (!(error2 instanceof StackOverflowError) &&
!(error2 instanceof OutOfMemoryError))
throw error2;
// Stack overflow is OK here.
System.out.println("?");
} catch (StackOverflowError | OutOfMemoryError error2) {
// ignore
}
break;
}
return 0;
}
}
static void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -47,99 +47,82 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack010
* @run main/othervm/timeout=900 Stack010
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack010 extends Thread {
final static int THREADS = 10;
final static int CYCLES = 10;
public class Stack010 extends Thread {
final static int THREADS = 1;
final static int CYCLES = 1;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
//
// Measure maximal recursion depth until stack overflow:
//
int maxDepth = 0;
for (int depth = 10; ; depth += 10)
for (int depth = 10; ; depth += 10) {
try {
recurse(depth);
maxDepth = depth;
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
break;
}
out.println("Max. depth: " + maxDepth);
}
System.out.println("Max. depth: " + maxDepth);
//
// Execute multiple threads repeatedly provoking stack overflows:
//
stack010 threads[] = new stack010[THREADS];
Stack010 threads[] = new Stack010[THREADS];
for (int i = 0; i < threads.length; i++) {
threads[i] = new stack010();
threads[i].depthToTry = 10 * maxDepth;
threads[i] = new Stack010();
threads[i].depthToTry = 100 * maxDepth;
threads[i].start();
}
for (int i = 0; i < threads.length; i++)
if (threads[i].isAlive())
for (int i = 0; i < threads.length; i++) {
if (threads[i].isAlive()) {
try {
threads[i].join();
} catch (InterruptedException exception) {
exception.printStackTrace(out);
return 2;
throw new RuntimeException(exception);
}
}
}
//
// Check if unexpected exceptions were not thrown:
//
int exitCode = 0;
for (int i = 0; i < threads.length; i++)
for (int i = 0; i < threads.length; i++) {
if (threads[i].thrown != null) {
threads[i].thrown.printStackTrace(out);
exitCode = 2;
threads[i].thrown.printStackTrace();
throw new RuntimeException("Exception in the thread " + threads[i], threads[i].thrown);
}
if (exitCode != 0)
out.println("# TEST FAILED");
return exitCode;
}
}
int depthToTry = 0;
Throwable thrown = null;
public void run() {
for (int i = 0; i < CYCLES; i++)
for (int i = 0; i < CYCLES; i++) {
try {
System.out.println("depth = " +depthToTry);
recurse(depthToTry);
throw new Exception(
"TEST_RFE: no stack overflow thrown" +
", need to try deeper recursion?");
} catch (StackOverflowError soe) {
// It's OK: stack overflow was expected.
} catch (OutOfMemoryError oome) {
// Also OK: out of memory may indacate stack overflow.
} catch (StackOverflowError | OutOfMemoryError err) {
// It's OK
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath)
throw (ThreadDeath) throwable;
// It isn't OK!
thrown = throwable;
break;
}
}
}
static void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -47,99 +47,81 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack011
* @run main/othervm/timeout=900 Stack011
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack011 extends Thread {
public class Stack011 extends Thread {
final static int THREADS = 10;
final static int CYCLES = 10;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
//
// Measure maximal recursion depth until stack overflow:
//
int maxDepth = 0;
for (int depth = 10; ; depth += 10)
for (int depth = 10; ; depth += 10) {
try {
recurse(depth);
maxDepth = depth;
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError soe) {
break;
}
out.println("Max. depth: " + maxDepth);
}
System.out.println("Max. depth: " + maxDepth);
//
// Execute multiple threads repeatedly provoking stack overflows:
//
stack011 threads[] = new stack011[THREADS];
Stack011 threads[] = new Stack011[THREADS];
for (int i = 0; i < threads.length; i++) {
threads[i] = new stack011();
threads[i] = new Stack011();
threads[i].depthToTry = 10 * maxDepth;
threads[i].start();
}
for (int i = 0; i < threads.length; i++)
if (threads[i].isAlive())
for (int i = 0; i < threads.length; i++) {
if (threads[i].isAlive()) {
try {
threads[i].join();
} catch (InterruptedException exception) {
exception.printStackTrace(out);
return 2;
throw new RuntimeException(exception);
}
}
}
//
// Check if unexpected exceptions were not thrown:
//
int exitCode = 0;
for (int i = 0; i < threads.length; i++)
for (int i = 0; i < threads.length; i++) {
if (threads[i].thrown != null) {
threads[i].thrown.printStackTrace(out);
exitCode = 2;
threads[i].thrown.printStackTrace();
throw new RuntimeException("Exception in the thread " + threads[i], threads[i].thrown);
}
if (exitCode != 0)
out.println("# TEST FAILED");
return exitCode;
}
}
int depthToTry = 0;
Throwable thrown = null;
public void run() {
for (int i = 0; i < CYCLES; i++)
for (int i = 0; i < CYCLES; i++) {
try {
recurse(depthToTry);
throw new Exception(
"TEST_RFE: no stack overflow thrown" +
", need to try deeper recursion?");
} catch (StackOverflowError error) {
// It's OK: stack overflow was expected.
} catch (OutOfMemoryError oome) {
// Also OK: recursion may result in memory lack.
} catch (StackOverflowError | OutOfMemoryError err) {
// It's OK
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath)
throw (ThreadDeath) throwable;
// It isn't OK!
thrown = throwable;
break;
}
}
}
final static void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -48,100 +48,82 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack012
* @run main/othervm/timeout=900 Stack012
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack012 extends Thread {
public class Stack012 extends Thread {
final static int THREADS = 10;
final static int CYCLES = 10;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
stack012 test = new stack012();
Stack012 test = new Stack012();
//
// Measure maximal recursion depth until stack overflow:
//
int maxDepth = 0;
for (int depth = 10; ; depth += 10)
for (int depth = 10; ; depth += 10) {
try {
test.recurse(depth);
maxDepth = depth;
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
break;
}
out.println("Max. depth: " + maxDepth);
}
System.out.println("Max. depth: " + maxDepth);
//
// Execute multiple threads repeatedly provoking stack overflows:
//
stack012 threads[] = new stack012[THREADS];
Stack012 threads[] = new Stack012[THREADS];
for (int i = 0; i < threads.length; i++) {
threads[i] = new stack012();
threads[i] = new Stack012();
threads[i].depthToTry = 10 * maxDepth;
threads[i].start();
}
for (int i = 0; i < threads.length; i++)
if (threads[i].isAlive())
for (int i = 0; i < threads.length; i++) {
if (threads[i].isAlive()) {
try {
threads[i].join();
} catch (InterruptedException exception) {
exception.printStackTrace(out);
return 2;
throw new RuntimeException(exception);
}
}
}
//
// Check if unexpected exceptions were not thrown:
//
int exitCode = 0;
for (int i = 0; i < threads.length; i++)
for (int i = 0; i < threads.length; i++) {
if (threads[i].thrown != null) {
threads[i].thrown.printStackTrace(out);
exitCode = 2;
threads[i].thrown.printStackTrace();
throw new RuntimeException("Exception in the thread " + threads[i], threads[i].thrown);
}
if (exitCode != 0)
out.println("# TEST FAILED");
return exitCode;
}
}
int depthToTry = 0;
Throwable thrown = null;
public void run() {
for (int i = 0; i < CYCLES; i++)
for (int i = 0; i < CYCLES; i++) {
try {
this.recurse(depthToTry);
throw new Exception(
"TEST_RFE: no stack overflow thrown" +
", need to try deeper recursion?");
} catch (StackOverflowError error) {
// It's OK: stack overflow was expected.
} catch (OutOfMemoryError oome) {
// Also OK: invocation may result in out of memory.
} catch (StackOverflowError | OutOfMemoryError err) {
// It's OK
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath)
throw (ThreadDeath) throwable;
// It isn't OK!
thrown = throwable;
break;
}
}
}
final void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -47,81 +47,67 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack013
* @run main/othervm/timeout=900 Stack013
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack013 extends stack013i {
public class Stack013 extends Stack013i {
final static int THREADS = 10;
final static int CYCLES = 10;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
stack013i test = new stack013();
Stack013i test = new Stack013();
//
// Measure maximal recursion depth until stack overflow:
//
int maxDepth = 0;
for (int depth = 10; ; depth += 10)
for (int depth = 10; ; depth += 10) {
try {
test.recurse(depth);
maxDepth = depth;
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
break;
}
out.println("Max. depth: " + maxDepth);
}
System.out.println("Max. depth: " + maxDepth);
//
// Execute multiple threads repeatedly provoking stack overflows:
//
stack013i threads[] = new stack013i[THREADS];
Stack013i threads[] = new Stack013i[THREADS];
for (int i = 0; i < threads.length; i++) {
threads[i] = new stack013();
threads[i] = new Stack013();
threads[i].depthToTry = 10 * maxDepth;
threads[i].cycles = CYCLES;
threads[i].start();
}
for (int i = 0; i < threads.length; i++)
if (threads[i].isAlive())
for (int i = 0; i < threads.length; i++) {
if (threads[i].isAlive()) {
try {
threads[i].join();
} catch (InterruptedException exception) {
exception.printStackTrace(out);
return 2;
throw new RuntimeException(exception);
}
}
}
//
// Check if unexpected exceptions were thrown:
//
int exitCode = 0;
for (int i = 0; i < threads.length; i++)
for (int i = 0; i < threads.length; i++) {
if (threads[i].thrown != null) {
threads[i].thrown.printStackTrace(out);
exitCode = 2;
threads[i].thrown.printStackTrace();
throw new RuntimeException("Exception in the thread " + threads[i], threads[i].thrown);
}
if (exitCode != 0)
out.println("# TEST FAILED");
return exitCode;
}
}
void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}
abstract class stack013i extends Thread {
abstract class Stack013i extends Thread {
//
// Pure virtual method:
//
@ -135,24 +121,20 @@ abstract class stack013i extends Thread {
//
// Provoke multiple stack overflows:
//
for (int i = 0; i < cycles; i++)
for (int i = 0; i < cycles; i++) {
try {
recurse(depthToTry);
throw new Exception(
"TEST_RFE: no stack overflow thrown" +
", need to try deeper recursion?");
} catch (StackOverflowError error) {
// It's OK: stack overflow was expected.
} catch (OutOfMemoryError oome) {
// Also OK: out of memory is eligible here.
} catch (StackOverflowError | OutOfMemoryError err) {
// It's OK
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath)
throw (ThreadDeath) throwable;
// It isn't OK!
thrown = throwable;
break;
}
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -50,81 +50,67 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack014
* @run main/othervm/timeout=900 Stack014
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack014 extends stack014i {
public class Stack014 extends Stack014i {
final static int THREADS = 10;
final static int CYCLES = 10;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
stack014i test = new stack014();
Stack014i test = new Stack014();
//
// Measure maximal recursion depth until stack overflow:
//
int maxDepth = 0;
for (int depth = 10; ; depth += 10)
for (int depth = 10; ; depth += 10) {
try {
test.recurse(depth);
maxDepth = depth;
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
break;
}
out.println("Max. depth: " + maxDepth);
}
System.out.println("Max. depth: " + maxDepth);
//
// Execute multiple threads repeatedly provoking stack overflows:
//
stack014i threads[] = new stack014i[THREADS];
Stack014i threads[] = new Stack014i[THREADS];
for (int i = 0; i < threads.length; i++) {
threads[i] = new stack014();
threads[i] = new Stack014();
threads[i].depthToTry = 10 * maxDepth;
threads[i].cycles = CYCLES;
threads[i].start();
}
for (int i = 0; i < threads.length; i++)
if (threads[i].isAlive())
for (int i = 0; i < threads.length; i++) {
if (threads[i].isAlive()) {
try {
threads[i].join();
} catch (InterruptedException exception) {
exception.printStackTrace(out);
return 2;
throw new RuntimeException(exception);
}
}
}
//
// Check if unexpected exceptions were thrown:
//
int exitCode = 0;
for (int i = 0; i < threads.length; i++)
for (int i = 0; i < threads.length; i++) {
if (threads[i].thrown != null) {
threads[i].thrown.printStackTrace(out);
exitCode = 2;
threads[i].thrown.printStackTrace();
throw new RuntimeException("Exception in the thread " + threads[i], threads[i].thrown);
}
if (exitCode != 0)
out.println("# TEST FAILED");
return exitCode;
}
}
synchronized void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
}
abstract class stack014i extends Thread {
abstract class Stack014i extends Thread {
//
// Pure virtual method:
//
@ -138,24 +124,20 @@ abstract class stack014i extends Thread {
//
// Provoke multiple stack overflows:
//
for (int i = 0; i < cycles; i++)
for (int i = 0; i < cycles; i++) {
try {
recurse(depthToTry);
throw new Exception(
"TEST_RFE: no stack overflow thrown" +
", need to try deeper recursion?");
} catch (StackOverflowError error) {
// It's OK: stack overflow was expected.
} catch (OutOfMemoryError oome) {
// Also OK: if there is no memory for stack expansion.
} catch (StackOverflowError | OutOfMemoryError err) {
// It's OK
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath)
throw (ThreadDeath) throwable;
// It isn't OK!
thrown = throwable;
break;
}
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -48,88 +48,74 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires vm.opt.DeoptimizeALot != true
* @run main/othervm/timeout=900 nsk.stress.stack.stack015
* @run main/othervm/timeout=900 Stack015
*/
package nsk.stress.stack;
import java.io.PrintStream;
public class stack015 extends stack015i {
public class Stack015 extends Stack015i {
final static int THREADS = 10;
final static int CYCLES = 10;
final static int STEP = 10;
final static int RESERVE = 10;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
//
// The test will invoke the particular stack015.recurse()
// The test will invoke the particular Stack015.recurse()
// method via abstract test.recurse() invocations.
//
stack015i test = new stack015();
stack015i.test = test;
Stack015i test = new Stack015();
Stack015i.test = test;
//
// Measure maximal recursion depth until stack overflow:
//
int maxDepth = 0;
for (int depth = 0; ; depth += STEP)
for (int depth = 0; ; depth += STEP) {
try {
test.recurse(depth);
maxDepth = depth;
} catch (StackOverflowError soe) {
break;
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
break;
}
out.println("Max. depth: " + maxDepth);
}
System.out.println("Max. depth: " + maxDepth);
//
// Execute multiple threads repeatedly provoking stack overflows:
//
stack015i threads[] = new stack015i[THREADS];
Stack015i threads[] = new Stack015i[THREADS];
for (int i = 0; i < threads.length; i++) {
threads[i] = new stack015();
threads[i] = new Stack015();
threads[i].depthToTry = RESERVE * maxDepth;
threads[i].start();
}
for (int i = 0; i < threads.length; i++)
if (threads[i].isAlive())
for (int i = 0; i < threads.length; i++) {
if (threads[i].isAlive()) {
try {
threads[i].join();
} catch (InterruptedException exception) {
exception.printStackTrace(out);
return 2;
throw new RuntimeException(exception);
}
}
}
//
// Check if unexpected exceptions were thrown:
//
int exitCode = 0;
for (int i = 0; i < threads.length; i++)
for (int i = 0; i < threads.length; i++) {
if (threads[i].thrown != null) {
threads[i].thrown.printStackTrace(out);
exitCode = 2;
threads[i].thrown.printStackTrace();
throw new RuntimeException("Exception in the thread " + threads[i], threads[i].thrown);
}
if (exitCode != 0)
out.println("# TEST FAILED");
return exitCode;
}
}
synchronized void syncRecurse(int depth) {
if (depth > 0)
if (depth > 0) {
syncRecurse(depth - 1);
}
}
}
abstract class stack015i extends Thread {
abstract class Stack015i extends Thread {
//
// Pure virtual method:
//
@ -139,24 +125,25 @@ abstract class stack015i extends Thread {
//
// Stack overflow must occur here:
//
syncRecurse(stack015.STEP);
syncRecurse(Stack015.STEP);
//
// If no stack overflow occured, try again with deeper stack:
//
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
Throwable thrown = null;
int depthToTry;
static stack015i test;
static Stack015i test;
public void run() {
//
// Provoke multiple stack overflows:
//
for (int i = 0; i < stack015.CYCLES; i++)
for (int i = 0; i < Stack015.CYCLES; i++) {
try {
//
// All threads invoke the same synchronized method:
@ -167,17 +154,13 @@ abstract class stack015i extends Thread {
"TEST_RFE: no stack overflow thrown" +
", need to try deeper recursion?");
} catch (StackOverflowError error) {
// It's OK: stack overflow was expected.
} catch (OutOfMemoryError oome) {
// Also OK: there may be no memory for stack expansion.
} catch (StackOverflowError | OutOfMemoryError err) {
// It's OK
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath)
throw (ThreadDeath) throwable;
// It isn't OK!
thrown = throwable;
break;
}
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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,21 +49,12 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires (vm.opt.DeoptimizeALot != true & vm.compMode != "Xcomp")
* @library /vmTestbase
* @build nsk.share.Terminator
* @run main/othervm/timeout=900 -Xint -Xss448K nsk.stress.stack.stack016 -eager
* @run main/othervm/timeout=900 -Xcomp -Xss448K nsk.stress.stack.stack016 -eager
* @run main/othervm/timeout=900 -Xcomp -XX:-TieredCompilation -Xss448K nsk.stress.stack.stack016 -eager
* @run main/othervm/timeout=900 -Xint -Xss448K Stack016
* @run main/othervm/timeout=900 -Xcomp -Xss448K Stack016
* @run main/othervm/timeout=900 -Xcomp -XX:-TieredCompilation -Xss448K Stack016
*/
package nsk.stress.stack;
import nsk.share.Terminator;
import java.io.PrintStream;
public class stack016 extends Thread {
public class Stack016 extends Thread {
private final static int THREADS = 10;
private final static int CYCLES = 10;
private final static int STEP = 10;
@ -71,37 +62,11 @@ public class stack016 extends Thread {
private final static int PROBES = STEP * RESERVE;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
Stack016 test = new Stack016();
test.doRun();
}
public static int run(String args[], PrintStream out) {
verbose = false;
boolean eager = false;
for (int i = 0; i < args.length; i++)
if (args[i].toLowerCase().equals("-verbose"))
verbose = true;
else if (args[i].toLowerCase().equals("-eager"))
eager = true;
if (!eager)
Terminator.appoint(Terminator.parseAppointment(args));
stack016.out = out;
stack016 test = new stack016();
return test.doRun();
}
private static boolean verbose;
private static PrintStream out;
private void display(Object message) {
if (!verbose)
return;
synchronized (out) {
out.println(message.toString());
}
}
private int doRun() {
private void doRun() {
//
// Measure recursive depth before stack overflow:
//
@ -114,14 +79,14 @@ public class stack016 extends Thread {
break;
}
}
out.println("Maximal recursion depth: " + maxDepth);
System.out.println("Maximal recursion depth: " + maxDepth);
//
// Run the tested threads:
//
stack016 threads[] = new stack016[THREADS];
Stack016 threads[] = new Stack016[THREADS];
for (int i = 0; i < threads.length; i++) {
threads[i] = new stack016();
threads[i] = new Stack016();
threads[i].setName("Thread: " + (i + 1) + "/" + THREADS);
threads[i].depthToTry = RESERVE * maxDepth;
threads[i].start();
@ -131,8 +96,7 @@ public class stack016 extends Thread {
try {
threads[i].join();
} catch (InterruptedException exception) {
exception.printStackTrace(out);
return 2;
throw new RuntimeException(exception);
}
}
}
@ -140,16 +104,12 @@ public class stack016 extends Thread {
//
// Check if unexpected exceptions were thrown:
//
int exitCode = 0;
for (int i = 0; i < threads.length; i++) {
if (threads[i].thrown != null) {
threads[i].thrown.printStackTrace(out);
exitCode = 2;
threads[i].thrown.printStackTrace();
throw new RuntimeException("Exception in the thread " + threads[i], threads[i].thrown);
}
}
if (exitCode != 0)
out.println("# TEST FAILED");
return exitCode;
}
private int stackTop = 0;
@ -161,11 +121,7 @@ public class stack016 extends Thread {
if (depth > 0) {
try {
trickyRecurse(depth - 1);
} catch (Error error) {
if (!(error instanceof StackOverflowError) &&
!(error instanceof OutOfMemoryError))
throw error;
} catch (StackOverflowError | OutOfMemoryError error) {
//
// Provoke more stack overflow,
// if current stack is deep enough:
@ -180,28 +136,24 @@ public class stack016 extends Thread {
}
private static void recurse(int depth) {
if (depth > 0)
if (depth > 0) {
recurse(depth - 1);
}
}
public void run() {
String threadName = Thread.currentThread().getName();
for (int i = 1; i <= CYCLES; i++) {
try {
display(threadName + ", iteration: " + i + "/" + CYCLES +
System.out.println(threadName + ", iteration: " + i + "/" + CYCLES +
", depthToTry: " + depthToTry);
trickyRecurse(depthToTry);
throw new Error(
"TEST_BUG: trickyRecursion() must throw an error anyway!");
} catch (StackOverflowError error) {
// It's OK: stack overflow was expected.
} catch (OutOfMemoryError oome) {
// Also OK, if there is no memory for stack expansion.
} catch (StackOverflowError | OutOfMemoryError err) {
// It's OK
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath)
throw (ThreadDeath) throwable;
thrown = throwable;
break;
}

View File

@ -42,99 +42,59 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires (vm.opt.DeoptimizeALot != true & vm.compMode != "Xcomp" & vm.pageSize == 4096)
* @library /vmTestbase
* @build nsk.share.Terminator
* @run main/othervm/timeout=900 -Xss220K nsk.stress.stack.stack017 -eager
* @run main/othervm/timeout=900 -Xss220K Stack017
*/
package nsk.stress.stack;
import nsk.share.Terminator;
import java.io.PrintStream;
public class stack017 extends Thread {
public class Stack017 extends Thread {
private final static int THREADS = 10;
private final static int CYCLES = 10;
private final static int PROBES = 100;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
verbose = false;
boolean eager = false;
for (int i = 0; i < args.length; i++)
if (args[i].toLowerCase().equals("-verbose"))
verbose = true;
else if (args[i].toLowerCase().equals("-eager"))
eager = true;
if (!eager)
Terminator.appoint(Terminator.parseAppointment(args));
stack017.out = out;
stack017 test = new stack017();
return test.doRun();
}
private static boolean verbose;
private static PrintStream out;
private void display(Object message) {
if (!verbose)
return;
synchronized (out) {
out.println(message.toString());
}
Stack017 test = new Stack017();
test.doRun();
}
private static int depthToTry;
private int doRun() {
private void doRun() {
//
// Measure recursive depth before stack overflow:
//
try {
recurse(0);
} catch (StackOverflowError soe) {
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
}
out.println("Maximal recursion depth: " + maxDepth);
System.out.println("Maximal recursion depth: " + maxDepth);
depthToTry = maxDepth;
//
// Run the tested threads:
//
stack017 threads[] = new stack017[THREADS];
Stack017 threads[] = new Stack017[THREADS];
for (int i = 0; i < threads.length; i++) {
threads[i] = new stack017();
threads[i] = new Stack017();
threads[i].setName("Thread: " + (i + 1) + "/" + THREADS);
threads[i].start();
}
for (int i = 0; i < threads.length; i++)
if (threads[i].isAlive())
for (int i = 0; i < threads.length; i++) {
if (threads[i].isAlive()) {
try {
threads[i].join();
} catch (InterruptedException exception) {
exception.printStackTrace(out);
return 2;
throw new RuntimeException(exception);
}
}
}
//
// Check if unexpected exceptions were thrown:
//
int exitCode = 0;
for (int i = 0; i < threads.length; i++)
for (int i = 0; i < threads.length; i++) {
if (threads[i].thrown != null) {
threads[i].thrown.printStackTrace(out);
exitCode = 2;
threads[i].thrown.printStackTrace();
throw new RuntimeException("Exception in the thread " + threads[i], threads[i].thrown);
}
if (exitCode != 0)
out.println("# TEST FAILED");
return exitCode;
}
}
private int maxDepth = 0;
@ -148,11 +108,7 @@ public class stack017 extends Thread {
try {
maxDepth = depth;
trickyRecurse(depth + 1);
} catch (Error error) {
if (!(error instanceof StackOverflowError) &&
!(error instanceof OutOfMemoryError))
throw error;
} catch (StackOverflowError | OutOfMemoryError error) {
//
// Stack problem caught: provoke it again,
// if current stack is enough deep:
@ -169,19 +125,14 @@ public class stack017 extends Thread {
String threadName = Thread.currentThread().getName();
for (int i = 1; i <= CYCLES; i++)
try {
display(threadName + ", iteration: " + i + "/" + CYCLES);
System.out.println(threadName + ", iteration: " + i + "/" + CYCLES);
trickyRecurse(0);
throw new Exception(
"TEST_BUG: stack overflow was expected!");
} catch (StackOverflowError oome) {
// It's OK: stack overflow was expected.
} catch (OutOfMemoryError oome) {
// Also OK, if there is no memory for stack expansion.
} catch (StackOverflowError | OutOfMemoryError err) {
// It's OK
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath)
throw (ThreadDeath) throwable;
// It isn't OK!
thrown = throwable;
break;

View File

@ -47,58 +47,24 @@
* 4366625 (P4/S4) multiple stack overflow causes HS crash
*
* @requires (vm.opt.DeoptimizeALot != true & vm.compMode != "Xcomp" & vm.pageSize == 4096)
* @library /vmTestbase
* @build nsk.share.Terminator
* @run main/othervm/timeout=900 -Xss220K nsk.stress.stack.stack018 -eager
* @run main/othervm/timeout=900 -Xss220K Stack018
*/
package nsk.stress.stack;
import nsk.share.Terminator;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class stack018 extends Thread {
public class Stack018 extends Thread {
private final static int THREADS = 10;
private final static int CYCLES = 10;
private final static int STEP = 100;
private final static int RESERVE = 100;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
Stack018 test = new Stack018();
test.doRun();
}
public static int run(String args[], PrintStream out) {
verbose = false;
boolean eager = false;
for (int i = 0; i < args.length; i++)
if (args[i].toLowerCase().equals("-verbose"))
verbose = true;
else if (args[i].toLowerCase().equals("-eager"))
eager = true;
if (!eager)
Terminator.appoint(Terminator.parseAppointment(args));
stack018.out = out;
stack018 test = new stack018();
return test.doRun();
}
private static boolean verbose;
private static PrintStream out;
private void display(Object message) {
if (!verbose)
return;
synchronized (out) {
out.println(message.toString());
}
}
private int doRun() {
private void doRun() {
//
// Measure maximal recursion depth until stack overflow:
//
@ -112,10 +78,8 @@ public class stack018 extends Thread {
if ((target instanceof StackOverflowError) ||
(target instanceof OutOfMemoryError))
break; // OK.
target.printStackTrace(out);
if (target instanceof ThreadDeath)
throw (ThreadDeath) target;
return 2;
target.printStackTrace();
throw new RuntimeException(exception);
}
}
@ -123,41 +87,38 @@ public class stack018 extends Thread {
// The depth STEP was enough to cause StackOverflowError or OutOfMemoryError.
maxDepth = STEP;
}
out.println("Maximal recursion depth: " + maxDepth);
System.out.println("Maximal recursion depth: " + maxDepth);
//
// Run the tested threads:
//
stack018 threads[] = new stack018[THREADS];
Stack018 threads[] = new Stack018[THREADS];
for (int i = 0; i < threads.length; i++) {
threads[i] = new stack018();
threads[i] = new Stack018();
threads[i].setName("Thread: " + (i + 1) + "/" + THREADS);
threads[i].depthToTry = RESERVE * maxDepth;
threads[i].start();
}
for (int i = 0; i < threads.length; i++)
if (threads[i].isAlive())
for (int i = 0; i < threads.length; i++) {
if (threads[i].isAlive()) {
try {
threads[i].join();
} catch (InterruptedException exception) {
exception.printStackTrace(out);
return 2;
throw new RuntimeException(exception);
}
}
}
//
// Check if unexpected exceptions were thrown:
//
int exitCode = 0;
for (int i = 0; i < threads.length; i++)
for (int i = 0; i < threads.length; i++) {
if (threads[i].thrown != null) {
out.println("# " + threads[i].getName()
System.out.println("# " + threads[i].getName()
+ ": " + threads[i].thrown);
exitCode = 2;
throw new RuntimeException("Exception in the thread " + threads[i], threads[i].thrown);
}
if (exitCode != 0)
out.println("# TEST FAILED");
return exitCode;
}
}
private int depthToTry = 0;
@ -167,7 +128,7 @@ public class stack018 extends Thread {
String threadName = Thread.currentThread().getName();
for (int i = 1; i <= CYCLES; i++)
try {
display(threadName + ", iteration: " + i + "/" + CYCLES);
System.out.println(threadName + ", iteration: " + i + "/" + CYCLES);
invokeRecurse(depthToTry);
throw new Error("TEST_RFE: try deeper invocations!");
@ -176,8 +137,6 @@ public class stack018 extends Thread {
if ((target instanceof StackOverflowError) ||
(target instanceof OutOfMemoryError))
continue; // OK.
if (target instanceof ThreadDeath)
throw (ThreadDeath) target;
thrown = target;
break;
}
@ -205,7 +164,7 @@ public class stack018 extends Thread {
//
// Optimization trick: allocate once, use everywhere.
//
method = stack018.class.getMethod("recurse");
method = Stack018.class.getMethod("recurse");
params = new Object[]{};
}
this.depth = depth; // actual parameter
@ -215,10 +174,11 @@ public class stack018 extends Thread {
private int depth = 0; // actual parameter for recurse()
public void recurse() throws Exception {
if (depth > 0)
if (depth > 0) {
//
// Self-invoke via reflection:
//
invokeRecurse(depth - 1);
}
}
}

View File

@ -43,45 +43,22 @@
*
* @requires (vm.opt.DeoptimizeALot != true & vm.compMode != "Xcomp" & vm.pageSize == 4096)
* @requires os.family != "windows"
* @library /vmTestbase
* @build nsk.share.Terminator
* @run main/othervm/timeout=900 -Xss200K nsk.stress.stack.stack019 -eager
* @run main/othervm/timeout=900 -Xss200K Stack019
*/
package nsk.stress.stack;
import nsk.share.Terminator;
import java.io.PrintStream;
public class stack019 {
public class Stack019 {
private final static int CYCLES = 50;
private final static int PROBES = 50;
public static void main(String[] args) {
int exitCode = run(args, System.out);
System.exit(exitCode + 95);
}
public static int run(String args[], PrintStream out) {
boolean verbose = false, eager = false;
for (int i = 0; i < args.length; i++)
if (args[i].toLowerCase().equals("-verbose"))
verbose = true;
else if (args[i].toLowerCase().equals("-eager"))
eager = true;
if (!eager)
Terminator.appoint(Terminator.parseAppointment(args));
//
// Measure recursive depth before stack overflow:
//
try {
recurse(0);
} catch (StackOverflowError soe) {
} catch (OutOfMemoryError oome) {
} catch (StackOverflowError | OutOfMemoryError err) {
}
out.println("Maximal recursion depth: " + maxDepth);
System.out.println("Maximal recursion depth: " + maxDepth);
depthToTry = maxDepth;
//
@ -89,23 +66,15 @@ public class stack019 {
//
for (int i = 0; i < CYCLES; i++) {
try {
out.println("Iteration: " + i + "/" + CYCLES);
System.out.println("Iteration: " + i + "/" + CYCLES);
trickyRecurse(0);
out.println("# TEST_BUG: stack overflow was expected!");
return 2;
} catch (StackOverflowError error) {
} catch (OutOfMemoryError oome) {
// It's OK: stack overflow was expected.
throw new RuntimeException("# TEST_BUG: stack overflow was expected!");
} catch (StackOverflowError | OutOfMemoryError error) {
// It's OK
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath)
throw (ThreadDeath) throwable;
throwable.printStackTrace(out);
return 2;
throw new RuntimeException(throwable);
}
}
return 0;
}
private static int maxDepth;
@ -120,17 +89,14 @@ public class stack019 {
try {
maxDepth = depth;
trickyRecurse(depth + 1);
} catch (Error error) {
if (!(error instanceof StackOverflowError) &&
!(error instanceof OutOfMemoryError))
throw error;
} catch (StackOverflowError | OutOfMemoryError error){
//
// Stack problem caught: provoke it again,
// if current stack is enough deep:
//
if (depth < depthToTry - PROBES)
if (depth < depthToTry - PROBES) {
throw error;
}
recurse(depth + 1);
}
}

View File

@ -54,7 +54,7 @@ Short description of files:
text processing:
Grep.java, Paragrep.java
timeouts handling:
Terminator.java, TimeoutHandler.java
TimeoutHandler.java
tree structures support:
Denotation.java, TreeNodesDenotation.java
RAS mode support:

View File

@ -1,172 +0,0 @@
/*
* Copyright (c) 2001, 2020, 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.
*/
package nsk.share;
/**
* Terminator is used to terminate a stress test with PASS exit status
* before the test is terminated as timed out (and so failed).
*
* <p>Terminator class holds a thread which sleeps for the given amount
* of time, and then wakes up and executes <tt>System.exit()</tt>
* with the given exit status. That thread is daemon, so it doesn't
* prevent application from exiting once all its threads finish
* before it's time for termination. Appointing terminator in zero
* delay implies immediate <tt>exit()</tt>.
*
* <p>There is a limitation: you may appoint no more than one terminator
* per application.
*/
public class Terminator {
/**
* Use specific <tt>appoint()</tt> method to appoint terminator.
*
* @see #appoint(int)
* @see #appoint(int,int)
*/
protected Terminator() {}
/**
* One terminator per application, or <tt>null</tt> (by default).
*/
private static Thread terminator = null;
/**
* <p>Return timeout (or waittime) value munus the margin
* value (which is assumed 1 minute by default).
*
* <p>Treat <tt>args[0]</tt> as <tt>$TIMEOUT</tt> value, or seek for
* <tt>-waittime=$WAITTIME</tt> value. If both parameters
* (or either none of them) are assigned, throw an exception to
* report parameters inconsistency.
*
* <p>Also, seek for <tt>-margin=...</tt> assignment, or assume margin
* is 1 minute.
*
* @param args Is usually obtained via the application's command-line.
*
* @throws IllegalArgumentException If <tt>args[]</tt> is inconsistent.
*
* @see #appoint(int)
* @see #appoint(int,int)
*/
public static int parseAppointment(String args[]) {
int timeout=-1, margin=1;
int timeouts=0, waittimes=0, margins=0;
for (int i=0; i<args.length; i++) {
if (args[i].startsWith("-")) {
if (args[i].startsWith("-waittime=")) {
timeout = Integer.parseInt(args[i].substring(10));
waittimes++;
}
if (args[i].startsWith("-margin=")) {
margin = Integer.parseInt(args[i].substring(8));
margins++;
}
} else {
if (i == 0) {
timeout = Integer.parseInt(args[i]);
timeouts++;
}
}
};
if (timeouts==0 && waittimes==0)
throw new IllegalArgumentException(
"no $TIMEOUT, nor -waittime=$WAITTIME is set");
if (waittimes > 1)
throw new IllegalArgumentException(
"more than one -waittime=... is set");
if (margins > 1)
throw new IllegalArgumentException(
"more than one -margin=... is set");
int result = timeout - margin;
if (result <= 0)
throw new IllegalArgumentException(
"delay appointment must be greater than "+margin+" minutes");
return result;
}
/**
* Appoint terminator after the given amount of <tt>minutes</tt>,
* so that exit status would be 95 (to simulate JCK-like PASS
* status).
*
* @throws IllegalStateException If terminator is already appointed.
*
* @see #appoint(int,int)
* @see #parseAppointment(String[])
*/
public static void appoint(int minutes) {
appoint(minutes,95); // JCK-like PASS status
}
/**
* Appoint Terminator for the given amount of <tt>minutes</tt>,
* so that the given <tt>status</tt> would be exited when time
* is over.
*
* @throws IllegalStateException If terminator is already appointed.
*
* @see #appoint(int)
* @see #parseAppointment(String[])
*/
public static void appoint(int minutes, int status) {
if (terminator != null)
throw new IllegalStateException("Terminator is already appointed.");
final long timeToExit = System.currentTimeMillis() + 60*1000L*minutes;
final int exitStatus = status;
terminator = new Thread(Terminator.class.getName()) {
public void run() {
long timeToSleep = timeToExit - System.currentTimeMillis();
if (timeToSleep > 0)
try {
//
// Use wait() instead of sleep(), because Java 2
// specification doesn't guarantee the method
// sleep() to yield to other threads.
//
Object someDummyObject = new Object();
synchronized (someDummyObject) {
someDummyObject.wait(timeToSleep);
}
} catch (InterruptedException exception) {
exception.printStackTrace(System.err);
return;
};
//
// OK, lets do it now:
//
System.err.println(
"#\n# Terminator: prescheduled program termination.\n#");
System.exit(exitStatus); // terminator to all threads
}
};
terminator.setPriority(Thread.MAX_PRIORITY);
terminator.setDaemon(true);
terminator.start();
}
}