36 * First of all the test checks that the maximum amount of memory that
37 * the Java virtual machine will attempt to use (Runtime.maxMemory()) is
38 * greater than 4G. If that value is less than 4G, the test passes, otherwise
39 * it starts testing.
40 * A number of threads is started. That number is set in *.cfg file or is
41 * calculated by the test itself based on the machine (see
42 * nsk.share.gc.Algorithms.getThreadsCount() method).
43 * Each thread creates 9 arrays - one of each of the following types: byte,
44 * short, char, int, long, boolean, double, float, Object. All arrays have
45 * the same size, and that size is calculated so that all threads together are
46 * supposed to eat about 1.3G of the heap (30% of 4G).
47 *
48 * @library /vmTestbase
49 * /test/lib
50 * @run driver jdk.test.lib.FileInstaller . .
51 * @run main/othervm -XX:-UseGCOverheadLimit gc.huge.quicklook.largeheap.Access.access
52 */
53
54 package gc.huge.quicklook.largeheap.Access;
55
56 import java.util.concurrent.ThreadLocalRandom;
57 import java.util.ArrayList;
58 import nsk.share.TestFailure;
59 import nsk.share.gc.*;
60
61 public class access extends ThreadedGCTest {
62
63 // The test should fill just about 30% of 4G range (32-bit address range)
64 final static double PART_OF_HEAP = 0.3;
65 final static long GIGOBYTE = 1024 * 1024 * 1024;
66 // Approximate number of bytes for one element of each tested type
67 // (byte, short, char, int, long, double, float, Object)
68 final static long TYPES_SIZE =
69 Memory.getByteSize()
70 + Memory.getShortSize()
71 + Memory.getIntSize()
72 + Memory.getCharSize()
73 + Memory.getLongSize()
74 + Memory.getDoubleSize()
75 + Memory.getFloatSize();
76 //+ Memory.getBooleanSize()
77 //+ Memory.getReferenceObjectSize();
78 private final static int STORAGE_SIZE_DIM1 = 65536;
79 private final static int STORAGE_SIZE_DIM2 = (int) (4 * GIGOBYTE / Memory.getLongSize() / STORAGE_SIZE_DIM1);
148 return;
149 }
150 }
151 for (Object obj : list) {
152 // check hashcode just to avoid optimization
153 if (obj.hashCode() == -1) {
154 throw new TestFailure("Unexpected hashcode");
155 }
156 }
157 }
158 } finally {
159 list.clear();
160 }
161 }
162 }
163
164 class MainWorker implements Runnable {
165
166 @Override
167 public void run() {
168 synchronized (lock) {
169 for (int i = 0; i < STORAGE_SIZE_DIM1; i++) {
170 if (!getExecutionController().continueExecution()) {
171 log.debug("Test run out of time before 4G were allocated");
172 lock.notifyAll();
173 return;
174 }
175 storage[i] = new long[STORAGE_SIZE_DIM2];
176 }
177 log.debug("The 4G are allocated, starting to test");
178 is4GAllocated = true;
179 lock.notifyAll();
180 }
181 ThreadLocalRandom random = ThreadLocalRandom.current();
182 while (getExecutionController().continueExecution()) {
183 int i = random.nextInt(STORAGE_SIZE_DIM1);
184 int j = random.nextInt(STORAGE_SIZE_DIM2);
185 long value = random.nextLong(Long.MAX_VALUE);
186 storage[i][j] = value;
187 if (storage[i][j] != value) {
188 throw new TestFailure("The value = "
189 + storage[i][j] + " when expected ="
190 + value);
191 }
192 }
193
194 }
195 }
196
197 @Override
198 public void run() {
199 if (testConditions()) {
200 super.run();
201 }
202 }
203
204 @Override
205 protected Runnable createRunnable(int i) {
|
36 * First of all the test checks that the maximum amount of memory that
37 * the Java virtual machine will attempt to use (Runtime.maxMemory()) is
38 * greater than 4G. If that value is less than 4G, the test passes, otherwise
39 * it starts testing.
40 * A number of threads is started. That number is set in *.cfg file or is
41 * calculated by the test itself based on the machine (see
42 * nsk.share.gc.Algorithms.getThreadsCount() method).
43 * Each thread creates 9 arrays - one of each of the following types: byte,
44 * short, char, int, long, boolean, double, float, Object. All arrays have
45 * the same size, and that size is calculated so that all threads together are
46 * supposed to eat about 1.3G of the heap (30% of 4G).
47 *
48 * @library /vmTestbase
49 * /test/lib
50 * @run driver jdk.test.lib.FileInstaller . .
51 * @run main/othervm -XX:-UseGCOverheadLimit gc.huge.quicklook.largeheap.Access.access
52 */
53
54 package gc.huge.quicklook.largeheap.Access;
55
56 import java.util.ArrayList;
57 import nsk.share.TestFailure;
58 import nsk.share.gc.*;
59 import nsk.share.test.LocalRandom;
60
61 public class access extends ThreadedGCTest {
62
63 // The test should fill just about 30% of 4G range (32-bit address range)
64 final static double PART_OF_HEAP = 0.3;
65 final static long GIGOBYTE = 1024 * 1024 * 1024;
66 // Approximate number of bytes for one element of each tested type
67 // (byte, short, char, int, long, double, float, Object)
68 final static long TYPES_SIZE =
69 Memory.getByteSize()
70 + Memory.getShortSize()
71 + Memory.getIntSize()
72 + Memory.getCharSize()
73 + Memory.getLongSize()
74 + Memory.getDoubleSize()
75 + Memory.getFloatSize();
76 //+ Memory.getBooleanSize()
77 //+ Memory.getReferenceObjectSize();
78 private final static int STORAGE_SIZE_DIM1 = 65536;
79 private final static int STORAGE_SIZE_DIM2 = (int) (4 * GIGOBYTE / Memory.getLongSize() / STORAGE_SIZE_DIM1);
148 return;
149 }
150 }
151 for (Object obj : list) {
152 // check hashcode just to avoid optimization
153 if (obj.hashCode() == -1) {
154 throw new TestFailure("Unexpected hashcode");
155 }
156 }
157 }
158 } finally {
159 list.clear();
160 }
161 }
162 }
163
164 class MainWorker implements Runnable {
165
166 @Override
167 public void run() {
168 // ensure LocalRandom is loaded and has enough memory
169 LocalRandom.init();
170 synchronized (lock) {
171 for (int i = 0; i < STORAGE_SIZE_DIM1; i++) {
172 if (!getExecutionController().continueExecution()) {
173 log.debug("Test run out of time before 4G were allocated");
174 lock.notifyAll();
175 return;
176 }
177 storage[i] = new long[STORAGE_SIZE_DIM2];
178 }
179 log.debug("The 4G are allocated, starting to test");
180 is4GAllocated = true;
181 lock.notifyAll();
182 }
183 while (getExecutionController().continueExecution()) {
184 int i = LocalRandom.nextInt(STORAGE_SIZE_DIM1);
185 int j = LocalRandom.nextInt(STORAGE_SIZE_DIM2);
186 long value = LocalRandom.nextLong();
187 storage[i][j] = value;
188 if (storage[i][j] != value) {
189 throw new TestFailure("The value = "
190 + storage[i][j] + " when expected ="
191 + value);
192 }
193 }
194
195 }
196 }
197
198 @Override
199 public void run() {
200 if (testConditions()) {
201 super.run();
202 }
203 }
204
205 @Override
206 protected Runnable createRunnable(int i) {
|