Skip to content

Commit 00c37bf

Browse files
author
Christian Wimmer
committed
Remove StringAccess
1 parent e4a1f23 commit 00c37bf

File tree

2 files changed

+17
-47
lines changed

2 files changed

+17
-47
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import java.io.File;
2828
import java.io.PrintWriter;
29+
import java.lang.invoke.MethodHandles;
30+
import java.lang.invoke.VarHandle;
2931
import java.lang.management.GarbageCollectorMXBean;
3032
import java.lang.management.ManagementFactory;
3133
import java.lang.management.OperatingSystemMXBean;
@@ -441,14 +443,28 @@ private static Map<String, Long> calculateCodeBreakdown(Collection<CompileTask>
441443
return classNameToCodeSize;
442444
}
443445

446+
private static final VarHandle STRING_VALUE;
447+
static {
448+
try {
449+
MethodHandles.Lookup privateLookup = MethodHandles.privateLookupIn(String.class, MethodHandles.lookup());
450+
STRING_VALUE = privateLookup.unreflectVarHandle(String.class.getDeclaredField("value"));
451+
} catch (ReflectiveOperationException e) {
452+
throw new ExceptionInInitializerError(e);
453+
}
454+
}
455+
456+
private static int getInternalByteArrayLength(String string) {
457+
return ((byte[]) STRING_VALUE.get(string)).length;
458+
}
459+
444460
private Map<String, Long> calculateHeapBreakdown(Collection<ObjectInfo> heapObjects) {
445461
Map<String, Long> classNameToSize = new HashMap<>();
446462
long stringByteLength = 0;
447463
for (ObjectInfo o : heapObjects) {
448464
classNameToSize.merge(o.getClazz().toJavaName(true), o.getSize(), Long::sum);
449465
Object javaObject = o.getObject();
450466
if (javaObject instanceof String) {
451-
stringByteLength += StringAccess.getInternalByteArrayLength((String) javaObject);
467+
stringByteLength += getInternalByteArrayLength((String) javaObject);
452468
}
453469
}
454470

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/StringAccess.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)