Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport][22.3] Fallback from PosixPerfMemoryProvider to CHeapPerfMemoryProvider. #5392

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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