Search in sources :

Example 16 with Type

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

the class BytecodeNode method popBasicArgumentsWithArray.

// Effort to prevent double copies. Erases sub-word primitive types.
@ExplodeLoop
public static Object[] popBasicArgumentsWithArray(VirtualFrame frame, int top, final Symbol<Type>[] signature, Object[] args, final int argCount, int start) {
    // Use basic types
    CompilerAsserts.partialEvaluationConstant(argCount);
    CompilerAsserts.partialEvaluationConstant(signature);
    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)) {
                // fall through
                case 'Z':
                // fall through
                case 'B':
                // fall through
                case 'S':
                // fall through
                case 'C':
                case 'I':
                    args[i + start] = popInt(frame, argAt);
                    break;
                case 'F':
                    args[i + start] = popFloat(frame, argAt);
                    break;
                case 'J':
                    args[i + start] = popLong(frame, argAt);
                    --argAt;
                    break;
                case 'D':
                    args[i + start] = popDouble(frame, argAt);
                    --argAt;
                    break;
                default:
                    CompilerDirectives.transferToInterpreter();
                    throw EspressoError.shouldNotReachHere();
            }
        // @formatter:on
        } else {
            args[i + start] = popObject(frame, argAt);
        }
        --argAt;
    }
    return args;
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 17 with Type

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

the class JniEnv method GetStaticFieldID.

/**
 * <h3>jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig);
 * </h3>
 * <p>
 * Returns the field ID for a static field of a class. The field is specified by its name and
 * signature. The GetStatic<type>Field and SetStatic<type>Field families of accessor functions
 * use field IDs to retrieve static fields.
 * <p>
 * GetStaticFieldID() causes an uninitialized class to be initialized.
 *
 * @param clazz a Java class object.
 * @param namePtr the static 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 specified static field cannot be found.
 * @throws NoSuchFieldError if the specified static 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 GetStaticFieldID(@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;
    Field field = null;
    Symbol<Name> fieldName = getNames().lookup(name);
    if (fieldName != null) {
        Symbol<Type> fieldType = getTypes().lookup(type);
        if (fieldType != null) {
            Klass klass = clazz.getMirrorKlass();
            klass.safeInitialize();
            // Lookup only if name and type are known symbols.
            field = klass.lookupField(fieldName, fieldType, Klass.LookupMode.STATIC_ONLY);
            assert field == null || field.getType().equals(fieldType);
        }
    }
    if (field == null || !field.isStatic()) {
        Meta meta = getMeta();
        throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchFieldError, name);
    }
    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 18 with Type

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

the class ClassRegistry method defineKlass.

@SuppressWarnings("try")
public ObjectKlass defineKlass(Symbol<Type> typeOrNull, final byte[] bytes, ClassDefinitionInfo info) {
    Meta meta = getMeta();
    ParserKlass parserKlass;
    try (DebugCloseable parse = KLASS_PARSE.scope(getContext().getTimers())) {
        parserKlass = getParserKlass(bytes, typeOrNull, info);
    }
    Symbol<Type> type = typeOrNull == null ? parserKlass.getType() : typeOrNull;
    if (info.addedToRegistry()) {
        Klass maybeLoaded = findLoadedKlass(type);
        if (maybeLoaded != null) {
            throw meta.throwExceptionWithMessage(meta.java_lang_LinkageError, "Class " + type + " already defined");
        }
    }
    Symbol<Type> superKlassType = parserKlass.getSuperKlass();
    ObjectKlass klass = createKlass(meta, parserKlass, type, superKlassType, info);
    if (info.addedToRegistry()) {
        registerKlass(klass, type);
    } else if (info.isStrongHidden()) {
        registerStrongHiddenClass(klass);
    }
    return klass;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable)

Example 19 with Type

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

the class MethodVerifier method verifyPutField.

private void verifyPutField(int bci, OperandStack stack, int curOpcode) {
    // Check CP validity
    PoolConstant pc = poolAt(code.readCPI(bci));
    verifyGuarantee(pc.tag() == ConstantPool.Tag.FIELD_REF, "Invalid CP constant for PUTFIELD: " + pc.toString());
    pc.validate(pool);
    // Obtain field info
    FieldRefConstant frc = (FieldRefConstant) pc;
    assert Validation.validFieldDescriptor(frc.getType(pool));
    Symbol<Type> fieldDesc = frc.getType(pool);
    Operand toPut = stack.pop(kindToOperand(fieldDesc));
    checkInit(toPut);
    if (curOpcode == PUTFIELD) {
        // Pop and check verifier
        assert Validation.validClassNameEntry(frc.getHolderKlassName(pool));
        Symbol<Type> fieldHolderType = getTypes().fromName(frc.getHolderKlassName(pool));
        Operand fieldHolder = kindToOperand(fieldHolderType);
        Operand receiver = checkInitAccess(stack.popRef(fieldHolder), fieldHolder);
        verifyGuarantee(!receiver.isArrayType(), "Trying to access field of an array type: " + receiver);
        if (!receiver.isUninitThis()) {
            checkProtectedMember(receiver, fieldHolderType, frc, false);
        }
    }
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) FieldRefConstant(com.oracle.truffle.espresso.classfile.constantpool.FieldRefConstant) PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant)

Example 20 with Type

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

the class MethodVerifier method getTypeFromPool.

private Symbol<Type> getTypeFromPool(int c, String s) {
    PoolConstant pc = poolAt(c);
    verifyGuarantee(pc.tag() == CLASS, s + pc.toString());
    pc.validate(pool);
    ClassConstant cc = (ClassConstant) pc;
    assert Validation.validClassNameEntry(cc.getName(pool));
    Symbol<Type> type = getTypes().fromName(cc.getName(pool));
    return type;
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant) ClassConstant(com.oracle.truffle.espresso.classfile.constantpool.ClassConstant)

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