From 3922a521b957a0acac87b1369e2dd8d277647ee7 Mon Sep 17 00:00:00 2001 From: Peter Hofer Date: Thu, 29 Sep 2022 14:18:06 +0200 Subject: [PATCH] Fallback from PosixPerfMemoryProvider to CHeapPerfMemoryProvider. (cherry picked from commit 62432ef3b318bf4eae3c50d3e612cca8208bd988) --- .../oracle/svm/core/jvmstat/PerfMemory.java | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfMemory.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfMemory.java index ba2e8eaf5f59..b2ed521f2df7 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfMemory.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfMemory.java @@ -71,18 +71,10 @@ public PerfMemory() { } public boolean initialize() { - PerfMemoryProvider m = getPerfMemoryProvider(); - ByteBuffer b = m.create(); - if (b == null || b.capacity() < PerfMemoryPrologue.getPrologueSize()) { + if (!createBuffer()) { return false; } - memoryProvider = m; - buffer = b; - capacity = b.capacity(); - rawMemory = WordFactory.pointer(SubstrateUtil.cast(b, Target_java_nio_Buffer.class).address); - assert verifyRawMemoryAccess(); - PerfMemoryPrologue.initialize(rawMemory, ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN)); used = PerfMemoryPrologue.getPrologueSize(); @@ -90,16 +82,38 @@ public boolean initialize() { return true; } - private static PerfMemoryProvider getPerfMemoryProvider() { + private boolean createBuffer() { + PerfMemoryProvider m = null; + ByteBuffer b = null; if (PerfDataMemoryMappedFile.getValue() && tryAcquirePerfDataFile()) { - return ImageSingletons.lookup(PerfMemoryProvider.class); + m = ImageSingletons.lookup(PerfMemoryProvider.class); + b = m.create(); + if (b == null) { + releasePerfDataFile(); + } } - /* - * Memory mapped file support is disabled or another isolate already owns the perf data - * file. Either way, this isolate needs to use C heap memory instead. - */ - return new CHeapPerfMemoryProvider(); + if (b == null) { + /* + * Memory mapped file support is disabled, another isolate already owns the perf data + * file, or the file or buffer could not be created. Either way, this isolate needs to + * use C heap memory instead. + */ + m = new CHeapPerfMemoryProvider(); + b = m.create(); + } + + if (b == null || b.capacity() < PerfMemoryPrologue.getPrologueSize()) { + return false; + } + + memoryProvider = m; + buffer = b; + capacity = b.capacity(); + rawMemory = WordFactory.pointer(SubstrateUtil.cast(b, Target_java_nio_Buffer.class).address); + assert verifyRawMemoryAccess(); + + return true; } private boolean verifyRawMemoryAccess() {