use of com.oracle.truffle.espresso.jni.RawBuffer in project graal by oracle.
the class AgentLibraries method initialize.
void initialize() {
Object ret;
getVM().getJvmti().enterPhase(JvmtiPhase.ONLOAD);
for (AgentLibrary agent : agents) {
TruffleObject onLoad = lookupOnLoad(agent);
if (onLoad == null) {
throw context.abort("Unable to locate " + AGENT_ONLOAD + " in agent " + agent.name);
}
try (RawBuffer optionBuffer = RawBuffer.getNativeString(agent.options)) {
ret = interop.execute(onLoad, context.getVM().getJavaVM(), optionBuffer.pointer(), RawPointer.nullInstance());
assert interop.fitsInInt(ret);
if (interop.asInt(ret) != JNI_OK) {
throw context.abort(AGENT_ONLOAD + " call for agent " + agent.name + " returned with error: " + interop.asInt(ret));
}
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
throw EspressoError.shouldNotReachHere(e);
}
}
getVM().getJvmti().enterPhase(JvmtiPhase.PRIMORDIAL);
}
use of com.oracle.truffle.espresso.jni.RawBuffer in project graal by oracle.
the class JImageLibrary method findLocation.
private long findLocation(TruffleObject jimage, TruffleObject sizePtr, String name) {
try (RawBuffer nameBuffer = RawBuffer.getNativeString(name)) {
TruffleObject namePtr = nameBuffer.pointer();
long location = (long) execute(findResource, jimage, emptyStringBuffer.pointer(), versionBuffer.pointer(), namePtr, sizePtr);
if (location != 0) {
// found.
return location;
}
String pkg = packageFromName(name);
if (pkg == null) {
return 0;
}
if (!getContext().modulesInitialized()) {
location = (long) execute(findResource, jimage, javaBaseBuffer.pointer(), versionBuffer.pointer(), namePtr, sizePtr);
if (location != 0 || !getContext().metaInitialized()) {
// finding certain classes in java.base (/ex: sun/misc/Unsafe).
return location;
}
TruffleObject moduleName;
try (RawBuffer pkgBuffer = RawBuffer.getNativeString(pkg)) {
moduleName = (TruffleObject) execute(packageToModule, jimage, pkgBuffer.pointer());
}
if (uncached.isNull(moduleName)) {
return 0;
}
return (long) execute(findResource, jimage, moduleName, versionBuffer.pointer(), namePtr, sizePtr);
} else {
Symbol<Name> pkgSymbol = getNames().lookup(pkg);
if (pkgSymbol == null) {
return 0;
}
PackageEntry pkgEntry = getRegistries().getBootClassRegistry().packages().lookup(pkgSymbol);
if (pkgEntry == null) {
return 0;
}
Symbol<Name> moduleName = pkgEntry.module().getName();
if (moduleName == Name.java_base) {
return (long) execute(findResource, jimage, javaBaseBuffer.pointer(), versionBuffer.pointer(), namePtr, sizePtr);
} else {
String nameAsString = moduleName == null ? "" : moduleName.toString();
try (RawBuffer moduleNameBuffer = RawBuffer.getNativeString(nameAsString)) {
return (long) execute(findResource, jimage, moduleNameBuffer.pointer(), versionBuffer.pointer(), namePtr, sizePtr);
}
}
}
}
}
Aggregations