Search in sources :

Example 1 with Type

use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.

the class BytecodeNode method popArguments.

@ExplodeLoop
public static Object[] popArguments(VirtualFrame frame, int top, boolean hasReceiver, final Symbol<Type>[] signature) {
    int argCount = Signatures.parameterCount(signature, false);
    int extraParam = hasReceiver ? 1 : 0;
    final Object[] args = new Object[argCount + extraParam];
    CompilerAsserts.partialEvaluationConstant(argCount);
    CompilerAsserts.partialEvaluationConstant(signature);
    CompilerAsserts.partialEvaluationConstant(hasReceiver);
    int argAt = top - 1;
    for (int i = argCount - 1; i >= 0; --i) {
        Symbol<Type> argType = Signatures.parameterType(signature, i);
        if (argType.length() == 1) {
            // @formatter:off
            switch(argType.byteAt(0)) {
                case 'Z':
                    args[i + extraParam] = (popInt(frame, argAt) != 0);
                    break;
                case 'B':
                    args[i + extraParam] = (byte) popInt(frame, argAt);
                    break;
                case 'S':
                    args[i + extraParam] = (short) popInt(frame, argAt);
                    break;
                case 'C':
                    args[i + extraParam] = (char) popInt(frame, argAt);
                    break;
                case 'I':
                    args[i + extraParam] = popInt(frame, argAt);
                    break;
                case 'F':
                    args[i + extraParam] = popFloat(frame, argAt);
                    break;
                case 'J':
                    args[i + extraParam] = popLong(frame, argAt);
                    --argAt;
                    break;
                case 'D':
                    args[i + extraParam] = popDouble(frame, argAt);
                    --argAt;
                    break;
                default:
                    CompilerDirectives.transferToInterpreter();
                    throw EspressoError.shouldNotReachHere();
            }
        // @formatter:on
        } else {
            args[i + extraParam] = popObject(frame, argAt);
        }
        --argAt;
    }
    if (hasReceiver) {
        args[0] = popObject(frame, argAt);
    }
    return args;
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 2 with Type

use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.

the class BytecodeNode method initArguments.

@ExplodeLoop
private void initArguments(VirtualFrame frame) {
    Object[] arguments = frame.getArguments();
    boolean hasReceiver = !getMethod().isStatic();
    int receiverSlot = hasReceiver ? 1 : 0;
    int curSlot = 0;
    if (hasReceiver) {
        assert StaticObject.notNull((StaticObject) arguments[0]) : "null receiver in init arguments !";
        StaticObject receiver = (StaticObject) arguments[0];
        setLocalObject(frame, curSlot, receiver);
        checkNoForeignObjectAssumption(receiver);
        curSlot += JavaKind.Object.getSlotCount();
    }
    Symbol<Type>[] methodSignature = getMethod().getParsedSignature();
    int argCount = Signatures.parameterCount(methodSignature, false);
    CompilerAsserts.partialEvaluationConstant(argCount);
    for (int i = 0; i < argCount; ++i) {
        Symbol<Type> argType = Signatures.parameterType(methodSignature, i);
        if (argType.length() == 1) {
            // @formatter:off
            switch(argType.byteAt(0)) {
                case 'Z':
                    setLocalInt(frame, curSlot, ((boolean) arguments[i + receiverSlot]) ? 1 : 0);
                    break;
                case 'B':
                    setLocalInt(frame, curSlot, ((byte) arguments[i + receiverSlot]));
                    break;
                case 'S':
                    setLocalInt(frame, curSlot, ((short) arguments[i + receiverSlot]));
                    break;
                case 'C':
                    setLocalInt(frame, curSlot, ((char) arguments[i + receiverSlot]));
                    break;
                case 'I':
                    setLocalInt(frame, curSlot, (int) arguments[i + receiverSlot]);
                    break;
                case 'F':
                    setLocalFloat(frame, curSlot, (float) arguments[i + receiverSlot]);
                    break;
                case 'J':
                    setLocalLong(frame, curSlot, (long) arguments[i + receiverSlot]);
                    ++curSlot;
                    break;
                case 'D':
                    setLocalDouble(frame, curSlot, (double) arguments[i + receiverSlot]);
                    ++curSlot;
                    break;
                default:
                    CompilerDirectives.transferToInterpreter();
                    throw EspressoError.shouldNotReachHere("unexpected kind");
            }
        // @formatter:on
        } else {
            // Reference type.
            StaticObject argument = (StaticObject) arguments[i + receiverSlot];
            setLocalObject(frame, curSlot, argument);
            checkNoForeignObjectAssumption(argument);
        }
        ++curSlot;
    }
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Symbol(com.oracle.truffle.espresso.descriptors.Symbol) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 3 with Type

use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.

the class JniEnv method RegisterNative.

// endregion DirectBuffers
// region Register/Unregister natives
@JniImpl
@TruffleBoundary
public int RegisterNative(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject methodNamePtr, @Pointer TruffleObject methodSignaturePtr, @Pointer TruffleObject closure) {
    String methodName = NativeUtils.interopPointerToString(methodNamePtr);
    String methodSignature = NativeUtils.interopPointerToString(methodSignaturePtr);
    assert methodName != null && methodSignature != null;
    Symbol<Name> name = getNames().lookup(methodName);
    Symbol<Signature> signature = getSignatures().lookupValidSignature(methodSignature);
    Meta meta = getMeta();
    if (name == null || signature == null) {
        setPendingException(Meta.initException(meta.java_lang_NoSuchMethodError));
        return JNI_ERR;
    }
    Method targetMethod = clazz.getMirrorKlass().lookupDeclaredMethod(name, signature);
    if (targetMethod != null && targetMethod.isNative()) {
        targetMethod.unregisterNative();
        getSubstitutions().removeRuntimeSubstitution(targetMethod);
    } else {
        setPendingException(Meta.initException(meta.java_lang_NoSuchMethodError));
        return JNI_ERR;
    }
    Substitutions.EspressoRootNodeFactory factory = null;
    // Lookup known VM methods to shortcut native boudaries.
    factory = lookupKnownVmMethods(closure, targetMethod);
    if (factory == null) {
        NativeSignature ns = Method.buildJniNativeSignature(targetMethod.getParsedSignature());
        final TruffleObject boundNative = getNativeAccess().bindSymbol(closure, ns);
        factory = createJniRootNodeFactory(() -> new NativeMethodNode(boundNative, targetMethod.getMethodVersion()), targetMethod);
    }
    Symbol<Type> classType = clazz.getMirrorKlass().getType();
    getSubstitutions().registerRuntimeSubstitution(classType, name, signature, factory, true);
    return JNI_OK;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) NativeSignature(com.oracle.truffle.espresso.ffi.NativeSignature) NativeType(com.oracle.truffle.espresso.ffi.NativeType) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) NativeSignature(com.oracle.truffle.espresso.ffi.NativeSignature) Signature(com.oracle.truffle.espresso.descriptors.Symbol.Signature) Substitutions(com.oracle.truffle.espresso.substitutions.Substitutions) NativeMethodNode(com.oracle.truffle.espresso.nodes.NativeMethodNode) IntrinsifiedNativeMethodNode(com.oracle.truffle.espresso.nodes.IntrinsifiedNativeMethodNode) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 4 with Type

use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.

the class JniEnv method GetFieldID.

// Checkstyle: stop method name check
// region Get*ID
/**
 * <h3>jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig);</h3>
 * <p>
 * Returns the field ID for an instance (nonstatic) field of a class. The field is specified by
 * its name and signature. The Get<type>Field and Set<type>Field families of accessor functions
 * use field IDs to retrieve object fields. GetFieldID() causes an uninitialized class to be
 * initialized. GetFieldID() cannot be used to obtain the length field of an array. Use
 * GetArrayLength() instead.
 *
 * @param clazz a Java class object.
 * @param namePtr the field name in a 0-terminated modified UTF-8 string.
 * @param typePtr the field signature in a 0-terminated modified UTF-8 string.
 * @return a field ID, or NULL if the operation fails.
 * @throws NoSuchFieldError: if the specified field cannot be found.
 * @throws ExceptionInInitializerError: if the class initializer fails due to an exception.
 * @throws OutOfMemoryError: if the system runs out of memory.
 */
@JniImpl
@Handle(Field.class)
public long GetFieldID(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject namePtr, @Pointer TruffleObject typePtr) {
    String name = NativeUtils.interopPointerToString(namePtr);
    String type = NativeUtils.interopPointerToString(typePtr);
    assert name != null && type != null;
    Klass klass = clazz.getMirrorKlass();
    Field field = null;
    Symbol<Name> fieldName = getNames().lookup(name);
    if (fieldName != null) {
        Symbol<Type> fieldType = getTypes().lookup(type);
        if (fieldType != null) {
            // Lookup only if name and type are known symbols.
            klass.safeInitialize();
            field = klass.lookupField(fieldName, fieldType);
            assert field == null || field.getType().equals(fieldType);
        }
    }
    if (field == null || field.isStatic()) {
        Meta meta = getMeta();
        throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchFieldError, name);
    }
    assert !field.isStatic();
    return fieldIds.handlify(field);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) Meta(com.oracle.truffle.espresso.meta.Meta) NativeType(com.oracle.truffle.espresso.ffi.NativeType) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 5 with Type

