mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-11 14:11:36 +00:00
8235250: Create (test) abstraction for allocating objects that is immune to removal by optimizations
Reviewed-by: eosterlund, tschatzl
This commit is contained in:
parent
979cd452ab
commit
c023983c7f
@ -23,8 +23,6 @@
|
||||
|
||||
package gc.arguments;
|
||||
|
||||
import static java.lang.ref.Reference.reachabilityFence;
|
||||
|
||||
/*
|
||||
* @test TestTargetSurvivorRatioFlag
|
||||
* @key gc
|
||||
@ -50,9 +48,9 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.Utils;
|
||||
import sun.hotspot.WhiteBox;
|
||||
import static gc.testlibrary.Allocation.blackHole;
|
||||
|
||||
/* In order to test that TargetSurvivorRatio affects survivor space occupancy
|
||||
* we setup fixed MaxTenuringThreshold and then verifying that if size of allocated
|
||||
@ -299,7 +297,7 @@ public class TestTargetSurvivorRatioFlag {
|
||||
|
||||
// force minor GC
|
||||
while (youngGCBean.getCollectionCount() <= initialGcId + MAX_TENURING_THRESHOLD * 2) {
|
||||
reachabilityFence(new byte[ARRAY_LENGTH]);
|
||||
blackHole(new byte[ARRAY_LENGTH]);
|
||||
}
|
||||
|
||||
allocator.release();
|
||||
|
||||
@ -23,12 +23,13 @@
|
||||
|
||||
package gc.cslocker;
|
||||
|
||||
import static java.lang.ref.Reference.reachabilityFence;
|
||||
import static gc.testlibrary.Allocation.blackHole;
|
||||
|
||||
/*
|
||||
* @test TestCSLocker
|
||||
* @key gc
|
||||
* @bug 6186200
|
||||
* @library /
|
||||
* @summary This short test check RFE 6186200 changes. One thread locked
|
||||
* @summary completely in JNI CS, while other is trying to allocate memory
|
||||
* @summary provoking GC. OOM means FAIL, deadlock means PASS.
|
||||
@ -75,7 +76,7 @@ class GarbageProducer extends Thread
|
||||
|
||||
while (isRunning) {
|
||||
try {
|
||||
reachabilityFence(new int[size]);
|
||||
blackHole(new int[size]);
|
||||
sleep(sleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
isRunning = false;
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
package gc.g1;
|
||||
|
||||
import static java.lang.ref.Reference.reachabilityFence;
|
||||
import static gc.testlibrary.Allocation.blackHole;
|
||||
|
||||
/*
|
||||
* @test TestHumongousAllocNearlyFullRegion
|
||||
@ -33,6 +33,7 @@ import static java.lang.ref.Reference.reachabilityFence;
|
||||
* @requires vm.gc.G1
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @library /test/lib
|
||||
* @library /
|
||||
* @run driver gc.g1.TestHumongousAllocNearlyFullRegion
|
||||
*/
|
||||
|
||||
@ -64,7 +65,7 @@ public class TestHumongousAllocNearlyFullRegion {
|
||||
for (int i = 0; i < heapSize; i++) {
|
||||
// 131069 is the number of longs it takes to fill a heapRegion except
|
||||
// for 8 bytes on 64 bit.
|
||||
reachabilityFence(new long[131069]);
|
||||
blackHole(new long[131069]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ package gc.g1.humongousObjects;
|
||||
import jdk.test.lib.Utils;
|
||||
import sun.hotspot.WhiteBox;
|
||||
|
||||
import static java.lang.ref.Reference.reachabilityFence;
|
||||
import static gc.testlibrary.Allocation.blackHole;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -141,7 +141,7 @@ public class TestNoAllocationsInHRegions {
|
||||
// Dead object allocation
|
||||
() -> {
|
||||
int size = RND.nextInt(DEAD_OBJECT_MAX_SIZE);
|
||||
reachabilityFence(new byte[size]);
|
||||
blackHole(new byte[size]);
|
||||
},
|
||||
|
||||
// Check
|
||||
|
||||
@ -32,7 +32,7 @@ import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.ReflectionException;
|
||||
|
||||
import static java.lang.ref.Reference.reachabilityFence;
|
||||
import static gc.testlibrary.Allocation.blackHole;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.LinkedList;
|
||||
@ -131,7 +131,7 @@ class MemoryStresser implements Runnable {
|
||||
// Dead object allocation
|
||||
() -> {
|
||||
int size = RND.nextInt(DEAD_OBJECT_MAX_SIZE);
|
||||
reachabilityFence(new byte[size]);
|
||||
blackHole(new byte[size]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
41
test/hotspot/jtreg/gc/testlibrary/Allocation.java
Normal file
41
test/hotspot/jtreg/gc/testlibrary/Allocation.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 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 gc.testlibrary;
|
||||
|
||||
public class Allocation {
|
||||
public static volatile Object obj;
|
||||
|
||||
/**
|
||||
* This code assigns the object to a "public static volatile" variable. The
|
||||
* compiler does not seem capable of optimizing through this (yet). Any object
|
||||
* allocated and sent to this method ought not to be optimized away.
|
||||
*
|
||||
* @param obj The allocation of this object will not be optimized away.
|
||||
*/
|
||||
|
||||
public static void blackHole(Object obj) {
|
||||
Allocation.obj = obj;
|
||||
Allocation.obj = null;
|
||||
}
|
||||
}
|
||||
@ -27,6 +27,7 @@ package gc.z;
|
||||
* @test TestSmallHeap
|
||||
* @requires vm.gc.Z & !vm.graal.enabled & vm.compMode != "Xcomp"
|
||||
* @summary Test ZGC with small heaps
|
||||
* @library /
|
||||
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx8M gc.z.TestSmallHeap
|
||||
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx16M gc.z.TestSmallHeap
|
||||
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx32M gc.z.TestSmallHeap
|
||||
@ -37,7 +38,7 @@ package gc.z;
|
||||
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -Xlog:gc,gc+init,gc+heap -Xmx1024M gc.z.TestSmallHeap
|
||||
*/
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import static gc.testlibrary.Allocation.blackHole;
|
||||
|
||||
public class TestSmallHeap {
|
||||
public static void main(String[] args) throws Exception {
|
||||
@ -45,10 +46,10 @@ public class TestSmallHeap {
|
||||
System.out.println("Max Capacity " + maxCapacity + " bytes");
|
||||
|
||||
// Allocate byte arrays of increasing length, so that
|
||||
// all allocaion paths (small/medium/large) are tested.
|
||||
// all allocation paths (small/medium/large) are tested.
|
||||
for (int length = 16; length <= maxCapacity / 16; length *= 2) {
|
||||
System.out.println("Allocating " + length + " bytes");
|
||||
Reference.reachabilityFence(new byte[length]);
|
||||
blackHole(new byte[length]);
|
||||
}
|
||||
|
||||
System.out.println("Success");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user