Skip to content

Commit a93e5ef

Browse files
committed
8275608: runtime/Metaspace/elastic/TestMetaspaceAllocationMT2 too slow
Backport-of: d6d82f52d4a4fac037ee9424503f8b7f11a61c40
1 parent 096c31c commit a93e5ef

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

test/hotspot/jtreg/runtime/Metaspace/elastic/MetaspaceTestArena.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
import sun.hotspot.WhiteBox;
2727

28-
import java.util.concurrent.atomic.AtomicLong;
29-
3028
public class MetaspaceTestArena {
3129

3230
long arena;
@@ -38,7 +36,7 @@ public class MetaspaceTestArena {
3836
long numAllocated = 0;
3937
long deallocatedWords = 0;
4038
long numDeallocated = 0;
41-
long numAllocationFailures = 0;
39+
volatile long numAllocationFailures = 0;
4240

4341
private synchronized boolean reachedCeiling() {
4442
return (allocatedWords - deallocatedWords) > allocationCeiling;

test/hotspot/jtreg/runtime/Metaspace/elastic/MetaspaceTestManyArenasManyThreads.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2020 SAP SE. All rights reserved.
2+
* Copyright (c) 2021 SAP SE. All rights reserved.
3+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -63,7 +63,7 @@ public void runTest() throws Exception {
6363
Thread.sleep(200);
6464

6565
for (RandomAllocatorThread t: threads) {
66-
if (t.allocator.arena.numAllocationFailures > 0) {
66+
if (t.allocator.arena.numAllocationFailures > 1000) {
6767
t.interrupt();
6868
t.join();
6969
context.destroyArena(t.allocator.arena);

test/hotspot/jtreg/runtime/Metaspace/elastic/MetaspaceTestWithThreads.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2020 SAP SE. All rights reserved.
2+
* Copyright (c) 2021 SAP SE. All rights reserved.
3+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -23,8 +23,6 @@
2323
*
2424
*/
2525

26-
import java.util.Set;
27-
2826
public class MetaspaceTestWithThreads {
2927

3028
// The context to use.
@@ -53,6 +51,8 @@ protected void stopAllThreads() throws InterruptedException {
5351
// Stop all threads.
5452
for (Thread t: threads) {
5553
t.interrupt();
54+
}
55+
for (Thread t: threads) {
5656
t.join();
5757
}
5858
}

test/hotspot/jtreg/runtime/Metaspace/elastic/RandomAllocator.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2020 SAP SE. All rights reserved.
2+
* Copyright (c) 2021 SAP SE. All rights reserved.
3+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -46,7 +46,11 @@ public class RandomAllocator {
4646
ArrayList<Allocation> to_dealloc = new ArrayList<>();
4747

4848
long ticks = 0;
49-
boolean allocationError = false;
49+
50+
// Allocate (breathe in) until arena is full, then - to test the arena deallocator - deallocate some allocations
51+
// and breathe in again until full.
52+
boolean breatheIn = true;
53+
int breatheOutTicks = 0;
5054

5155
Random localRandom;
5256

@@ -57,15 +61,16 @@ private boolean rollDice(double probability) {
5761

5862
// Allocate a random amount from the arena. If dice hits right, add this to the deallocation list.
5963
void allocateRandomly() {
60-
allocationError = false;
6164
long word_size = profile.randomAllocationSize();
6265
Allocation a = arena.allocate(word_size);
6366
if (a != null) {
6467
if (to_dealloc.size() < 10000) {
6568
to_dealloc.add(a);
6669
}
6770
} else {
68-
allocationError = true;
71+
// On allocation error, breathe out a bit
72+
breatheIn = false;
73+
breatheOutTicks = 0;
6974
}
7075
}
7176

@@ -80,19 +85,20 @@ void deallocateRandomly() {
8085
}
8186

8287
public void tick() {
83-
84-
if (!allocationError) {
88+
if (breatheIn) {
89+
// allocate until we hit the ceiling
8590
allocateRandomly();
86-
if(rollDice(profile.randomDeallocProbability)) {
91+
if (rollDice(profile.randomDeallocProbability)) {
8792
deallocateRandomly();
8893
}
8994
} else {
90-
deallocateRandomly();
91-
allocationError = false;
95+
if (++breatheOutTicks < 100) {
96+
deallocateRandomly();
97+
} else {
98+
breatheIn = true;
99+
}
92100
}
93-
94101
ticks ++;
95-
96102
}
97103

98104
public RandomAllocator(MetaspaceTestArena arena) {
@@ -102,6 +108,10 @@ public RandomAllocator(MetaspaceTestArena arena) {
102108
this.localRandom = new Random(RandomHelper.random().nextInt());
103109
}
104110

111+
long numAllocationFailures() {
112+
return arena.numAllocationFailures;
113+
}
114+
105115
@Override
106116
public String toString() {
107117
return arena.toString() + ", ticks=" + ticks;

test/hotspot/jtreg/runtime/Metaspace/elastic/RandomAllocatorThread.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2020 SAP SE. All rights reserved.
2+
* Copyright (c) 2021 SAP SE. All rights reserved.
3+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,6 @@
2323
*
2424
*/
2525

26-
import java.util.Random;
2726
import java.util.concurrent.BrokenBarrierException;
2827
import java.util.concurrent.CyclicBarrier;
2928

@@ -55,9 +54,7 @@ public void run() {
5554
}
5655

5756
while (!Thread.interrupted()) {
58-
for (int i = 0; i < 1000; i++) {
59-
allocator.tick();
60-
}
57+
allocator.tick();
6158
}
6259

6360
// System.out.println("+ [" + id + "] " + allocator);

0 commit comments

Comments
 (0)