Skip to content

Commit

Permalink
8275608: runtime/Metaspace/elastic/TestMetaspaceAllocationMT2 too slow
Browse files Browse the repository at this point in the history
Reviewed-by: mbaesken, shade
  • Loading branch information
tstuefe committed Oct 29, 2021
1 parent a1ec4f9 commit d6d82f5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

import sun.hotspot.WhiteBox;

import java.util.concurrent.atomic.AtomicLong;

public class MetaspaceTestArena {

long arena;
Expand All @@ -38,7 +36,7 @@ public class MetaspaceTestArena {
long numAllocated = 0;
long deallocatedWords = 0;
long numDeallocated = 0;
long numAllocationFailures = 0;
volatile long numAllocationFailures = 0;

private synchronized boolean reachedCeiling() {
return (allocatedWords - deallocatedWords) > allocationCeiling;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020 SAP SE. All rights reserved.
* Copyright (c) 2021 SAP SE. All rights reserved.
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -63,7 +63,7 @@ public void runTest() throws Exception {
Thread.sleep(200);

for (RandomAllocatorThread t: threads) {
if (t.allocator.arena.numAllocationFailures > 0) {
if (t.allocator.arena.numAllocationFailures > 1000) {
t.interrupt();
t.join();
context.destroyArena(t.allocator.arena);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020 SAP SE. All rights reserved.
* Copyright (c) 2021 SAP SE. All rights reserved.
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,8 +23,6 @@
*
*/

import java.util.Set;

public class MetaspaceTestWithThreads {

// The context to use.
Expand Down Expand Up @@ -53,6 +51,8 @@ protected void stopAllThreads() throws InterruptedException {
// Stop all threads.
for (Thread t: threads) {
t.interrupt();
}
for (Thread t: threads) {
t.join();
}
}
Expand Down
34 changes: 22 additions & 12 deletions test/hotspot/jtreg/runtime/Metaspace/elastic/RandomAllocator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020 SAP SE. All rights reserved.
* Copyright (c) 2021 SAP SE. All rights reserved.
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -46,7 +46,11 @@ public class RandomAllocator {
ArrayList<Allocation> to_dealloc = new ArrayList<>();

long ticks = 0;
boolean allocationError = false;

// Allocate (breathe in) until arena is full, then - to test the arena deallocator - deallocate some allocations
// and breathe in again until full.
boolean breatheIn = true;
int breatheOutTicks = 0;

Random localRandom;

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

// Allocate a random amount from the arena. If dice hits right, add this to the deallocation list.
void allocateRandomly() {
allocationError = false;
long word_size = profile.randomAllocationSize();
Allocation a = arena.allocate(word_size);
if (a != null) {
if (to_dealloc.size() < 10000) {
to_dealloc.add(a);
}
} else {
allocationError = true;
// On allocation error, breathe out a bit
breatheIn = false;
breatheOutTicks = 0;
}
}

Expand All @@ -80,19 +85,20 @@ void deallocateRandomly() {
}

public void tick() {

if (!allocationError) {
if (breatheIn) {
// allocate until we hit the ceiling
allocateRandomly();
if(rollDice(profile.randomDeallocProbability)) {
if (rollDice(profile.randomDeallocProbability)) {
deallocateRandomly();
}
} else {
deallocateRandomly();
allocationError = false;
if (++breatheOutTicks < 100) {
deallocateRandomly();
} else {
breatheIn = true;
}
}

ticks ++;

}

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

long numAllocationFailures() {
return arena.numAllocationFailures;
}

@Override
public String toString() {
return arena.toString() + ", ticks=" + ticks;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020 SAP SE. All rights reserved.
* Copyright (c) 2021 SAP SE. All rights reserved.
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,6 @@
*
*/

import java.util.Random;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

Expand Down Expand Up @@ -55,9 +54,7 @@ public void run() {
}

while (!Thread.interrupted()) {
for (int i = 0; i < 1000; i++) {
allocator.tick();
}
allocator.tick();
}

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

7 comments on commit d6d82f5

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tstuefe
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on d6d82f5 Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tstuefe The target repository jdk17u-dev is not a valid target for backports.
List of valid target repositories: openjdk/jdk11u, openjdk/jdk11u-dev, openjdk/jdk12u, openjdk/jdk13u, openjdk/jdk13u-dev, openjdk/jdk14u, openjdk/jdk15u, openjdk/jdk15u-dev, openjdk/jdk16u, openjdk/jdk17u, openjdk/jdk18.
Supplying the organization/group prefix is optional.

@tstuefe
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u

@openjdk
Copy link

@openjdk openjdk bot commented on d6d82f5 Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tstuefe the backport was successfully created on the branch tstuefe-backport-d6d82f52 in my personal fork of openjdk/jdk17u. To create a pull request with this backport targeting openjdk/jdk17u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit d6d82f52 from the openjdk/jdk repository.

The commit being backported was authored by Thomas Stuefe on 29 Oct 2021 and was reviewed by Matthias Baesken and Aleksey Shipilev.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u:

$ git fetch https://github.com/openjdk-bots/jdk17u tstuefe-backport-d6d82f52:tstuefe-backport-d6d82f52
$ git checkout tstuefe-backport-d6d82f52
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u tstuefe-backport-d6d82f52

@tstuefe
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on d6d82f5 Jan 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tstuefe the backport was successfully created on the branch tstuefe-backport-d6d82f52 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit d6d82f52 from the openjdk/jdk repository.

The commit being backported was authored by Thomas Stuefe on 29 Oct 2021 and was reviewed by Matthias Baesken and Aleksey Shipilev.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev tstuefe-backport-d6d82f52:tstuefe-backport-d6d82f52
$ git checkout tstuefe-backport-d6d82f52
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev tstuefe-backport-d6d82f52

Please sign in to comment.