< prev index next > test/hotspot/jtreg/vmTestbase/nsk/share/gc/Memory.java
Print this page
/*
! * Copyright (c) 2005, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
/*
! * Copyright (c) 2005, 2026, 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.
import nsk.share.test.LocalRandom;
import java.io.PrintStream;
import nsk.share.gc.gp.GarbageProducer;
import nsk.share.gc.tree.*;
- import nsk.share.gc.gp.MemoryStrategy;
import nsk.share.log.Log;
/**
* Different utility methods to work with memory objects.
*/
public final class Memory {
private static int bits = 0;
private static int referenceSize = 0;
private static int objectExtraSize = 0;
private Memory() {
}
private static int getBits() {
if (bits == 0)
import nsk.share.test.LocalRandom;
import java.io.PrintStream;
import nsk.share.gc.gp.GarbageProducer;
import nsk.share.gc.tree.*;
import nsk.share.log.Log;
/**
* Different utility methods to work with memory objects.
*/
public final class Memory {
private static int bits = 0;
private static int referenceSize = 0;
private static int objectExtraSize = 0;
+ private static final boolean previewEnabled =
+ System.getProperty("test.java.opts", "").contains("--enable-preview") ||
+ System.getProperty("test.vm.opts", "").contains("--enable-preview");
+
+
private Memory() {
}
private static int getBits() {
if (bits == 0)
if (referenceSize == 0)
referenceSize = (getBits() == 64) ? 8 : 4;
return referenceSize;
}
+ public static boolean isPreviewEnabled() {
+ return previewEnabled;
+ }
+
+ public static boolean isValhallaEnabled() {
+ return previewEnabled;
+ }
+
/**
* Get size of primitive type int.
*/
public static int getIntSize() {
return 4;
public static int getDoubleSize() {
return 8;
}
/**
+ * Get size of Integer element in Integer array.
+ * If array is not flattened, the only reference size is returned, the referred values
+ * should be added manually in references are not null.
+ */
+ public static int getIntegerArrayElementSize() {
+
+ if (!Memory.isValhallaEnabled()) {
+ return getReferenceSize();
+ }
+ return 8;
+ }
+
+ /**
+ * Get size of Byte element in Byte array.
+ * If array is not flattened, the only reference size is returned, the referred values
+ * should be added manually in references are not null.
+ */
+ public static int getByteArrayElementSize() {
+
+ if (!Memory.isValhallaEnabled()) {
+ return getReferenceSize();
+ }
+ return 2;
+ }
+
+ /**
+ * Get size of Boolean element in Boolean array.
+ * If array is not flattened, the only reference size is returned, the referred values
+ * should be added manually in references are not null.
+ */
+ public static int getBooleanArrayElementSize() {
+ if (!Memory.isValhallaEnabled()) {
+ return getReferenceSize();
+ }
+ return 2;
+ }
+
+
+
+ /**
* Get how many extra bytes an object occupies in the heap
* compared to sum of it's fields.
*
* TODO: somehow determine the real value
*/
* @param objectSize size of each object in array
* @return length of array
*/
public static int getArrayLength(long memory, long objectSize) {
int arrayExtraSize = getArrayExtraSize();
! return (int) Math.min((memory - arrayExtraSize) / objectSize,
Integer.MAX_VALUE);
}
/**
* Get an approximate size of array of given length and object size.
*
* @param objectSize size of each object in array
* @return length of array
*/
public static int getArrayLength(long memory, long objectSize) {
int arrayExtraSize = getArrayExtraSize();
! int length = (int) Math.min((memory - arrayExtraSize) / objectSize,
Integer.MAX_VALUE);
+ return Math.max(length, 0);
}
/**
* Get an approximate size of array of given length and object size.
*
< prev index next >