Skip to content

Commit

Permalink
Fallback from PosixPerfMemoryProvider to CHeapPerfMemoryProvider.
Browse files Browse the repository at this point in the history
(cherry picked from commit 62432ef)
  • Loading branch information
peter-hofer authored and galderz committed Nov 17, 2022
1 parent 2a0af49 commit 3922a52
Showing 1 changed file with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,49 @@ 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();
initialTime = System.nanoTime();
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() {
Expand Down

0 comments on commit 3922a52

Please sign in to comment.