8080511: Refresh of jimage support

Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: alanb, mchung, psandoz, acorn, lfoltan, ctornqvi
This commit is contained in:
Jean-Francois Denise 2015-06-25 18:25:19 +02:00
parent 6684a41c5d
commit aaac2cbb54
40 changed files with 2815 additions and 322 deletions

View file

@ -27,6 +27,7 @@
#include <new>
#include "classfile/classLoaderData.hpp"
#include "classfile/imageFile.hpp"
#include "classfile/stringTable.hpp"
#include "code/codeCache.hpp"
#include "jvmtifiles/jvmtiEnv.hpp"
@ -1125,6 +1126,132 @@ WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb))
return (jlong) MetaspaceGC::capacity_until_GC();
WB_END
WB_ENTRY(jboolean, WB_ReadImageFile(JNIEnv* env, jobject wb, jstring imagefile))
const char* filename = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(imagefile));
return ImageFileReader::open(filename) != NULL;
WB_END
WB_ENTRY(jlong, WB_imageOpenImage(JNIEnv *env, jobject wb, jstring path, jboolean big_endian))
ThreadToNativeFromVM ttn(thread);
const char *nativePath = env->GetStringUTFChars(path, NULL);
jlong ret = JVM_ImageOpen(env, nativePath, big_endian);
env->ReleaseStringUTFChars(path, nativePath);
return ret;
WB_END
WB_ENTRY(void, WB_imageCloseImage(JNIEnv *env, jobject wb, jlong id))
ThreadToNativeFromVM ttn(thread);
JVM_ImageClose(env, id);
WB_END
WB_ENTRY(jlong, WB_imageGetIndexAddress(JNIEnv *env, jobject wb, jlong id))
ThreadToNativeFromVM ttn(thread);
return JVM_ImageGetIndexAddress(env, id);
WB_END
WB_ENTRY(jlong, WB_imageGetDataAddress(JNIEnv *env, jobject wb, jlong id))
ThreadToNativeFromVM ttn(thread);
return JVM_ImageGetDataAddress(env, id);
WB_END
WB_ENTRY(jboolean, WB_imageRead(JNIEnv *env, jobject wb, jlong id, jlong offset, jobject uncompressedBuffer, jlong uncompressed_size))
ThreadToNativeFromVM ttn(thread);
if (uncompressedBuffer == NULL) {
return JNI_FALSE;
}
unsigned char* uncompressedAddress =
(unsigned char*) env->GetDirectBufferAddress(uncompressedBuffer);
return JVM_ImageRead(env, id, offset, uncompressedAddress, uncompressed_size);
WB_END
WB_ENTRY(jboolean, WB_imageReadCompressed(JNIEnv *env, jobject wb, jlong id, jlong offset, jobject compressedBuffer, jlong compressed_size, jobject uncompressedBuffer, jlong uncompressed_size))
ThreadToNativeFromVM ttn(thread);
if (uncompressedBuffer == NULL || compressedBuffer == NULL) {
return false;
}
// Get address of read direct buffer.
unsigned char* compressedAddress =
(unsigned char*) env->GetDirectBufferAddress(compressedBuffer);
// Get address of decompression direct buffer.
unsigned char* uncompressedAddress =
(unsigned char*) env->GetDirectBufferAddress(uncompressedBuffer);
return JVM_ImageReadCompressed(env, id, offset, compressedAddress, compressed_size, uncompressedAddress, uncompressed_size);
WB_END
WB_ENTRY(jbyteArray, WB_imageGetStringBytes(JNIEnv *env, jobject wb, jlong id, jlong offset))
ThreadToNativeFromVM ttn(thread);
const char* data = JVM_ImageGetStringBytes(env, id, offset);
// Determine String length.
size_t size = strlen(data);
// Allocate byte array.
jbyteArray byteArray = env->NewByteArray((jsize) size);
// Get array base address.
jbyte* rawBytes = env->GetByteArrayElements(byteArray, NULL);
// Copy bytes from image string table.
memcpy(rawBytes, data, size);
// Release byte array base address.
env->ReleaseByteArrayElements(byteArray, rawBytes, 0);
return byteArray;
WB_END
WB_ENTRY(jlong, WB_imageGetStringsSize(JNIEnv *env, jobject wb, jlong id))
ImageFileReader* reader = ImageFileReader::idToReader(id);
return reader? reader->strings_size() : 0L;
WB_END
WB_ENTRY(jlongArray, WB_imageGetAttributes(JNIEnv *env, jobject wb, jlong id, jint offset))
ThreadToNativeFromVM ttn(thread);
// Allocate a jlong large enough for all location attributes.
jlongArray attributes = env->NewLongArray(JVM_ImageGetAttributesCount(env));
// Get base address for jlong array.
jlong* rawAttributes = env->GetLongArrayElements(attributes, NULL);
jlong* ret = JVM_ImageGetAttributes(env, rawAttributes, id, offset);
// Release jlong array base address.
env->ReleaseLongArrayElements(attributes, rawAttributes, 0);
return ret == NULL ? NULL : attributes;
WB_END
WB_ENTRY(jlongArray, WB_imageFindAttributes(JNIEnv *env, jobject wb, jlong id, jbyteArray utf8))
ThreadToNativeFromVM ttn(thread);
// Allocate a jlong large enough for all location attributes.
jlongArray attributes = env->NewLongArray(JVM_ImageGetAttributesCount(env));
// Get base address for jlong array.
jlong* rawAttributes = env->GetLongArrayElements(attributes, NULL);
jsize size = env->GetArrayLength(utf8);
jbyte* rawBytes = env->GetByteArrayElements(utf8, NULL);
jlong* ret = JVM_ImageFindAttributes(env, rawAttributes, rawBytes, size, id);
env->ReleaseByteArrayElements(utf8, rawBytes, 0);
env->ReleaseLongArrayElements(attributes, rawAttributes, 0);
return ret == NULL ? NULL : attributes;
WB_END
WB_ENTRY(jintArray, WB_imageAttributeOffsets(JNIEnv *env, jobject wb, jlong id))
ThreadToNativeFromVM ttn(thread);
unsigned int length = JVM_ImageAttributeOffsetsLength(env, id);
if (length == 0) {
return NULL;
}
jintArray offsets = env->NewIntArray(length);
// Get base address of result.
jint* rawOffsets = env->GetIntArrayElements(offsets, NULL);
jint* ret = JVM_ImageAttributeOffsets(env, rawOffsets, length, id);
// Release result base address.
env->ReleaseIntArrayElements(offsets, rawOffsets, 0);
return ret == NULL ? NULL : offsets;
WB_END
WB_ENTRY(jint, WB_imageGetIntAtAddress(JNIEnv *env, jobject wb, jlong address, jint offset, jboolean big_endian))
unsigned char* arr = (unsigned char*) address + offset;
jint uraw;
if (big_endian) {
uraw = arr[0] << 24 | arr[1]<<16 | (arr[2]<<8) | arr[3];
} else {
uraw = arr[0] | arr[1]<<8 | (arr[2]<<16) | arr[3]<<24;
}
return uraw;
WB_END
WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
Monitor::_safepoint_check_always :
@ -1428,8 +1555,23 @@ static JNINativeMethod methods[] = {
{CC"getCodeBlob", CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob },
{CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize },
{CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize },
{CC"readImageFile", CC"(Ljava/lang/String;)Z", (void*)&WB_ReadImageFile },
{CC"imageOpenImage", CC"(Ljava/lang/String;Z)J",(void*)&WB_imageOpenImage },
{CC"imageCloseImage", CC"(J)V", (void*)&WB_imageCloseImage },
{CC"imageGetIndexAddress",CC"(J)J", (void*)&WB_imageGetIndexAddress},
{CC"imageGetDataAddress",CC"(J)J", (void*)&WB_imageGetDataAddress},
{CC"imageRead", CC"(JJLjava/nio/ByteBuffer;J)Z",
(void*)&WB_imageRead },
{CC"imageReadCompressed",CC"(JJLjava/nio/ByteBuffer;JLjava/nio/ByteBuffer;J)Z",
(void*)&WB_imageReadCompressed},
{CC"imageGetStringBytes",CC"(JI)[B", (void*)&WB_imageGetStringBytes},
{CC"imageGetStringsSize",CC"(J)J", (void*)&WB_imageGetStringsSize},
{CC"imageGetAttributes", CC"(JI)[J", (void*)&WB_imageGetAttributes},
{CC"imageFindAttributes",CC"(J[B)[J", (void*)&WB_imageFindAttributes},
{CC"imageAttributeOffsets",CC"(J)[I", (void*)&WB_imageAttributeOffsets},
{CC"imageGetIntAtAddress",CC"(JIZ)I", (void*)&WB_imageGetIntAtAddress},
{CC"assertMatchingSafepointCalls", CC"(ZZ)V", (void*)&WB_AssertMatchingSafepointCalls },
{CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
{CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
{CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint },
{CC"getMethodBooleanOption",
CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",