use of com.oracle.truffle.espresso.descriptors.Symbol 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 in project graal by oracle.
the class ObjectKlass method getNestedTypeNames.
@TruffleBoundary
public List<Symbol<Name>> getNestedTypeNames() {
ArrayList<Symbol<Name>> result = new ArrayList<>();
InnerClassesAttribute innerClasses = getKlassVersion().innerClasses;
if (innerClasses != null) {
for (InnerClassesAttribute.Entry entry : innerClasses.entries()) {
if (entry.innerClassIndex != 0) {
result.add(getConstantPool().classAt(entry.innerClassIndex).getName(getConstantPool()));
}
}
}
return result;
}
use of com.oracle.truffle.espresso.descriptors.Symbol in project graal by oracle.
the class InnerClassRedefiner method fetchMissingInnerClasses.
private void fetchMissingInnerClasses(HotSwapClassInfo hotswapInfo) throws RedefintionNotSupportedException {
StaticObject definingLoader = hotswapInfo.getClassLoader();
ArrayList<Symbol<Symbol.Name>> innerNames = new ArrayList<>(1);
try {
searchConstantPoolForInnerClassNames(hotswapInfo, innerNames);
} catch (ClassFormatError ex) {
throw new RedefintionNotSupportedException(ErrorCodes.INVALID_CLASS_FORMAT);
}
// poke the defining guest classloader for the resources
for (Symbol<Symbol.Name> innerName : innerNames) {
if (!hotswapInfo.knowsInnerClass(innerName)) {
byte[] classBytes = null;
StaticObject resourceGuestString = context.getMeta().toGuestString(innerName + ".class");
StaticObject inputStream = (StaticObject) context.getMeta().java_lang_ClassLoader_getResourceAsStream.invokeDirect(definingLoader, resourceGuestString);
if (StaticObject.notNull(inputStream)) {
classBytes = readAllBytes(inputStream);
} else {
// There is no safe way to retrieve the class bytes using e.g. a scheme using
// j.l.ClassLoader#loadClass and special marker for the type to have the call
// end up in defineClass where we could grab the bytes. Guest language
// classloaders in many cases have caches for the class name that prevents
// forcefully attempting to load previously not loadable classes.
// without the class bytes, the matching is less precise and cached un-matched
// inner class instances that are executed after redefintion will lead to
// NoSuchMethod errors because they're marked as removed
}
if (classBytes != null) {
hotswapInfo.addInnerClass(ClassInfo.create(innerName, classBytes, definingLoader, context));
}
}
}
}
use of com.oracle.truffle.espresso.descriptors.Symbol in project graal by oracle.
the class InnerClassRedefiner method findLoadedInnerClasses.
Set<ObjectKlass> findLoadedInnerClasses(Klass klass) {
// we use a cache to store inner/outer class mappings
Map<Symbol<Symbol.Type>, Set<ObjectKlass>> classLoaderMap = innerKlassCache.get(klass.getDefiningClassLoader());
if (classLoaderMap == null) {
classLoaderMap = new HashMap<>();
// register a listener on the registry to fill in
// future loaded anonymous inner classes
ClassRegistry classRegistry = context.getRegistries().getClassRegistry(klass.getDefiningClassLoader());
classRegistry.registerOnLoadListener(new DefineKlassListener() {
@Override
public void onKlassDefined(ObjectKlass objectKlass) {
InnerClassRedefiner.this.onKlassDefined(objectKlass);
}
});
// do a one-time look up of all currently loaded
// classes for this loader and fill in the map
List<Klass> loadedKlasses = classRegistry.getLoadedKlasses();
for (Klass loadedKlass : loadedKlasses) {
if (loadedKlass instanceof ObjectKlass) {
ObjectKlass objectKlass = (ObjectKlass) loadedKlass;
Matcher matcher = ANON_INNER_CLASS_PATTERN.matcher(loadedKlass.getNameAsString());
if (matcher.matches()) {
Symbol<Symbol.Name> outerClassName = getOuterClassName(loadedKlass.getName());
if (outerClassName != null && outerClassName.length() > 0) {
Symbol<Symbol.Type> outerType = context.getTypes().fromName(outerClassName);
Set<ObjectKlass> innerKlasses = classLoaderMap.get(outerType);
if (innerKlasses == null) {
innerKlasses = new HashSet<>(1);
classLoaderMap.put(outerType, innerKlasses);
}
innerKlasses.add(objectKlass);
}
}
}
}
// add to cache
innerKlassCache.put(klass.getDefiningClassLoader(), classLoaderMap);
}
Set<ObjectKlass> innerClasses = classLoaderMap.get(klass.getType());
return innerClasses != null ? innerClasses : new HashSet<>(0);
}
use of com.oracle.truffle.espresso.descriptors.Symbol in project graal by oracle.
the class InnerClassRedefiner method onKlassDefined.
private void onKlassDefined(ObjectKlass klass) {
Matcher matcher = ANON_INNER_CLASS_PATTERN.matcher(klass.getNameAsString());
if (matcher.matches()) {
Map<Symbol<Symbol.Type>, Set<ObjectKlass>> classLoaderMap = innerKlassCache.get(klass.getDefiningClassLoader());
// found inner class, now hunt down the outer
Symbol<Symbol.Name> outerName = getOuterClassName(klass.getName());
Symbol<Symbol.Type> outerType = context.getTypes().fromName(outerName);
Set<ObjectKlass> innerKlasses = classLoaderMap.get(outerType);
if (innerKlasses == null) {
innerKlasses = new HashSet<>(1);
classLoaderMap.put(outerType, innerKlasses);
}
innerKlasses.add(klass);
}
}
Aggregations