use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.
the class JniEnv method GetMethodID.
/**
* <h3>jmethodID GetMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig);</h3>
* <p>
* Returns the method ID for an instance (nonstatic) method of a class or interface. The method
* may be defined in one of the clazz’s superclasses and inherited by clazz. The method is
* determined by its name and signature.
* <p>
* GetMethodID() causes an uninitialized class to be initialized.
* <p>
* To obtain the method ID of a constructor, supply <init> as the method name and void (V) as
* the return type.
*
* @param clazz a Java class object.
* @param namePtr the method name in a 0-terminated modified UTF-8 string.
* @param signaturePtr the method signature in 0-terminated modified UTF-8 string.
* @return a method ID, or NULL if the specified method cannot be found.
* @throws NoSuchMethodError if the specified method 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(Method.class)
public long GetMethodID(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject namePtr, @Pointer TruffleObject signaturePtr) {
String name = NativeUtils.interopPointerToString(namePtr);
String signature = NativeUtils.interopPointerToString(signaturePtr);
assert name != null && signature != null;
Method method = null;
Symbol<Name> methodName = getNames().lookup(name);
if (methodName != null) {
Symbol<Signature> methodSignature = getSignatures().lookupValidSignature(signature);
if (methodSignature != null) {
Klass klass = clazz.getMirrorKlass();
klass.safeInitialize();
// Lookup only if name and type are known symbols.
method = klass.lookupMethod(methodName, methodSignature, klass);
}
}
if (method == null || method.isStatic()) {
Meta meta = getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, name);
}
return methodIds.handlify(method);
}
use of com.oracle.truffle.espresso.descriptors.Symbol.Name 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.Name 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.Name in project graal by oracle.
the class ClassfileParser method parseRecordComponentAttributes.
private Attribute[] parseRecordComponentAttributes() {
final int size = stream.readU2();
Attribute[] componentAttributes = new Attribute[size];
CommonAttributeParser commonAttributeParser = new CommonAttributeParser(InfoType.Record);
for (int j = 0; j < size; j++) {
final Symbol<Name> attributeName = pool.symbolAt(stream.readU2(), "attribute name");
final int attributeSize = stream.readS4();
Attribute attr = commonAttributeParser.parseCommonAttribute(attributeName, attributeSize);
componentAttributes[j] = attr == null ? new Attribute(attributeName, stream.readByteArray(attributeSize)) : attr;
}
return componentAttributes;
}
use of com.oracle.truffle.espresso.descriptors.Symbol.Name in project graal by oracle.
the class ClassfileParser method parseClassAttributes.
private Attribute[] parseClassAttributes() {
int attributeCount = stream.readU2();
if (attributeCount == 0) {
if (maxBootstrapMethodAttrIndex >= 0) {
throw ConstantPool.classFormatError("BootstrapMethods attribute is missing");
}
return Attribute.EMPTY_ARRAY;
}
SourceFileAttribute sourceFileName = null;
SourceDebugExtensionAttribute sourceDebugExtensionAttribute = null;
NestHostAttribute nestHost = null;
NestMembersAttribute nestMembers = null;
EnclosingMethodAttribute enclosingMethod = null;
BootstrapMethodsAttribute bootstrapMethods = null;
InnerClassesAttribute innerClasses = null;
PermittedSubclassesAttribute permittedSubclasses = null;
RecordAttribute record = null;
CommonAttributeParser commonAttributeParser = new CommonAttributeParser(InfoType.Class);
final Attribute[] classAttributes = spawnAttributesArray(attributeCount);
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 (attributeName.equals(Name.SourceFile)) {
if (sourceFileName != null) {
throw ConstantPool.classFormatError("Duplicate SourceFile attribute");
}
classAttributes[i] = sourceFileName = parseSourceFileAttribute(attributeName);
} else if (attributeName.equals(Name.SourceDebugExtension)) {
if (sourceDebugExtensionAttribute != null) {
throw ConstantPool.classFormatError("Duplicate SourceDebugExtension attribute");
}
classAttributes[i] = sourceDebugExtensionAttribute = parseSourceDebugExtensionAttribute(attributeName, attributeSize);
} else if (attributeName.equals(Name.Synthetic)) {
classFlags |= ACC_SYNTHETIC;
classAttributes[i] = new Attribute(attributeName, null);
} else if (attributeName.equals(Name.InnerClasses)) {
if (innerClasses != null) {
throw ConstantPool.classFormatError("Duplicate InnerClasses attribute");
}
classAttributes[i] = innerClasses = parseInnerClasses(attributeName);
} else if (majorVersion >= JAVA_1_5_VERSION) {
if (majorVersion >= JAVA_7_VERSION && attributeName.equals(Name.BootstrapMethods)) {
if (bootstrapMethods != null) {
throw ConstantPool.classFormatError("Duplicate BootstrapMethods attribute");
}
classAttributes[i] = bootstrapMethods = parseBootstrapMethods(attributeName);
} else if (attributeName.equals(Name.EnclosingMethod)) {
if (enclosingMethod != null) {
throw ConstantPool.classFormatError("Duplicate EnclosingMethod attribute");
}
classAttributes[i] = enclosingMethod = parseEnclosingMethodAttribute(attributeName);
} else if (majorVersion >= JAVA_11_VERSION && attributeName.equals(Name.NestHost)) {
if (nestHost != null) {
throw ConstantPool.classFormatError("Duplicate NestHost attribute");
}
if (nestMembers != null) {
throw ConstantPool.classFormatError("Classfile cannot have both a nest members and a nest host attribute.");
}
if (attributeSize != 2) {
throw ConstantPool.classFormatError("Attribute length of NestHost must be 2");
}
classAttributes[i] = nestHost = parseNestHostAttribute(attributeName);
} else if (majorVersion >= JAVA_11_VERSION && attributeName.equals(Name.NestMembers)) {
if (nestMembers != null) {
throw ConstantPool.classFormatError("Duplicate NestMembers attribute");
}
if (nestHost != null) {
throw ConstantPool.classFormatError("Classfile cannot have both a nest members and a nest host attribute.");
}
classAttributes[i] = nestMembers = parseNestMembers(attributeName);
} else if (majorVersion >= JAVA_14_VERSION && attributeName.equals(Name.Record)) {
if (record != null) {
throw ConstantPool.classFormatError("Duplicate Record attribute");
}
classAttributes[i] = record = parseRecord(attributeName);
} else if (majorVersion >= JAVA_17_VERSION && attributeName.equals(Name.PermittedSubclasses)) {
if (permittedSubclasses != null) {
throw ConstantPool.classFormatError("Duplicate PermittedSubclasses attribute");
}
classAttributes[i] = permittedSubclasses = parsePermittedSubclasses(attributeName);
} else {
Attribute attr = commonAttributeParser.parseCommonAttribute(attributeName, attributeSize);
// stream.skip(attributeSize);
classAttributes[i] = attr == null ? new Attribute(attributeName, stream.readByteArray(attributeSize)) : attr;
}
} else {
// stream.skip(attributeSize);
classAttributes[i] = new Attribute(attributeName, stream.readByteArray(attributeSize));
}
if (attributeSize != stream.getPosition() - startPosition) {
throw ConstantPool.classFormatError("Invalid attribute length for " + attributeName + " attribute");
}
}
if (maxBootstrapMethodAttrIndex >= 0 && bootstrapMethods == null) {
throw ConstantPool.classFormatError("BootstrapMethods attribute is missing");
}
return classAttributes;
}
Aggregations