[vmkit-commits] [vmkit] r199063 - add two functions from sun/misc/Perf.
Gael Thomas
gael.thomas at lip6.fr
Sun Jan 12 13:35:44 PST 2014
Author: gthomas
Date: Sun Jan 12 15:35:43 2014
New Revision: 199063
URL: http://llvm.org/viewvc/llvm-project?rev=199063&view=rev
Log:
add two functions from sun/misc/Perf.
Added:
vmkit/branches/mcjit/lib/j3/openjdk/j3perf.cc
Modified:
vmkit/branches/mcjit/include/j3/j3.h
vmkit/branches/mcjit/include/j3/j3lib.h
vmkit/branches/mcjit/include/j3/j3monitor.h
vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc
vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc
vmkit/branches/mcjit/lib/j3/vm/j3.cc
vmkit/branches/mcjit/lib/j3/vm/j3jni.cc
vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc
Modified: vmkit/branches/mcjit/include/j3/j3.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=199063&r1=199062&r2=199063&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3.h (original)
+++ vmkit/branches/mcjit/include/j3/j3.h Sun Jan 12 15:35:43 2014
@@ -148,6 +148,8 @@ namespace j3 {
J3ObjectType* clName, const vmkit::Name* name, J3Type* type) __attribute__((noreturn));
static void linkageError(J3Method* method) __attribute__((noreturn));
+ static void outOfMemoryError() __attribute__((noreturn));
+
static void nullPointerException() __attribute__((noreturn));
static void classCastException() __attribute__((noreturn));
@@ -157,6 +159,8 @@ namespace j3 {
static void illegalMonitorStateException() __attribute__((noreturn));
+ static void illegalArgumentException(const char* msg) __attribute__((noreturn));
+
static void printStackTrace();
void forceSymbolDefinition();
Modified: vmkit/branches/mcjit/include/j3/j3lib.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3lib.h?rev=199063&r1=199062&r2=199063&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3lib.h (original)
+++ vmkit/branches/mcjit/include/j3/j3lib.h Sun Jan 12 15:35:43 2014
@@ -7,6 +7,7 @@
namespace j3 {
class J3;
class J3ClassLoader;
+ class J3ObjectHandle;
class J3Lib {
public:
@@ -16,6 +17,8 @@ namespace j3 {
static void loadSystemLibraries(J3ClassLoader* loader);
static void bootstrap(J3* vm);
+
+ static J3ObjectHandle* newDirectByteBuffer(void* address, size_t len);
};
}
Modified: vmkit/branches/mcjit/include/j3/j3monitor.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3monitor.h?rev=199063&r1=199062&r2=199063&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3monitor.h (original)
+++ vmkit/branches/mcjit/include/j3/j3monitor.h Sun Jan 12 15:35:43 2014
@@ -40,7 +40,8 @@ namespace j3 {
void init(J3Monitor* next); /* acquire the lock for the next inflate */
public:
bool isDeflatable(); /* acquire the lock for the next inflate */
- void prepare(J3Object* _object, uintptr_t header, J3LockRecord* _record);
+ J3Monitor* prepare(J3Object* _object, uintptr_t header, J3LockRecord* _record);
+ J3Monitor* prepare();
void lock();
void unlock();
Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc?rev=199063&r1=199062&r2=199063&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3lib.cc Sun Jan 12 15:35:43 2014
@@ -74,3 +74,27 @@ void J3Lib::loadSystemLibraries(J3ClassL
loader->addNativeLibrary(handle);
}
+J3ObjectHandle* J3Lib::newDirectByteBuffer(void* address, size_t len) {
+#if 0
+ JavaObject* res = 0;
+ llvm_gcroot(res, 0);
+
+ BEGIN_JNI_EXCEPTION
+
+ JavaThread* th = JavaThread::get();
+ Jnjvm* myvm = th->getJVM();
+ UserClass* BB = myvm->upcalls->newDirectByteBuffer;
+
+ res = BB->doNew(myvm);
+
+ myvm->upcalls->InitDirectByteBuffer->invokeIntSpecial(myvm, BB, res,
+ (uint64_t)(uintptr_t)address, (int)capacity);
+
+ jobject ret = (jobject)th->pushJNIRef(res);
+ RETURN_FROM_JNI(ret);
+ END_JNI_EXCEPTION
+
+ RETURN_FROM_JNI(0);
+#endif
+ J3::internalError("not yet implemented");
+}
Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=199063&r1=199062&r2=199063&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Sun Jan 12 15:35:43 2014
@@ -12,6 +12,8 @@
#include <dlfcn.h>
#include <sys/utsname.h>
#include <sys/time.h>
+#include <stdlib.h>
+#include <fcntl.h>
using namespace j3;
@@ -1200,14 +1202,43 @@ jint JNICALL JVM_GetLastErrorString(char
* cleanup, such as removing redundant separator characters. It modifies
* the given pathname string in place.
*/
-char * JNICALL JVM_NativePath(char *) { enterJVM(); leaveJVM(); NYI(); }
+char* JNICALL JVM_NativePath(char* path) {
+ char buf[PATH_MAX];
+ enterJVM();
+ realpath(path, buf);
+ strcpy(path, buf);
+ leaveJVM();
+ return path;
+}
/*
* Open a file descriptor. This function returns a negative error code
* on error, and a non-negative integer that is the file descriptor on
* success.
*/
-jint JNICALL JVM_Open(const char *fname, jint flags, jint mode) { enterJVM(); leaveJVM(); NYI(); }
+jint JNICALL JVM_Open(const char *fname, jint flags, jint mode) {
+ jint res;
+ enterJVM();
+ // Special flag the JVM uses
+ // means to delete the file after opening.
+ static const int O_DELETE = 0x10000;
+ res = open(fname, flags & ~O_DELETE, mode);
+
+ // Map EEXIST to special JVM_EEXIST, otherwise all errors are -1
+ if (res < 0) {
+ if (errno == EEXIST)
+ res = JVM_EEXIST;
+ else
+ res = -1;
+ }
+
+ // Handle O_DELETE flag, if specified
+ if (flags & O_DELETE)
+ unlink(fname);
+ leaveJVM();
+
+ return res;
+}
/*
* Close a file descriptor. This function returns -1 on error, and 0
@@ -1327,10 +1358,35 @@ int jio_vfprintf(FILE *f, const char *fm
}
-void * JNICALL JVM_RawMonitorCreate(void) { enterJVM(); leaveJVM(); NYI(); }
-void JNICALL JVM_RawMonitorDestroy(void *mon) { enterJVM(); leaveJVM(); NYI(); }
-jint JNICALL JVM_RawMonitorEnter(void *mon) { enterJVM(); leaveJVM(); NYI(); }
-void JNICALL JVM_RawMonitorExit(void *mon) { enterJVM(); leaveJVM(); NYI(); }
+void* JNICALL JVM_RawMonitorCreate(void) {
+ void* res;
+ enterJVM();
+ res = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
+ if(!res)
+ J3::outOfMemoryError();
+ leaveJVM();
+ return res;
+}
+
+void JNICALL JVM_RawMonitorDestroy(void *mon) {
+ enterJVM();
+ free(mon);
+ leaveJVM();
+}
+
+jint JNICALL JVM_RawMonitorEnter(void *mon) {
+ jint res;
+ enterJVM();
+ res = pthread_mutex_lock((pthread_mutex_t*)mon);
+ leaveJVM();
+ return res;
+}
+
+void JNICALL JVM_RawMonitorExit(void *mon) {
+ enterJVM();
+ pthread_mutex_unlock((pthread_mutex_t*)mon);
+ leaveJVM();
+}
/*
* java.lang.management support
Added: vmkit/branches/mcjit/lib/j3/openjdk/j3perf.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3perf.cc?rev=199063&view=auto
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3perf.cc (added)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3perf.cc Sun Jan 12 15:35:43 2014
@@ -0,0 +1,87 @@
+#include "j3/j3jni.h"
+#include "j3/j3.h"
+#include "j3/j3thread.h"
+
+namespace j3 {
+ class PerfData {
+ public:
+ // the Variability enum must be kept in synchronization with the
+ // the com.sun.hotspot.perfdata.Variability class
+ enum Variability {
+ V_Constant = 1,
+ V_Monotonic = 2,
+ V_Variable = 3,
+ V_last = V_Variable
+ };
+
+ // the Units enum must be kept in synchronization with the
+ // the com.sun.hotspot.perfdata.Units class
+ enum Units {
+ U_None = 1,
+ U_Bytes = 2,
+ U_Ticks = 3,
+ U_Events = 4,
+ U_String = 5,
+ U_Hertz = 6,
+ U_Last = U_Hertz
+ };
+
+ private:
+ const vmkit::Name* name;
+ Variability variability;
+ Units units;
+ uint64_t value;
+
+ public:
+ PerfData(const vmkit::Name* _name, Variability _variability, Units _units, uint64_t _value) {
+ name = _name;
+ variability = _variability;
+ units = _units;
+ value = _value;
+ }
+
+ uint64_t* address() { return &value; }
+ };
+
+ class PerfDataManager {
+ pthread_mutex_t mutex;
+ std::map<const vmkit::Name*, PerfData*> perfDatas;
+ public:
+ static PerfDataManager manager;
+
+ PerfDataManager() {
+ pthread_mutex_init(&mutex, 0);
+ }
+
+ PerfData* define(const vmkit::Name* name, PerfData::Variability variability, PerfData::Units units, uint64_t value) {
+ pthread_mutex_lock(&mutex);
+ PerfData* res = perfDatas[name];
+ if(res)
+ J3::illegalArgumentException("trying to redefine a perf counter");
+ perfDatas[name] = res = new PerfData(name, variability, units, value);
+ pthread_mutex_unlock(&mutex);
+ return res;
+ }
+ };
+
+ PerfDataManager PerfDataManager::manager;
+}
+
+using namespace j3;
+
+extern "C" {
+ JNIEXPORT void JNICALL Java_sun_misc_Perf_registerNatives(JNIEnv* env, jclass clazz) {
+ // Nothing, we define the Perf methods with the expected signatures.
+ }
+
+ JNIEXPORT jobject JNICALL Java_sun_misc_Perf_createLong(JNIEnv* env, jobject perf, jstring name,
+ jint variability, jint units, jlong value) {
+ PerfData* pd;
+ enterJVM();
+ J3* vm = J3Thread::get()->vm();
+ pd = PerfDataManager::manager.define(vm->stringToName(name),
+ (PerfData::Variability)variability, (PerfData::Units)units, value);
+ leaveJVM();
+ return env->NewDirectByteBuffer(pd->address(), sizeof(uint64_t));
+ }
+}
Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc?rev=199063&r1=199062&r2=199063&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3unsafe.cc Sun Jan 12 15:35:43 2014
@@ -11,7 +11,7 @@
using namespace j3;
extern "C" {
- JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(JNIEnv* env, jobject unsafe) {
+ JNIEXPORT void JNICALL Java_sun_misc_Unsafe_registerNatives(JNIEnv* env, jclass clazz) {
// Nothing, we define the Unsafe methods with the expected signatures.
}
@@ -66,11 +66,19 @@ extern "C" {
}
JNIEXPORT jlong JNICALL Java_sun_misc_Unsafe_allocateMemory(JNIEnv* env, jobject unsafe, jlong bytes) {
- return (jlong)(uintptr_t)malloc(bytes);
+ jlong res;
+ enterJVM();
+ res = (jlong)(uintptr_t)malloc(bytes);
+ if(!res)
+ J3::outOfMemoryError();
+ leaveJVM();
+ return res;
}
JNIEXPORT void JNICALL Java_sun_misc_Unsafe_freeMemory(JNIEnv* env, jobject unsafe, jlong addr) {
+ enterJVM();
free((void*)(uintptr_t)addr);
+ leaveJVM();
}
#define unsafeGetPut(jtype, id, j3id, sign) \
Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=199063&r1=199062&r2=199063&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Sun Jan 12 15:35:43 2014
@@ -273,6 +273,10 @@ void J3::linkageError(J3Method* method)
method->signature()->name()->cStr());
}
+void J3::outOfMemoryError() {
+ internalError("out of memory error");
+}
+
void J3::negativeArraySizeException(int32_t length) {
internalError("negative array size exception: %ld", length);
}
@@ -289,6 +293,10 @@ void J3::illegalMonitorStateException()
internalError("illegal monitor state exception");
}
+void J3::illegalArgumentException(const char* msg) {
+ internalError("illegal argument exception: %s", msg);
+}
+
void J3::vinternalError(const char* msg, va_list va) {
char buf[65536];
vsnprintf(buf, 65536, msg, va);
Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=199063&r1=199062&r2=199063&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Sun Jan 12 15:35:43 2014
@@ -6,6 +6,7 @@
#include "j3/j3method.h"
#include "j3/j3thread.h"
#include "j3/j3utf16.h"
+#include "j3/j3lib.h"
#include <stdlib.h>
#define NYI() { J3Thread::get()->vm()->internalError("not yet implemented: '%s'", __PRETTY_FUNCTION__); }
@@ -582,7 +583,14 @@ jboolean JNICALL ExceptionCheck(JNIEnv*
return J3Thread::get()->hasPendingException();
}
-jobject JNICALL NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) { enterJVM(); leaveJVM(); NYI(); }
+jobject JNICALL NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) {
+ jobject res;
+ enterJVM();
+ res = J3Lib::newDirectByteBuffer(address, capacity);
+ leaveJVM();
+ return res;
+}
+
void* JNICALL GetDirectBufferAddress(JNIEnv* env, jobject buf) { enterJVM(); leaveJVM(); NYI(); }
jlong JNICALL GetDirectBufferCapacity(JNIEnv* env, jobject buf) { enterJVM(); leaveJVM(); NYI(); }
Modified: vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc?rev=199063&r1=199062&r2=199063&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3monitor.cc Sun Jan 12 15:35:43 2014
@@ -16,11 +16,16 @@ bool J3Monitor::isDeflatable() {
return pthread_mutex_trylock(&mutex) == 0;
}
-void J3Monitor::prepare(J3Object* _object, uintptr_t _header, J3LockRecord* _record) {
+J3Monitor* J3Monitor::prepare(J3Object* _object, uintptr_t _header, J3LockRecord* _record) {
object = _object;
record = _record;
header = _header;
owner = _record ? J3Thread::get(_record) : 0;
+ return this;
+}
+
+J3Monitor* J3Monitor::prepare() {
+ return prepare(0, 0, 0);
}
void J3Monitor::checkRecord() {
More information about the vmkit-commits
mailing list