8300732: Whitebox functions for Metaspace test should use byte size
Reviewed-by: stuefe, asmehra
This commit is contained in:
parent
67d1ef1479
commit
50b6e41e0e
@ -1721,8 +1721,13 @@ int WhiteBox::array_bytes_to_length(size_t bytes) {
|
||||
///////////////
|
||||
// MetaspaceTestContext and MetaspaceTestArena
|
||||
WB_ENTRY(jlong, WB_CreateMetaspaceTestContext(JNIEnv* env, jobject wb, jlong commit_limit, jlong reserve_limit))
|
||||
assert(is_aligned(commit_limit, BytesPerWord),
|
||||
"WB_CreateMetaspaceTestContext: commit_limit is not a multiple of the system word byte size");
|
||||
assert(is_aligned(reserve_limit, BytesPerWord),
|
||||
"WB_CreateMetaspaceTestContext: reserve_limit is not a multiple of the system word byte size");
|
||||
metaspace::MetaspaceTestContext* context =
|
||||
new metaspace::MetaspaceTestContext("whitebox-metaspace-context", (size_t) commit_limit, (size_t) reserve_limit);
|
||||
new metaspace::MetaspaceTestContext("whitebox-metaspace-context", (size_t) commit_limit / BytesPerWord,
|
||||
(size_t) reserve_limit / BytesPerWord);
|
||||
return (jlong)p2i(context);
|
||||
WB_END
|
||||
|
||||
@ -1740,14 +1745,14 @@ WB_ENTRY(void, WB_PrintMetaspaceTestContext(JNIEnv* env, jobject wb, jlong conte
|
||||
context0->print_on(tty);
|
||||
WB_END
|
||||
|
||||
WB_ENTRY(jlong, WB_GetTotalCommittedWordsInMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context))
|
||||
WB_ENTRY(jlong, WB_GetTotalCommittedBytesInMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context))
|
||||
metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context;
|
||||
return context0->committed_words();
|
||||
return (jlong)context0->committed_words() * BytesPerWord;
|
||||
WB_END
|
||||
|
||||
WB_ENTRY(jlong, WB_GetTotalUsedWordsInMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context))
|
||||
WB_ENTRY(jlong, WB_GetTotalUsedBytesInMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context))
|
||||
metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context;
|
||||
return context0->used_words();
|
||||
return (jlong)context0->used_words() * BytesPerWord;
|
||||
WB_END
|
||||
|
||||
WB_ENTRY(jlong, WB_CreateArenaInTestContext(JNIEnv* env, jobject wb, jlong context, jboolean is_micro))
|
||||
@ -1760,21 +1765,33 @@ WB_ENTRY(void, WB_DestroyMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena
|
||||
delete (metaspace::MetaspaceTestArena*) arena;
|
||||
WB_END
|
||||
|
||||
WB_ENTRY(jlong, WB_AllocateFromMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena, jlong word_size))
|
||||
metaspace::MetaspaceTestArena* arena0 = (metaspace::MetaspaceTestArena*) arena;
|
||||
MetaWord* p = arena0->allocate((size_t) word_size);
|
||||
WB_ENTRY(jlong, WB_AllocateFromMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena, jlong size))
|
||||
assert(is_aligned(size, BytesPerWord),
|
||||
"WB_AllocateFromMetaspaceTestArena: size is not a multiple of the system word byte size");
|
||||
metaspace::MetaspaceTestArena *arena0 = (metaspace::MetaspaceTestArena *)arena;
|
||||
MetaWord *p = arena0->allocate((size_t) size / BytesPerWord);
|
||||
return (jlong)p2i(p);
|
||||
WB_END
|
||||
|
||||
WB_ENTRY(void, WB_DeallocateToMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena, jlong p, jlong word_size))
|
||||
WB_ENTRY(void, WB_DeallocateToMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena, jlong p, jlong size))
|
||||
assert(is_aligned(size, BytesPerWord),
|
||||
"WB_DeallocateToMetaspaceTestArena: size is not a multiple of the system word byte size");
|
||||
metaspace::MetaspaceTestArena* arena0 = (metaspace::MetaspaceTestArena*) arena;
|
||||
arena0->deallocate((MetaWord*)p, (size_t) word_size);
|
||||
arena0->deallocate((MetaWord*)p, (size_t) size / BytesPerWord);
|
||||
WB_END
|
||||
|
||||
WB_ENTRY(jlong, WB_GetMaxMetaspaceAllocationSize(JNIEnv* env, jobject wb))
|
||||
return (jlong) Metaspace::max_allocation_word_size() * BytesPerWord;
|
||||
WB_END
|
||||
|
||||
WB_ENTRY(jlong, WB_WordSize(JNIEnv* env))
|
||||
return (jlong)BytesPerWord;
|
||||
WB_END
|
||||
|
||||
WB_ENTRY(jlong, WB_RootChunkWordSize(JNIEnv* env))
|
||||
return (jlong)Metaspace::reserve_alignment_words();
|
||||
WB_END
|
||||
|
||||
//////////////
|
||||
|
||||
WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size))
|
||||
@ -2956,8 +2973,8 @@ static JNINativeMethod methods[] = {
|
||||
{CC"destroyMetaspaceTestContext", CC"(J)V", (void*)&WB_DestroyMetaspaceTestContext},
|
||||
{CC"purgeMetaspaceTestContext", CC"(J)V", (void*)&WB_PurgeMetaspaceTestContext},
|
||||
{CC"printMetaspaceTestContext", CC"(J)V", (void*)&WB_PrintMetaspaceTestContext},
|
||||
{CC"getTotalCommittedWordsInMetaspaceTestContext", CC"(J)J",(void*)&WB_GetTotalCommittedWordsInMetaspaceTestContext},
|
||||
{CC"getTotalUsedWordsInMetaspaceTestContext", CC"(J)J", (void*)&WB_GetTotalUsedWordsInMetaspaceTestContext},
|
||||
{CC"getTotalCommittedBytesInMetaspaceTestContext", CC"(J)J",(void*)&WB_GetTotalCommittedBytesInMetaspaceTestContext},
|
||||
{CC"getTotalUsedBytesInMetaspaceTestContext", CC"(J)J", (void*)&WB_GetTotalUsedBytesInMetaspaceTestContext},
|
||||
{CC"createArenaInTestContext", CC"(JZ)J", (void*)&WB_CreateArenaInTestContext},
|
||||
{CC"destroyMetaspaceTestArena", CC"(J)V", (void*)&WB_DestroyMetaspaceTestArena},
|
||||
{CC"allocateFromMetaspaceTestArena", CC"(JJ)J", (void*)&WB_AllocateFromMetaspaceTestArena},
|
||||
@ -2977,6 +2994,8 @@ static JNINativeMethod methods[] = {
|
||||
{CC"cleanMetaspaces", CC"()V", (void*)&WB_CleanMetaspaces},
|
||||
{CC"rss", CC"()J", (void*)&WB_Rss},
|
||||
{CC"printString", CC"(Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_PrintString},
|
||||
{CC"wordSize", CC"()J", (void*)&WB_WordSize},
|
||||
{CC"rootChunkWordSize", CC"()J", (void*)&WB_RootChunkWordSize}
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020 SAP SE. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
@ -26,11 +26,11 @@
|
||||
public class Allocation {
|
||||
|
||||
public long p;
|
||||
public long word_size;
|
||||
public long size;
|
||||
|
||||
public Allocation(long p, long word_size) {
|
||||
public Allocation(long p, long size) {
|
||||
this.p = p;
|
||||
this.word_size = word_size;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public boolean isNull() {
|
||||
@ -41,7 +41,7 @@ public class Allocation {
|
||||
public String toString() {
|
||||
return "Allocation{" +
|
||||
"p=" + p +
|
||||
", word_size=" + word_size +
|
||||
", size=" + size +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020 SAP SE. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
@ -43,6 +43,9 @@ public class AllocationProfile {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns random allocation size measured in words
|
||||
*/
|
||||
public long randomAllocationSize() {
|
||||
Random r = new Random();
|
||||
return r.nextInt((int)(maximumSingleAllocationSize - minimumSingleAllocationSize + 1)) + minimumSingleAllocationSize;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2023, SAP SE. All rights reserved.
|
||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 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
|
||||
@ -31,25 +31,25 @@ public class MetaspaceTestArena {
|
||||
|
||||
final long allocationCeiling;
|
||||
|
||||
// Number and word size of allocations
|
||||
long allocatedWords = 0;
|
||||
// Number and byte size of allocations
|
||||
long allocatedBytes = 0;
|
||||
long numAllocated = 0;
|
||||
long deallocatedWords = 0;
|
||||
long deallocatedBytes = 0;
|
||||
long numDeallocated = 0;
|
||||
volatile long numAllocationFailures = 0;
|
||||
|
||||
private synchronized boolean reachedCeiling() {
|
||||
return (allocatedWords - deallocatedWords) > allocationCeiling;
|
||||
return (allocatedBytes - deallocatedBytes) > allocationCeiling;
|
||||
}
|
||||
|
||||
private synchronized void accountAllocation(long words) {
|
||||
private synchronized void accountAllocation(long size) {
|
||||
numAllocated ++;
|
||||
allocatedWords += words;
|
||||
allocatedBytes += size;
|
||||
}
|
||||
|
||||
private synchronized void accountDeallocation(long words) {
|
||||
private synchronized void accountDeallocation(long size) {
|
||||
numDeallocated ++;
|
||||
deallocatedWords += words;
|
||||
deallocatedBytes += size;
|
||||
}
|
||||
|
||||
MetaspaceTestArena(long arena0, long allocationCeiling) {
|
||||
@ -57,42 +57,42 @@ public class MetaspaceTestArena {
|
||||
this.arena = arena0;
|
||||
}
|
||||
|
||||
public Allocation allocate(long words) {
|
||||
public Allocation allocate(long size) {
|
||||
if (reachedCeiling()) {
|
||||
numAllocationFailures ++;
|
||||
return null;
|
||||
}
|
||||
WhiteBox wb = WhiteBox.getWhiteBox();
|
||||
long p = wb.allocateFromMetaspaceTestArena(arena, words);
|
||||
long p = wb.allocateFromMetaspaceTestArena(arena, size);
|
||||
if (p == 0) {
|
||||
numAllocationFailures ++;
|
||||
return null;
|
||||
} else {
|
||||
accountAllocation(words);
|
||||
accountAllocation(size);
|
||||
}
|
||||
return new Allocation(p, words);
|
||||
return new Allocation(p, size);
|
||||
}
|
||||
|
||||
public void deallocate(Allocation a) {
|
||||
WhiteBox wb = WhiteBox.getWhiteBox();
|
||||
wb.deallocateToMetaspaceTestArena(arena, a.p, a.word_size);
|
||||
accountDeallocation(a.word_size);
|
||||
wb.deallocateToMetaspaceTestArena(arena, a.p, a.size);
|
||||
accountDeallocation(a.size);
|
||||
}
|
||||
|
||||
//// Convenience functions ////
|
||||
|
||||
public Allocation allocate_expect_success(long words) {
|
||||
Allocation a = allocate(words);
|
||||
public Allocation allocate_expect_success(long size) {
|
||||
Allocation a = allocate(size);
|
||||
if (a.isNull()) {
|
||||
throw new RuntimeException("Allocation failed (" + words + ")");
|
||||
throw new RuntimeException("Allocation failed (" + size + ")");
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
public void allocate_expect_failure(long words) {
|
||||
Allocation a = allocate(words);
|
||||
public void allocate_expect_failure(long size) {
|
||||
Allocation a = allocate(size);
|
||||
if (!a.isNull()) {
|
||||
throw new RuntimeException("Allocation failed (" + words + ")");
|
||||
throw new RuntimeException("Allocation failed (" + size + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,9 +104,9 @@ public class MetaspaceTestArena {
|
||||
public String toString() {
|
||||
return "arena=" + arena +
|
||||
", ceiling=" + allocationCeiling +
|
||||
", allocatedWords=" + allocatedWords +
|
||||
", allocatedBytes=" + allocatedBytes +
|
||||
", numAllocated=" + numAllocated +
|
||||
", deallocatedWords=" + deallocatedWords +
|
||||
", deallocatedBytes=" + deallocatedBytes +
|
||||
", numDeallocated=" + numDeallocated +
|
||||
", numAllocationFailures=" + numAllocationFailures +
|
||||
'}';
|
||||
|
@ -39,9 +39,9 @@ public class MetaspaceTestContext {
|
||||
|
||||
HashSet<MetaspaceTestArena> arenaList = new HashSet<>();
|
||||
|
||||
long allocatedWords;
|
||||
long allocatedBytes;
|
||||
long numAllocated;
|
||||
long deallocatedWords;
|
||||
long deallocatedBytes;
|
||||
long numDeallocated;
|
||||
long allocationFailures;
|
||||
|
||||
@ -101,20 +101,20 @@ public class MetaspaceTestContext {
|
||||
}
|
||||
}
|
||||
|
||||
public long committedWords() {
|
||||
public long committedBytes() {
|
||||
long l = 0;
|
||||
if (context != 0) {
|
||||
WhiteBox wb = WhiteBox.getWhiteBox();
|
||||
l = wb.getTotalCommittedWordsInMetaspaceTestContext(context);
|
||||
l = wb.getTotalCommittedBytesInMetaspaceTestContext(context);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public long usedWords() {
|
||||
public long usedBytes() {
|
||||
long l = 0;
|
||||
if (context != 0) {
|
||||
WhiteBox wb = WhiteBox.getWhiteBox();
|
||||
l = wb.getTotalUsedWordsInMetaspaceTestContext(context);
|
||||
l = wb.getTotalUsedBytesInMetaspaceTestContext(context);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
@ -124,10 +124,10 @@ public class MetaspaceTestContext {
|
||||
}
|
||||
|
||||
public void updateTotals() {
|
||||
allocatedWords = deallocatedWords = numAllocated = numDeallocated = 0;
|
||||
allocatedBytes = deallocatedBytes = numAllocated = numDeallocated = 0;
|
||||
for (MetaspaceTestArena a : arenaList) {
|
||||
allocatedWords += a.allocatedWords;
|
||||
deallocatedWords += a.deallocatedWords;
|
||||
allocatedBytes += a.allocatedBytes;
|
||||
deallocatedBytes += a.deallocatedBytes;
|
||||
numAllocated += a.numAllocated;
|
||||
numDeallocated += a.numDeallocated;
|
||||
allocationFailures += a.numAllocationFailures;
|
||||
@ -159,17 +159,17 @@ public class MetaspaceTestContext {
|
||||
|
||||
updateTotals();
|
||||
|
||||
long usageMeasured = usedWords();
|
||||
long committedMeasured = committedWords();
|
||||
long usageMeasured = usedBytes();
|
||||
long committedMeasured = committedBytes();
|
||||
|
||||
System.out.println("context used words " + usageMeasured + ", committed words " + committedMeasured
|
||||
System.out.println("context used bytes " + usageMeasured + ", committed bytes " + committedMeasured
|
||||
+ ".");
|
||||
|
||||
if (usageMeasured > committedMeasured) {
|
||||
throw new RuntimeException("Weirdness.");
|
||||
}
|
||||
|
||||
if (deallocatedWords > allocatedWords) {
|
||||
if (deallocatedBytes > allocatedBytes) {
|
||||
throw new RuntimeException("Weirdness.");
|
||||
}
|
||||
|
||||
@ -183,13 +183,13 @@ public class MetaspaceTestContext {
|
||||
}
|
||||
}
|
||||
|
||||
long expectedMinUsage = allocatedWords - deallocatedWords;
|
||||
long expectedMinUsage = allocatedBytes - deallocatedBytes;
|
||||
|
||||
if (usageMeasured < expectedMinUsage) {
|
||||
throw new RuntimeException("Usage too low: " + usageMeasured + " expected at least " + expectedMinUsage);
|
||||
}
|
||||
|
||||
long expectedMaxUsage = allocatedWords;
|
||||
long expectedMaxUsage = allocatedBytes;
|
||||
|
||||
// This is necessary a bit fuzzy, since Metaspace usage consists of:
|
||||
// - whatever we allocated
|
||||
@ -199,12 +199,12 @@ public class MetaspaceTestContext {
|
||||
|
||||
// Overhead per allocation (see metaspaceArena.cpp, get_raw_allocation_word_size() )
|
||||
// Any allocation is 3 words least
|
||||
expectedMaxUsage += (numAllocated * 3);
|
||||
expectedMaxUsage += (numAllocated * 3 * Settings.WORD_SIZE);
|
||||
|
||||
// Lets add a overhead per arena. Each arena carries a free block list containing
|
||||
// deallocated/retired blocks. We do not know how much. In general, the free block list should not
|
||||
// accumulate a lot of memory but be drained in the course of allocating memory from the arena.
|
||||
long overheadPerArena = 1024 * 1024 * numLiveArenas();
|
||||
long overheadPerArena = 1024 * 1024 * numLiveArenas() * Settings.WORD_SIZE;
|
||||
expectedMaxUsage += overheadPerArena;
|
||||
|
||||
if (expectedMaxUsage < usageMeasured) {
|
||||
@ -229,7 +229,7 @@ public class MetaspaceTestContext {
|
||||
// are stress tests,
|
||||
//
|
||||
long expectedMaxCommitted = usageMeasured;
|
||||
expectedMaxCommitted += Settings.rootChunkWordSize;
|
||||
expectedMaxCommitted += Settings.ROOT_CHUNK_WORD_SIZE * Settings.WORD_SIZE;
|
||||
expectedMaxCommitted *= 10.0;
|
||||
|
||||
if (committedMeasured > expectedMaxCommitted) {
|
||||
@ -247,9 +247,9 @@ public class MetaspaceTestContext {
|
||||
", numArenasCreated=" + numArenasCreated +
|
||||
", numArenasDestroyed=" + numArenasDestroyed +
|
||||
", numLiveArenas=" + numLiveArenas() +
|
||||
", allocatedWords=" + allocatedWords +
|
||||
", allocatedBytes=" + allocatedBytes +
|
||||
", numAllocated=" + numAllocated +
|
||||
", deallocatedWords=" + deallocatedWords +
|
||||
", deallocatedBytes=" + deallocatedBytes +
|
||||
", numDeallocated=" + numDeallocated +
|
||||
", allocationFailures=" + allocationFailures +
|
||||
'}';
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 2023 SAP SE. All rights reserved.
|
||||
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 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
|
||||
@ -28,7 +28,7 @@ public class MetaspaceTestWithThreads {
|
||||
// The context to use.
|
||||
final MetaspaceTestContext context;
|
||||
|
||||
// Total *word* size we allow for the test to allocation. The test may overshoot this a bit, but should not by much.
|
||||
// Total *byte* size we allow for the test to allocation. The test may overshoot this a bit, but should not by much.
|
||||
final long testAllocationCeiling;
|
||||
|
||||
// Number of parallel allocators
|
||||
@ -77,8 +77,8 @@ public class MetaspaceTestWithThreads {
|
||||
|
||||
context.checkStatistics();
|
||||
|
||||
if (context.committedWords() > 0) {
|
||||
throw new RuntimeException("Expected no committed words after purging empty metaspace context (was: " + context.committedWords() + ")");
|
||||
if (context.committedBytes() > 0) {
|
||||
throw new RuntimeException("Expected no committed bytes after purging empty metaspace context (was: " + context.committedBytes() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2021 SAP SE. All rights reserved.
|
||||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 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
|
||||
@ -26,6 +26,8 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import jdk.test.whitebox.WhiteBox;
|
||||
|
||||
/**
|
||||
* RandomAllocator sits atop an arena and allocates from it.
|
||||
*
|
||||
@ -61,8 +63,8 @@ public class RandomAllocator {
|
||||
|
||||
// Allocate a random amount from the arena. If dice hits right, add this to the deallocation list.
|
||||
void allocateRandomly() {
|
||||
long word_size = profile.randomAllocationSize();
|
||||
Allocation a = arena.allocate(word_size);
|
||||
long words = profile.randomAllocationSize();
|
||||
Allocation a = arena.allocate(words * Settings.WORD_SIZE);
|
||||
if (a != null) {
|
||||
if (to_dealloc.size() < 10000) {
|
||||
to_dealloc.add(a);
|
||||
|
@ -27,8 +27,8 @@ import jdk.test.whitebox.WhiteBox;
|
||||
|
||||
public final class Settings {
|
||||
|
||||
final static long rootChunkWordSize = 2048 * 1024;
|
||||
|
||||
final static long ROOT_CHUNK_WORD_SIZE = WhiteBox.getWhiteBox().rootChunkWordSize();
|
||||
final static long WORD_SIZE = WhiteBox.getWhiteBox().wordSize();
|
||||
static Settings theSettings;
|
||||
|
||||
static Settings settings() {
|
||||
|
@ -45,19 +45,21 @@
|
||||
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI TestMetaspaceAllocation
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Unit;
|
||||
|
||||
public class TestMetaspaceAllocation {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
MetaspaceTestContext context = new MetaspaceTestContext();
|
||||
MetaspaceTestArena arena1 = context.createArena(false, 1024 * 1024 * 4);
|
||||
MetaspaceTestArena arena2 = context.createArena(true,1024 * 1024 * 4);
|
||||
MetaspaceTestArena arena1 = context.createArena(false, 32L * Unit.M.size());
|
||||
MetaspaceTestArena arena2 = context.createArena(true, 32L * Unit.M.size());
|
||||
|
||||
Allocation a1 = arena1.allocate(100);
|
||||
Allocation a2 = arena2.allocate(100);
|
||||
Allocation a1 = arena1.allocate(800);
|
||||
Allocation a2 = arena2.allocate(800);
|
||||
|
||||
long used = context.usedWords();
|
||||
long committed = context.committedWords();
|
||||
long used = context.usedBytes();
|
||||
long committed = context.committedBytes();
|
||||
|
||||
System.out.println("used " + used + " committed " + committed);
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
/*
|
||||
* This is a stress test for allocating from a single MetaspaceArena from
|
||||
* multiple threads, optionally with reserve limit (mimicking the non-expandable CompressedClassSpace)
|
||||
* or commit limit (mimimcking MaxMetaspaceSize).
|
||||
* or commit limit (mimicking MaxMetaspaceSize).
|
||||
*
|
||||
* The test threads will start to allocate from the Arena, and occasionally deallocate.
|
||||
* The threads run with a safety allocation max; if reached (or, if the underlying arena
|
||||
@ -34,7 +34,7 @@
|
||||
* kind of float at the allocation ceiling, alternating between allocation and deallocation.
|
||||
*
|
||||
* We test with various flags, to exercise all 3 reclaim policies (none, balanced (default)
|
||||
* and aggessive) as well as one run with allocation guards enabled.
|
||||
* and aggressive) as well as one run with allocation guards enabled.
|
||||
*
|
||||
* We also set MetaspaceVerifyInterval very low to trigger many verifications in debug vm.
|
||||
*
|
||||
@ -90,21 +90,24 @@
|
||||
* TestMetaspaceAllocationMT1 3
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Unit;
|
||||
|
||||
public class TestMetaspaceAllocationMT1 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
final long testAllocationCeiling = 1024 * 1024 * 8; // 8m words = 64M on 64bit
|
||||
final long testAllocationCeiling = 64L * Unit.M.size();
|
||||
|
||||
final int numThreads = 4;
|
||||
final int seconds = Integer.parseInt(args[0]);
|
||||
|
||||
for (int i = 0; i < 3; i ++) {
|
||||
|
||||
long commitLimit = (i == 1) ? 1024 * 256 : 0;
|
||||
long commitLimit = (i == 1) ? 2 * Unit.M.size() : 0;
|
||||
|
||||
// Note: reserve limit must be a multiple of Metaspace::reserve_alignment_words()
|
||||
// (512K on 64bit, 1M on 32bit)
|
||||
long reserveLimit = (i == 2) ? Settings.rootChunkWordSize * 2 : 0;
|
||||
// (16 MB)
|
||||
long reserveLimit = (i == 2) ? Settings.ROOT_CHUNK_WORD_SIZE * 16: 0;
|
||||
|
||||
System.out.println("#### Test: ");
|
||||
System.out.println("#### testAllocationCeiling: " + testAllocationCeiling);
|
||||
|
@ -26,7 +26,7 @@
|
||||
/*
|
||||
* This is a stress test for allocating from a single MetaspaceArena from
|
||||
* multiple threads, optionally with reserve limit (mimicking the non-expandable CompressedClassSpace)
|
||||
* or commit limit (mimimcking MaxMetaspaceSize).
|
||||
* or commit limit (mimicking MaxMetaspaceSize).
|
||||
*
|
||||
* The test threads will start to allocate from the Arena, and occasionally deallocate.
|
||||
* The threads run with a safety allocation max; if reached (or, if the underlying arena
|
||||
@ -34,7 +34,7 @@
|
||||
* kind of float at the allocation ceiling, alternating between allocation and deallocation.
|
||||
*
|
||||
* We test with various flags, to exercise all 3 reclaim policies (none, balanced (default)
|
||||
* and aggessive) as well as one run with allocation guards enabled.
|
||||
* and aggressive) as well as one run with allocation guards enabled.
|
||||
*
|
||||
* We also set MetaspaceVerifyInterval very low to trigger many verifications in debug vm.
|
||||
*
|
||||
@ -90,20 +90,22 @@
|
||||
* TestMetaspaceAllocationMT2 3
|
||||
*/
|
||||
|
||||
import jdk.test.lib.Unit;
|
||||
|
||||
public class TestMetaspaceAllocationMT2 {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
final long testAllocationCeiling = 1024 * 1024 * 6; // 8m words = 64M on 64bit
|
||||
final long testAllocationCeiling = 48L * Unit.M.size();
|
||||
final int numThreads = 4;
|
||||
final int seconds = Integer.parseInt(args[0]);
|
||||
|
||||
for (int i = 0; i < 3; i ++) {
|
||||
|
||||
long commitLimit = (i == 1) ? 1024 * 256 : 0;
|
||||
long commitLimit = (i == 1) ? 2L * Unit.M.size() : 0;
|
||||
|
||||
// Note: reserve limit must be a multiple of Metaspace::reserve_alignment_words()
|
||||
long reserveLimit = (i == 2) ? Settings.rootChunkWordSize * 2 : 0;
|
||||
long reserveLimit = (i == 2) ? Settings.ROOT_CHUNK_WORD_SIZE * 16: 0;
|
||||
|
||||
System.out.println("#### Test: ");
|
||||
System.out.println("#### testAllocationCeiling: " + testAllocationCeiling);
|
||||
|
36
test/lib/jdk/test/lib/Unit.java
Normal file
36
test/lib/jdk/test/lib/Unit.java
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2024, Red Hat Inc.
|
||||
* 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 jdk.test.lib;
|
||||
|
||||
public enum Unit {
|
||||
B(1), K(1024), M(1024 * 1024), G(1024 * 1024 * 1024);
|
||||
public final long size;
|
||||
Unit(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
public long size() {
|
||||
return size;
|
||||
}
|
||||
}
|
@ -540,15 +540,19 @@ public class WhiteBox {
|
||||
public native void destroyMetaspaceTestContext(long context);
|
||||
public native void purgeMetaspaceTestContext(long context);
|
||||
public native void printMetaspaceTestContext(long context);
|
||||
public native long getTotalCommittedWordsInMetaspaceTestContext(long context);
|
||||
public native long getTotalUsedWordsInMetaspaceTestContext(long context);
|
||||
public native long getTotalCommittedBytesInMetaspaceTestContext(long context);
|
||||
public native long getTotalUsedBytesInMetaspaceTestContext(long context);
|
||||
public native long createArenaInTestContext(long context, boolean is_micro);
|
||||
public native void destroyMetaspaceTestArena(long arena);
|
||||
public native long allocateFromMetaspaceTestArena(long arena, long word_size);
|
||||
public native void deallocateToMetaspaceTestArena(long arena, long p, long word_size);
|
||||
public native long allocateFromMetaspaceTestArena(long arena, long size);
|
||||
public native void deallocateToMetaspaceTestArena(long arena, long p, long size);
|
||||
|
||||
public native long maxMetaspaceAllocationSize();
|
||||
|
||||
// Word size measured in bytes
|
||||
public native long wordSize();
|
||||
public native long rootChunkWordSize();
|
||||
|
||||
// Don't use these methods directly
|
||||
// Use jdk.test.whitebox.gc.GC class instead.
|
||||
public native boolean isGCSupported(int name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user