Professional Documents
Culture Documents
jvmls2015 Riggs 2637905
jvmls2015 Riggs 2637905
Roger Riggs
Consulting Member of Technical Staff
Java Products Group
August 10, 2015
ResourceContext getThreadContext();
ResourceContext getThreadContext(Thread thread);
ResourceRequest getResourceRequest(ResourceType type);
ResourceContext getUnassignedContext();
ResourceContext getTotalsContext();
if (approved > 0) {
// Accumulate only the amount allocated
allocated.getAndAdd(approved);
}
return approved;
}
private final AtomicLong value;
private final AtomicLong allocated;
NotifyingMeter freadMeter =
NotifyingMeter.create(ResourceType.FILE_READ, Example::monitorApprover);
rc1.addResourceMeter(freadMeter);
rc1.bindThreadContext();
// Consume resources
run.run();
} // AutoCloseable
}
@InstrumentationMethod
public void write(byte b[]) throws IOException {
if (b == null) {
write(b);
return; // never gets here ...
}
ResourceContext rc = SimpleResourceContext.getThreadContext(Thread.currentThread());
ResourceRequest ra = rc.getResourceRequest(ResourceType.FILE_WRITE);
ResourceId id = ResourceIdImpl.of(path);
int numBytesWritten = 0;
try {
write(b);
numBytesWritten = len; // if no exception assume all bytes written
} finally {
// Return any unwritten bytes
ra.request(-(approved - numBytesWritten), id);
}
}
}
• Credits
– Stefan Johansson – Hotspot GC
– John Coomes – Hotspot GC
– Staffan Larson – JVMTI and Instrumentation Template
– Brian Burkhalter – I/O instrumentation
– Charlie Hunt – Performance
– WLS Team for motivation and requirements
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 29