use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class Method method makeMirror.
public StaticObject makeMirror() {
Meta meta = getMeta();
Attribute rawRuntimeVisibleAnnotations = getAttribute(Name.RuntimeVisibleAnnotations);
StaticObject runtimeVisibleAnnotations = rawRuntimeVisibleAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleAnnotations.getData(), meta) : StaticObject.NULL;
Attribute rawRuntimeVisibleParameterAnnotations = getAttribute(Name.RuntimeVisibleParameterAnnotations);
StaticObject runtimeVisibleParameterAnnotations = rawRuntimeVisibleParameterAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleParameterAnnotations.getData(), meta) : StaticObject.NULL;
Attribute rawRuntimeVisibleTypeAnnotations = getAttribute(Name.RuntimeVisibleTypeAnnotations);
StaticObject runtimeVisibleTypeAnnotations = rawRuntimeVisibleTypeAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleTypeAnnotations.getData(), meta) : StaticObject.NULL;
Attribute rawAnnotationDefault = getAttribute(Name.AnnotationDefault);
StaticObject annotationDefault = rawAnnotationDefault != null ? StaticObject.wrap(rawAnnotationDefault.getData(), meta) : StaticObject.NULL;
final Klass[] rawParameterKlasses = resolveParameterKlasses();
StaticObject parameterTypes = meta.java_lang_Class.allocateReferenceArray(getParameterCount(), new IntFunction<StaticObject>() {
@Override
public StaticObject apply(int j) {
return rawParameterKlasses[j].mirror();
}
});
final Klass[] rawCheckedExceptions = getCheckedExceptions();
StaticObject guestCheckedExceptions = meta.java_lang_Class.allocateReferenceArray(rawCheckedExceptions.length, new IntFunction<StaticObject>() {
@Override
public StaticObject apply(int j) {
return rawCheckedExceptions[j].mirror();
}
});
SignatureAttribute signatureAttribute = (SignatureAttribute) getAttribute(Name.Signature);
StaticObject guestGenericSignature = StaticObject.NULL;
if (signatureAttribute != null) {
String sig = getConstantPool().symbolAt(signatureAttribute.getSignatureIndex(), "signature").toString();
guestGenericSignature = meta.toGuestString(sig);
}
StaticObject instance = meta.java_lang_reflect_Method.allocateInstance();
meta.java_lang_reflect_Method_init.invokeDirect(/* this */
instance, /* declaringClass */
getDeclaringKlass().mirror(), /* name */
getContext().getStrings().intern(getName()), /* parameterTypes */
parameterTypes, /* returnType */
resolveReturnKlass().mirror(), /* checkedExceptions */
guestCheckedExceptions, /* modifiers */
getMethodModifiers(), /* slot */
getVTableIndex(), /* signature */
guestGenericSignature, /* annotations */
runtimeVisibleAnnotations, /* parameterAnnotations */
runtimeVisibleParameterAnnotations, /* annotationDefault */
annotationDefault);
meta.HIDDEN_METHOD_KEY.setHiddenObject(instance, this);
meta.HIDDEN_METHOD_RUNTIME_VISIBLE_TYPE_ANNOTATIONS.setHiddenObject(instance, runtimeVisibleTypeAnnotations);
return instance;
}
use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class JniEnv method NewObjectVarargs.
@JniImpl
@JavaType(Object.class)
public StaticObject NewObjectVarargs(@JavaType(Class.class) StaticObject clazz, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
Method method = methodIds.getObject(methodId);
assert method.isConstructor();
Klass klass = clazz.getMirrorKlass();
if (klass.isInterface() || klass.isAbstract()) {
Meta meta = getMeta();
throw meta.throwException(meta.java_lang_InstantiationException);
}
klass.initialize();
StaticObject instance;
if (CompilerDirectives.isPartialEvaluationConstant(klass)) {
instance = klass.allocateInstance();
} else {
instance = allocateBoundary(klass);
}
method.invokeDirect(instance, popVarArgs(varargsPtr, method.getParsedSignature()));
return instance;
}
use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class JniEnv method ToReflectedField.
/**
* <h3>jobject ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic);
* </h3>
* <p>
* Converts a field ID derived from cls to a java.lang.reflect.Field object. isStatic must be
* set to JNI_TRUE if fieldID refers to a static field, and JNI_FALSE otherwise.
* <p>
* Throws OutOfMemoryError and returns 0 if fails.
*/
@JniImpl
@JavaType(java.lang.reflect.Field.class)
public StaticObject ToReflectedField(@JavaType(Class.class) StaticObject unused, @Handle(Field.class) long fieldId, @SuppressWarnings("unused") boolean isStatic) {
Field field = fieldIds.getObject(fieldId);
assert field.getDeclaringKlass().isAssignableFrom(unused.getMirrorKlass());
StaticObject fields = getVM().JVM_GetClassDeclaredFields(field.getDeclaringKlass().mirror(), false);
for (StaticObject declField : fields.<StaticObject[]>unwrap()) {
assert InterpreterToVM.instanceOf(declField, getMeta().java_lang_reflect_Field);
Field f = (Field) getMeta().HIDDEN_FIELD_KEY.getHiddenObject(declField);
if (field == f) {
return declField;
}
}
throw EspressoError.shouldNotReachHere("Field not found ", field);
}
use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class JniEnv method CallNonvirtualDoubleMethodVarargs.
@JniImpl
public double CallNonvirtualDoubleMethodVarargs(@JavaType(Object.class) StaticObject receiver, @JavaType(Class.class) StaticObject clazz, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
Method method = methodIds.getObject(methodId);
assert !method.isStatic();
assert (clazz.getMirrorKlass()) == method.getDeclaringKlass();
Object result = method.invokeDirect(receiver, popVarArgs(varargsPtr, method.getParsedSignature()));
return getMeta().asDouble(result, true);
}
use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class ClassRegistry method loadKlass.
/**
* Queries a registry to load a Klass for us.
*
* @param type the symbolic reference to the Klass we want to load
* @param protectionDomain The protection domain extracted from the guest class, or
* {@link StaticObject#NULL} if trusted.
* @return The Klass corresponding to given type
*/
@SuppressWarnings("try")
Klass loadKlass(Symbol<Type> type, StaticObject protectionDomain) {
if (Types.isArray(type)) {
Klass elemental = loadKlass(getTypes().getElementalType(type), protectionDomain);
if (elemental == null) {
return null;
}
return elemental.getArrayClass(Types.getArrayDimensions(type));
}
loadKlassCountInc();
// Double-checked locking on the symbol (globally unique).
ClassRegistries.RegistryEntry entry;
try (DebugCloseable probe = KLASS_PROBE.scope(getContext().getTimers())) {
entry = classes.get(type);
}
if (entry == null) {
synchronized (type) {
entry = classes.get(type);
if (entry == null) {
if (loadKlassImpl(type) == null) {
return null;
}
entry = classes.get(type);
}
}
} else {
// Grabbing a lock to fetch the class is not considered a hit.
loadKlassCacheHitsInc();
}
assert entry != null;
StaticObject classLoader = getClassLoader();
if (!StaticObject.isNull(classLoader)) {
entry.checkPackageAccess(getMeta(), classLoader, protectionDomain);
}
return entry.klass();
}
Aggregations