Search in sources :

Example 6 with ArrayKlass

use of com.oracle.truffle.espresso.impl.ArrayKlass in project graal by oracle.

the class BytecodeNode method allocateMultiArray.

// endregion Class/Method/Field resolution
// region Instance/array allocation
@ExplodeLoop
private int allocateMultiArray(VirtualFrame frame, int top, Klass klass, int allocatedDimensions) {
    assert klass.isArray();
    CompilerAsserts.partialEvaluationConstant(allocatedDimensions);
    CompilerAsserts.partialEvaluationConstant(klass);
    int[] dimensions = new int[allocatedDimensions];
    for (int i = 0; i < allocatedDimensions; ++i) {
        dimensions[i] = popInt(frame, top - allocatedDimensions + i);
    }
    putObject(frame, top - allocatedDimensions, getInterpreterToVM().newMultiArray(((ArrayKlass) klass).getComponentType(), dimensions));
    // Does not include the created (pushed) array.
    return -allocatedDimensions;
}
Also used : ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 7 with ArrayKlass

use of com.oracle.truffle.espresso.impl.ArrayKlass in project graal by oracle.

the class Target_sun_misc_Unsafe method arrayBaseOffset.

/**
 * Report the offset of the first element in the storage allocation of a given array class. If
 * {@link #arrayIndexScale} returns a non-zero value for the same class, you may use that scale
 * factor, together with this base offset, to form new offsets to access elements of arrays of
 * the given class.
 *
 * @see #getInt
 * @see #putInt
 */
@Substitution(hasReceiver = true, nameProvider = SharedUnsafeAppend0.class)
public static int arrayBaseOffset(@SuppressWarnings("unused") @JavaType(Unsafe.class) StaticObject self, @JavaType(Class.class) StaticObject clazz, @Inject Meta meta) {
    Unsafe unsafe = UnsafeAccess.getIfAllowed(meta);
    Klass klass = clazz.getMirrorKlass();
    assert klass.isArray();
    if (((ArrayKlass) klass).getComponentType().isPrimitive()) {
        Class<?> hostPrimitive = ((ArrayKlass) klass).getComponentType().getJavaKind().toJavaClass();
        return unsafe.arrayBaseOffset(Array.newInstance(hostPrimitive, 0).getClass());
    } else {
        // Just a reference type.
        return unsafe.arrayBaseOffset(Object[].class);
    }
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) Unsafe(sun.misc.Unsafe) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject)

Aggregations

ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)7 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)5 Klass (com.oracle.truffle.espresso.impl.Klass)4 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)4 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 Unsafe (sun.misc.Unsafe)2 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)1 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)1 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)1 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)1 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)1