use of com.oracle.truffle.espresso.meta.JavaKind in project graal by oracle.
the class JniEnv method GetPrimitiveArrayCritical.
@JniImpl
@Pointer
public TruffleObject GetPrimitiveArrayCritical(@JavaType(Object.class) StaticObject object, @Pointer TruffleObject isCopyPtr) {
if (!getUncached().isNull(isCopyPtr)) {
ByteBuffer isCopyBuf = NativeUtils.directByteBuffer(isCopyPtr, 1);
// Always copy since pinning is not supported.
isCopyBuf.put((byte) 1);
}
StaticObject array = object;
StaticObject clazz = GetObjectClass(array);
JavaKind componentKind = ((ArrayKlass) clazz.getMirrorKlass()).getComponentType().getJavaKind();
assert componentKind.isPrimitive();
int length = GetArrayLength(array);
ByteBuffer region = allocateDirect(length, componentKind);
@Pointer TruffleObject addressPtr = NativeUtils.byteBufferPointer(region);
// @formatter:off
switch(componentKind) {
case Boolean:
GetBooleanArrayRegion(array, 0, length, addressPtr);
break;
case Byte:
GetByteArrayRegion(array, 0, length, addressPtr);
break;
case Short:
GetShortArrayRegion(array, 0, length, addressPtr);
break;
case Char:
GetCharArrayRegion(array, 0, length, addressPtr);
break;
case Int:
GetIntArrayRegion(array, 0, length, addressPtr);
break;
case Float:
GetFloatArrayRegion(array, 0, length, addressPtr);
break;
case Long:
GetLongArrayRegion(array, 0, length, addressPtr);
break;
case Double:
GetDoubleArrayRegion(array, 0, length, addressPtr);
break;
// fall through
case Object:
// fall through
case Void:
// fall through
case Illegal:
default:
throw EspressoError.shouldNotReachHere();
}
return addressPtr;
}
use of com.oracle.truffle.espresso.meta.JavaKind in project graal by oracle.
the class JniEnv method popVarArgs.
public Object[] popVarArgs(@Pointer TruffleObject varargsPtr, final Symbol<Type>[] signature) {
VarArgs varargs = new VarArgsImpl(varargsPtr);
int paramCount = Signatures.parameterCount(signature, false);
Object[] args = new Object[paramCount];
for (int i = 0; i < paramCount; ++i) {
JavaKind kind = Signatures.parameterKind(signature, i);
// @formatter:off
switch(kind) {
case Boolean:
args[i] = varargs.popBoolean();
break;
case Byte:
args[i] = varargs.popByte();
break;
case Short:
args[i] = varargs.popShort();
break;
case Char:
args[i] = varargs.popChar();
break;
case Int:
args[i] = varargs.popInt();
break;
case Float:
args[i] = varargs.popFloat();
break;
case Long:
args[i] = varargs.popLong();
break;
case Double:
args[i] = varargs.popDouble();
break;
case Object:
args[i] = varargs.popObject();
break;
default:
CompilerDirectives.transferToInterpreter();
throw EspressoError.shouldNotReachHere("invalid parameter kind: " + kind);
}
// @formatter:on
}
return args;
}
use of com.oracle.truffle.espresso.meta.JavaKind in project graal by oracle.
the class JniEnv method ReleasePrimitiveArrayElements.
// endregion Get*ArrayElements
// region Release*ArrayElements
private void ReleasePrimitiveArrayElements(StaticObject object, @Pointer TruffleObject bufPtr, int mode) {
if (mode == 0 || mode == JNI_COMMIT) {
// Update array contents.
StaticObject array = object;
StaticObject clazz = GetObjectClass(array);
JavaKind componentKind = ((ArrayKlass) clazz.getMirrorKlass()).getComponentType().getJavaKind();
assert componentKind.isPrimitive();
int length = GetArrayLength(array);
// @formatter:off
switch(componentKind) {
case Boolean:
SetBooleanArrayRegion(array, 0, length, bufPtr);
break;
case Byte:
SetByteArrayRegion(array, 0, length, bufPtr);
break;
case Short:
SetShortArrayRegion(array, 0, length, bufPtr);
break;
case Char:
SetCharArrayRegion(array, 0, length, bufPtr);
break;
case Int:
SetIntArrayRegion(array, 0, length, bufPtr);
break;
case Float:
SetFloatArrayRegion(array, 0, length, bufPtr);
break;
case Long:
SetLongArrayRegion(array, 0, length, bufPtr);
break;
case Double:
SetDoubleArrayRegion(array, 0, length, bufPtr);
break;
default:
throw EspressoError.shouldNotReachHere();
}
// @formatter:on
}
if (mode == 0 || mode == JNI_ABORT) {
// Dispose copy.
releasePtr(bufPtr);
}
}
use of com.oracle.truffle.espresso.meta.JavaKind in project graal by oracle.
the class JniEnv method ReleasePrimitiveArrayCritical.
@JniImpl
public void ReleasePrimitiveArrayCritical(@JavaType(Object.class) StaticObject object, @Pointer TruffleObject carrayPtr, int mode) {
if (mode == 0 || mode == JNI_COMMIT) {
// Update array contents.
StaticObject array = object;
StaticObject clazz = GetObjectClass(array);
JavaKind componentKind = ((ArrayKlass) clazz.getMirrorKlass()).getComponentType().getJavaKind();
assert componentKind.isPrimitive();
int length = GetArrayLength(array);
// @formatter:off
switch(componentKind) {
case Boolean:
SetBooleanArrayRegion(array, 0, length, carrayPtr);
break;
case Byte:
SetByteArrayRegion(array, 0, length, carrayPtr);
break;
case Short:
SetShortArrayRegion(array, 0, length, carrayPtr);
break;
case Char:
SetCharArrayRegion(array, 0, length, carrayPtr);
break;
case Int:
SetIntArrayRegion(array, 0, length, carrayPtr);
break;
case Float:
SetFloatArrayRegion(array, 0, length, carrayPtr);
break;
case Long:
SetLongArrayRegion(array, 0, length, carrayPtr);
break;
case Double:
SetDoubleArrayRegion(array, 0, length, carrayPtr);
break;
default:
throw EspressoError.shouldNotReachHere();
}
// @formatter:on
}
if (mode == 0 || mode == JNI_ABORT) {
// Dispose copy.
releasePtr(carrayPtr);
}
}
use of com.oracle.truffle.espresso.meta.JavaKind in project graal by oracle.
the class ClassfileParser method parseField.
private ParserField parseField(boolean isInterface) {
int fieldFlags = stream.readU2();
int nameIndex = stream.readU2();
int typeIndex = stream.readU2();
pool.utf8At(nameIndex).validateFieldName();
final Symbol<Name> name = pool.symbolAt(nameIndex, "field name");
verifyFieldFlags(name, fieldFlags, isInterface);
final boolean isStatic = Modifier.isStatic(fieldFlags);
pool.utf8At(typeIndex).validateType(false);
Symbol<ModifiedUTF8> rawDescriptor = pool.symbolAt(typeIndex, "field descriptor");
final Symbol<Type> descriptor = Types.fromSymbol(rawDescriptor);
if (descriptor == null) {
throw ConstantPool.classFormatError("Invalid descriptor: " + rawDescriptor);
}
final int attributeCount = stream.readU2();
final Attribute[] fieldAttributes = spawnAttributesArray(attributeCount);
ConstantValueAttribute constantValue = null;
CommonAttributeParser commonAttributeParser = new CommonAttributeParser(InfoType.Field);
for (int i = 0; i < attributeCount; ++i) {
final int attributeNameIndex = stream.readU2();
final Symbol<Name> attributeName = pool.symbolAt(attributeNameIndex, "attribute name");
final int attributeSize = stream.readS4();
final int startPosition = stream.getPosition();
if (isStatic && attributeName.equals(Name.ConstantValue)) {
if (constantValue != null) {
throw ConstantPool.classFormatError("Duplicate ConstantValue attribute");
}
fieldAttributes[i] = constantValue = new ConstantValueAttribute(stream.readU2());
if (constantValue.getConstantValueIndex() == 0) {
throw ConstantPool.classFormatError("Invalid ConstantValue index");
}
} else if (attributeName.equals(Name.Synthetic)) {
fieldFlags |= ACC_SYNTHETIC;
fieldAttributes[i] = new Attribute(attributeName, null);
} else if (majorVersion >= JAVA_1_5_VERSION) {
Attribute attr = commonAttributeParser.parseCommonAttribute(attributeName, attributeSize);
// stream.skip(attributeSize);
fieldAttributes[i] = attr == null ? new Attribute(attributeName, stream.readByteArray(attributeSize)) : attr;
} else {
// stream.skip(attributeSize);
fieldAttributes[i] = new Attribute(attributeName, stream.readByteArray(attributeSize));
}
if (attributeSize != stream.getPosition() - startPosition) {
throw ConstantPool.classFormatError("Invalid attribute_length for " + attributeName + " attribute");
}
}
final JavaKind kind = Types.getJavaKind(descriptor);
if (kind == JavaKind.Void) {
throw ConstantPool.classFormatError("Fields cannot be of type void");
}
if (constantValue != null) {
Tag tag = pool.tagAt(constantValue.getConstantValueIndex());
boolean valid = false;
switch(kind) {
// fall through
case Boolean:
// fall through
case Byte:
// fall through
case Short:
// fall through
case Char:
case // fall through
Int:
valid = (tag == Tag.INTEGER);
break;
case Float:
valid = (tag == Tag.FLOAT);
break;
case Long:
valid = (tag == Tag.LONG);
break;
case Double:
valid = (tag == Tag.DOUBLE);
break;
case Object:
valid = (tag == Tag.STRING) && descriptor.equals(Type.java_lang_String);
break;
default:
{
throw ConstantPool.classFormatError("Cannot have ConstantValue for fields of type " + kind);
}
}
if (!valid) {
throw ConstantPool.classFormatError("ConstantValue attribute does not match field type");
}
}
return new ParserField(fieldFlags, name, descriptor, fieldAttributes);
}
Aggregations