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;
}
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;
}
}
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;
}
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);
}
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;
}
Aggregations