Skip to content

Commit

Permalink
8058176: [mlvm] tests should not allow code cache exhaustion
Browse files Browse the repository at this point in the history
Reviewed-by: iignatyev
  • Loading branch information
Evgeny Nikitin authored and iignatev committed Apr 14, 2021
1 parent 9406744 commit 4c83d24
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
8 changes: 1 addition & 7 deletions test/hotspot/jtreg/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,7 @@ vmTestbase/jit/escape/LockCoarsening/LockCoarsening001.java 8148743 generic-all
vmTestbase/jit/escape/LockCoarsening/LockCoarsening002.java 8208259 generic-all

vmTestbase/vm/mlvm/indy/func/jvmti/redefineClassInBootstrap/TestDescription.java 8013267 generic-all
vmTestbase/vm/mlvm/meth/func/java/throwException/Test.java 8058176 generic-all
vmTestbase/vm/mlvm/meth/stress/compiler/deoptimize/Test.java#id1 8058176 generic-all
vmTestbase/vm/mlvm/meth/stress/compiler/i2c_c2i/Test.java 8058176 generic-all
vmTestbase/vm/mlvm/meth/stress/compiler/sequences/Test.java 8058176 generic-all
vmTestbase/vm/mlvm/meth/stress/gc/callSequencesDuringGC/Test.java 8058176 generic-all
vmTestbase/vm/mlvm/meth/stress/java/sequences/Test.java 8058176 generic-all
vmTestbase/vm/mlvm/meth/stress/jdi/breakpointInCompiledCode/Test.java 8058176 generic-all
vmTestbase/vm/mlvm/meth/stress/jdi/breakpointInCompiledCode/Test.java 8257761 generic-all
vmTestbase/vm/mlvm/indy/func/jvmti/mergeCP_indy2none_a/TestDescription.java 8013267 generic-all
vmTestbase/vm/mlvm/indy/func/jvmti/mergeCP_indy2manyDiff_b/TestDescription.java 8013267 generic-all
vmTestbase/vm/mlvm/indy/func/jvmti/mergeCP_indy2manySame_b/TestDescription.java 8013267 generic-all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.lang.management.MemoryUsage;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.ManagementFactory;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;

import nsk.share.test.LazyIntArrayToString;
import nsk.share.test.TestUtils;
Expand Down Expand Up @@ -63,10 +68,47 @@ public class MHTransformationGen {

private static final boolean USE_THROW_CATCH = false; // Test bugs

private static final Optional<MemoryPoolMXBean> NON_SEGMENTED_CODE_CACHE_POOL;
private static final Optional<MemoryPoolMXBean> NON_NMETHODS_POOL;
private static final Optional<MemoryPoolMXBean> PROFILED_NMETHODS_POOL;
private static final Optional<MemoryPoolMXBean> NON_PROFILED_NMETHODS_POOL ;

// Limit numbers are arbitrary, feel free to change if arguably necessary
private static final int NON_SEGMENTED_CACHE_ALLOWANCE = 2_000_000;
private static final int SEGMENTED_CACHE_ALLOWANCE = 1_000_000;

static {
var pools = ManagementFactory.getMemoryPoolMXBeans();
NON_SEGMENTED_CODE_CACHE_POOL = pools.stream()
.filter(pool -> pool.getName().equals("CodeCache")).findFirst();
NON_NMETHODS_POOL = pools.stream()
.filter(pool -> pool.getName().equals("CodeHeap 'non-nmethods'")).findFirst();
PROFILED_NMETHODS_POOL = pools.stream()
.filter(pool -> pool.getName().equals("CodeHeap 'profiled nmethods'")).findFirst();
NON_PROFILED_NMETHODS_POOL = pools.stream()
.filter(pool -> pool.getName().equals("CodeHeap 'non-profiled nmethods'")).findFirst();
}

public static class ThrowCatchTestException extends Throwable {
private static final long serialVersionUID = -6749961303738648241L;
}

private static final boolean isCodeCacheEffectivelyFull() {
var result = new Object() { boolean value = false; };

BiConsumer<MemoryPoolMXBean, Integer> check = (pool, limit) -> {
var usage = pool.getUsage();
result.value |= usage.getMax() - usage.getUsed() < limit;
};

NON_SEGMENTED_CODE_CACHE_POOL.ifPresent(pool -> check.accept(pool, NON_SEGMENTED_CACHE_ALLOWANCE));
NON_NMETHODS_POOL.ifPresent(pool -> check.accept(pool, SEGMENTED_CACHE_ALLOWANCE));
PROFILED_NMETHODS_POOL.ifPresent(pool -> check.accept(pool, SEGMENTED_CACHE_ALLOWANCE));
NON_PROFILED_NMETHODS_POOL.ifPresent(pool -> check.accept(pool, SEGMENTED_CACHE_ALLOWANCE));

return result.value;
}

@SuppressWarnings("unused")
public static MHMacroTF createSequence(Argument finalRetVal, Object boundObj, MethodHandle finalMH, Argument[] finalArgs) throws Throwable {
Env.traceDebug("Generating sequence.");
Expand All @@ -87,7 +129,14 @@ public static MHMacroTF createSequence(Argument finalRetVal, Object boundObj, Me

List<MHTFPair> pendingPWTFs = new LinkedList<MHTFPair>();

for ( int i = nextInt(MAX_CYCLES); i > 0; i-- ) {
final int cyclesToBuild = nextInt(MAX_CYCLES);
for ( int i = 0; i < cyclesToBuild; i++) {
if (isCodeCacheEffectivelyFull()) {
Env.traceNormal("Not enought code cache to build up MH sequences anymore. " +
" Has only been able to achieve " + i + " out of " + cyclesToBuild);
break;
}

MHCall lastCall = graph.computeInboundCall();
Argument[] lastArgs = lastCall.getArgs();
MethodType type = lastCall.getTargetMH().type();
Expand Down

1 comment on commit 4c83d24

@openjdk-notifier
Copy link

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.