Search in sources :

Example 1 with RawBuffer

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);
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) RawBuffer(com.oracle.truffle.espresso.jni.RawBuffer) ArityException(com.oracle.truffle.api.interop.ArityException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 2 with RawBuffer

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);
                }
            }
        }
    }
}
Also used : PackageEntry(com.oracle.truffle.espresso.impl.PackageTable.PackageEntry) RawBuffer(com.oracle.truffle.espresso.jni.RawBuffer) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Aggregations

TruffleObject (com.oracle.truffle.api.interop.TruffleObject)2 RawBuffer (com.oracle.truffle.espresso.jni.RawBuffer)2 ArityException (com.oracle.truffle.api.interop.ArityException)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)1 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)1 PackageEntry (com.oracle.truffle.espresso.impl.PackageTable.PackageEntry)1