From 4b9cb4f4e4d138bdbe3cc335052c117637aef660 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 5 Aug 2011 18:06:29 -0600 Subject: [PATCH] enable JMX support for openjdk-src build and implement GetInputArgumentArray --- openjdk-src.mk | 7 +++++- src/bootimage.cpp | 2 +- src/classpath-openjdk.cpp | 45 ++++++++++++++++++++++++++++++++++++- src/jnienv.cpp | 11 ++++++++- src/machine.cpp | 7 +++++- src/machine.h | 5 ++++- src/openjdk/my_management.c | 2 ++ 7 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 src/openjdk/my_management.c diff --git a/openjdk-src.mk b/openjdk-src.mk index ed0c42199b..28166a9542 100644 --- a/openjdk-src.mk +++ b/openjdk-src.mk @@ -48,6 +48,7 @@ openjdk-sources = \ $(openjdk-src)/share/native/java/util/zip/ZipEntry.c \ $(openjdk-src)/share/native/java/util/zip/ZipFile.c \ $(openjdk-src)/share/native/java/util/zip/zip_util.c \ + $(openjdk-src)/share/native/sun/management/VMManagementImpl.c \ $(openjdk-src)/share/native/sun/misc/GC.c \ $(openjdk-src)/share/native/sun/misc/MessageUtils.c \ $(openjdk-src)/share/native/sun/misc/NativeSignalHandler.c \ @@ -112,6 +113,7 @@ openjdk-headers-classes = \ java.util.zip.Inflater \ java.util.zip.ZipEntry \ java.util.zip.ZipFile \ + sun.management.VMManagementImpl \ sun.misc.GC \ sun.misc.MessageUtils \ sun.misc.NativeSignalHandler \ @@ -151,6 +153,7 @@ openjdk-cflags = \ "-I$(openjdk-src)/share/native/java/lang/fdlibm/include" \ "-I$(openjdk-src)/share/native/java/net" \ "-I$(openjdk-src)/share/native/java/util/zip" \ + "-I$(openjdk-src)/share/native/sun/management" \ "-I$(openjdk-src)/share/native/sun/nio/ch" \ "-I$(openjdk-src)/share/javavm/include" \ -D_LITTLE_ENDIAN \ @@ -291,13 +294,15 @@ else "-I$(openjdk-src)/solaris/native/java/lang" \ "-I$(openjdk-src)/solaris/native/java/net" \ "-I$(openjdk-src)/solaris/native/java/util" \ + "-I$(openjdk-src)/solaris/native/sun/management" \ "-I$(openjdk-src)/solaris/native/sun/nio/ch" \ "-I$(openjdk-src)/solaris/javavm/include" \ "-I$(openjdk-src)/solaris/hpi/include" endif openjdk-local-sources = \ - $(src)/openjdk/my_net_util.c + $(src)/openjdk/my_net_util.c \ + $(src)/openjdk/my_management.c c-objects = $(foreach x,$(1),$(patsubst $(2)/%.c,$(3)/%-openjdk.o,$(x))) diff --git a/src/bootimage.cpp b/src/bootimage.cpp index 1371fae525..b58439e3a7 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -572,7 +572,7 @@ main(int ac, const char** av) p->initialize(&image, code, CodeCapacity); Machine* m = new (h->allocate(sizeof(Machine))) Machine - (s, h, f, 0, p, c, 0, 0); + (s, h, f, 0, p, c, 0, 0, 0, 0); Thread* t = p->makeThread(m, 0, 0); enter(t, Thread::ActiveState); diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 2b0c14c78e..8d70b860dd 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -355,7 +355,7 @@ class MyClasspath : public Classpath { MyClasspath(System* s, Allocator* allocator, const char* javaHome, const char* embedPrefix): - allocator(allocator), ranNetOnLoad(0) + allocator(allocator), ranNetOnLoad(0), ranManagementOnLoad(0) { class StringBuilder { public: @@ -613,6 +613,7 @@ class MyClasspath : public Classpath { unsigned zipEntryCsizeField; unsigned zipEntryMethodField; bool ranNetOnLoad; + bool ranManagementOnLoad; char buffer[BufferSize]; JmmInterface jmmInterface; }; @@ -1615,6 +1616,9 @@ getBootstrapResources(Thread* t, object, uintptr_t* arguments) extern "C" JNIEXPORT jint JNICALL net_JNI_OnLoad(JavaVM*, void*); +extern "C" JNIEXPORT jint JNICALL +management_JNI_OnLoad(JavaVM*, void*); + void JNICALL loadLibrary(Thread* t, object, uintptr_t* arguments) { @@ -1643,6 +1647,23 @@ loadLibrary(Thread* t, object, uintptr_t* arguments) } return; + } else if (strcmp(n, "management") == 0) { + bool ran; + + { ACQUIRE(t, t->m->classLock); + + local::MyClasspath* c = static_cast + (t->m->classpath); + + ran = c->ranManagementOnLoad; + c->ranManagementOnLoad = true; + } + + if (not ran) { + management_JNI_OnLoad(t->m, 0); + } + + return; } else if (strcmp(n, "zip") == 0 or strcmp(n, "nio") == 0) { @@ -5118,6 +5139,27 @@ GetVersion(Thread*) return JMM_VERSION_1_0; } +uint64_t +getInputArgumentArray(Thread* t, uintptr_t*) +{ + object array = makeObjectArray + (t, type(t, Machine::StringType), t->m->argumentCount); + PROTECT(t, array); + + for (unsigned i = 0; i < t->m->argumentCount; ++i) { + object argument = makeString(t, t->m->arguments[i]); + set(t, array, ArrayBody + (i * BytesPerWord), argument); + } + + return reinterpret_cast(makeLocalReference(t, array)); +} + +jobjectArray JNICALL +GetInputArgumentArray(Thread* t) +{ + return reinterpret_cast(run(t, getInputArgumentArray, 0)); +} + jint JNICALL GetOptionalSupport(Thread*, jmmOptionalSupport* support) { @@ -5203,6 +5245,7 @@ EXPORT(JVM_GetManagement)(jint version) interface->GetBoolAttribute = GetBoolAttribute; interface->GetMemoryManagers = GetMemoryManagers; interface->GetMemoryPools = GetMemoryPools; + interface->GetInputArgumentArray = GetInputArgumentArray; return interface; } else { diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 6328b067a1..a18e8433c0 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -3337,15 +3337,24 @@ JNI_CreateJavaVM(Machine** m, Thread** t, void* args) const char** properties = static_cast (h->allocate(sizeof(const char*) * propertyCount)); + const char** propertyPointer = properties; + + const char** arguments = static_cast + (h->allocate(sizeof(const char*) * a->nOptions)); + + const char** argumentPointer = arguments; + for (int i = 0; i < a->nOptions; ++i) { if (strncmp(a->options[i].optionString, "-D", 2) == 0) { *(propertyPointer++) = a->options[i].optionString + 2; } + *(argumentPointer++) = a->options[i].optionString; } *m = new (h->allocate(sizeof(Machine))) - Machine(s, h, bf, af, p, c, properties, propertyCount); + Machine + (s, h, bf, af, p, c, properties, propertyCount, arguments, a->nOptions); *t = p->makeThread(*m, 0, 0); diff --git a/src/machine.cpp b/src/machine.cpp index a62fe7a7e6..9168c09019 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -2399,7 +2399,8 @@ namespace vm { Machine::Machine(System* system, Heap* heap, Finder* bootFinder, Finder* appFinder, Processor* processor, Classpath* classpath, - const char** properties, unsigned propertyCount): + const char** properties, unsigned propertyCount, + const char** arguments, unsigned argumentCount): vtable(&javaVMVTable), system(system), heapClient(new (heap->allocate(sizeof(HeapClient))) @@ -2415,6 +2416,8 @@ Machine::Machine(System* system, Heap* heap, Finder* bootFinder, jniReferences(0), properties(properties), propertyCount(propertyCount), + arguments(arguments), + argumentCount(argumentCount), activeCount(0), liveCount(0), daemonCount(0), @@ -2481,6 +2484,8 @@ Machine::dispose() heap->free(heapPool[i], ThreadHeapSizeInBytes); } + heap->free(arguments, sizeof(const char*) * argumentCount); + heap->free(properties, sizeof(const char*) * propertyCount); static_cast(heapClient)->dispose(); diff --git a/src/machine.h b/src/machine.h index db1e55426e..28a3a764f1 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1273,7 +1273,8 @@ class Machine { Machine(System* system, Heap* heap, Finder* bootFinder, Finder* appFinder, Processor* processor, Classpath* classpath, const char** properties, - unsigned propertyCount); + unsigned propertyCount, const char** arguments, + unsigned argumentCount); ~Machine() { dispose(); @@ -1295,6 +1296,8 @@ class Machine { Reference* jniReferences; const char** properties; unsigned propertyCount; + const char** arguments; + unsigned argumentCount; unsigned activeCount; unsigned liveCount; unsigned daemonCount; diff --git a/src/openjdk/my_management.c b/src/openjdk/my_management.c new file mode 100644 index 0000000000..7f117bf58b --- /dev/null +++ b/src/openjdk/my_management.c @@ -0,0 +1,2 @@ +#define JNI_OnLoad management_JNI_OnLoad +#include "management.c"