use of com.oracle.truffle.espresso.descriptors.Symbol.Type in project graal by oracle.

the class ClassfileParser method parseExceptionHandlerEntries.

private ExceptionHandler[] parseExceptionHandlerEntries() {
    int count = stream.readU2();
    if (count == 0) {
        return ExceptionHandler.EMPTY_ARRAY;
    }
    ExceptionHandler[] entries = new ExceptionHandler[count];
    for (int i = 0; i < count; i++) {
        int startPc = stream.readU2();
        int endPc = stream.readU2();
        int handlerPc = stream.readU2();
        int catchTypeIndex = stream.readU2();
        Symbol<Type> catchType = null;
        if (catchTypeIndex != 0) {
            catchType = context.getTypes().fromName(pool.classAt(catchTypeIndex).getName(pool));
        }
        entries[i] = new ExceptionHandler(startPc, endPc, handlerPc, catchTypeIndex, catchType);
    }
    return entries;
}
Also used : ExceptionHandler(com.oracle.truffle.espresso.meta.ExceptionHandler) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type)

Aggregations

Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)26 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)9 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)9 NativeType (com.oracle.truffle.espresso.ffi.NativeType)8 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)6 Meta (com.oracle.truffle.espresso.meta.Meta)6 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)6 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)5 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)5 Klass (com.oracle.truffle.espresso.impl.Klass)5 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)3 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)3 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)3 MethodRefConstant (com.oracle.truffle.espresso.classfile.constantpool.MethodRefConstant)3 PoolConstant (com.oracle.truffle.espresso.classfile.constantpool.PoolConstant)3 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)3 Signature (com.oracle.truffle.espresso.descriptors.Symbol.Signature)3 ParserField (com.oracle.truffle.espresso.impl.ParserField)3 DebugCloseable (com.oracle.truffle.espresso.perf.DebugCloseable)3 BootstrapMethodsAttribute (com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute)2