use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class Target_sun_misc_Unsafe method arrayIndexScale.
/**
* Report the scale factor for addressing elements in the storage allocation of a given array
* class. However, arrays of "narrow" types will generally not work properly with accessors like
* {@link #getByte}, so the scale factor for such classes is reported as zero.
*
* @see #arrayBaseOffset
* @see #getInt
* @see #putInt
*/
@Substitution(hasReceiver = true, nameProvider = SharedUnsafeAppend0.class)
public static int arrayIndexScale(@SuppressWarnings("unused") @JavaType(Unsafe.class) StaticObject self, @JavaType(Class.class) StaticObject clazz, @Inject Meta meta) {
Unsafe unsafe = UnsafeAccess.getIfAllowed(meta);
Klass klass = clazz.getMirrorKlass();
assert klass.isArray();
if (((ArrayKlass) klass).getComponentType().isPrimitive()) {
Class<?> hostPrimitive = ((ArrayKlass) klass).getComponentType().getJavaKind().toJavaClass();
return unsafe.arrayIndexScale(Array.newInstance(hostPrimitive, 0).getClass());
} else {
// Just a reference type.
return unsafe.arrayIndexScale(Object[].class);
}
}
use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class Management method DumpThreads.
@ManagementImpl
@SuppressWarnings("unused")
@JavaType(internalName = "[Ljava/lang/management/ThreadInfo;")
public StaticObject DumpThreads(@JavaType(long[].class) StaticObject ids, boolean lockedMonitors, boolean lockedSynchronizers, @Inject SubstitutionProfiler profiler) {
StaticObject threadIds = ids;
if (StaticObject.isNull(threadIds)) {
StaticObject[] activeThreads = getContext().getActiveThreads();
threadIds = InterpreterToVM.allocatePrimitiveArray((byte) JavaKind.Long.getBasicType(), activeThreads.length, getMeta());
for (int j = 0; j < activeThreads.length; ++j) {
long tid = getThreadAccess().getThreadId(activeThreads[j]);
getInterpreterToVM().setArrayLong(tid, j, threadIds);
}
}
StaticObject result = getMeta().java_lang_management_ThreadInfo.allocateReferenceArray(threadIds.length());
if (GetThreadInfo(threadIds, 0, result, profiler) != JNI_OK) {
return StaticObject.NULL;
}
return result;
}
use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.
the class UnsafeAccess method initializeGuestUnsafeConstants.
public static void initializeGuestUnsafeConstants(Meta meta) {
/*
* To obtain the unobtainable fields, we would need to have one such method per supported
* host java version
*/
StaticObject staticStorage = meta.jdk_internal_misc_UnsafeConstants.tryInitializeAndGetStatics();
meta.jdk_internal_misc_UnsafeConstants_ADDRESS_SIZE0.set(staticStorage, UNSAFE.addressSize());
meta.jdk_internal_misc_UnsafeConstants_PAGE_SIZE.set(staticStorage, UNSAFE.pageSize());
meta.jdk_internal_misc_UnsafeConstants_BIG_ENDIAN.set(staticStorage, ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN);
meta.jdk_internal_misc_UnsafeConstants_UNALIGNED_ACCESS.set(staticStorage, Target_sun_misc_Unsafe.unalignedAccess0(/*- Ignored guest Unsafe */
StaticObject.NULL));
meta.jdk_internal_misc_UnsafeConstants_DATA_CACHE_LINE_FLUSH_SIZE.set(staticStorage, /*- Unobtainable */
0);
}
use of com.oracle.truffle.espresso.runtime.StaticObject 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.runtime.StaticObject in project graal by oracle.
the class InnerClassRedefiner method readAllBytes.
private byte[] readAllBytes(StaticObject inputStream) {
byte[] buf = new byte[4 * 0x400];
StaticObject guestBuf = StaticObject.wrap(buf, context.getMeta());
int readLen;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
while ((readLen = (int) context.getMeta().java_io_InputStream_read.invokeDirect(inputStream, guestBuf, 0, buf.length)) != -1) {
byte[] bytes = guestBuf.unwrap();
outputStream.write(bytes, 0, readLen);
}
return outputStream.toByteArray();
} catch (IOException ex) {
return new byte[0];
} finally {
context.getMeta().java_io_InputStream_close.invokeDirect(inputStream);
}
}
Aggregations