mirror of
https://github.com/corda/corda.git
synced 2025-01-21 12:05:08 +00:00
use JavaVMInitArgs instead of JDK1_1InitArgs in JNI_CreateJavaVM; support -Xbootclasspath option
This commit is contained in:
parent
17a42c5611
commit
920034e231
38
readme.txt
38
readme.txt
@ -176,40 +176,18 @@ extern "C" {
|
|||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
#ifdef JNI_VERSION_1_6
|
|
||||||
typedef struct JDK1_1InitArgs {
|
|
||||||
jint version;
|
|
||||||
|
|
||||||
char **properties;
|
|
||||||
jint checkSource;
|
|
||||||
jint nativeStackSize;
|
|
||||||
jint javaStackSize;
|
|
||||||
jint minHeapSize;
|
|
||||||
jint maxHeapSize;
|
|
||||||
jint verifyMode;
|
|
||||||
char *classpath;
|
|
||||||
|
|
||||||
jint (JNICALL *vfprintf)(FILE *fp, const char *format, va_list args);
|
|
||||||
void (JNICALL *exit)(jint code);
|
|
||||||
void (JNICALL *abort)(void);
|
|
||||||
|
|
||||||
jint enableClassGC;
|
|
||||||
jint enableVerboseGC;
|
|
||||||
jint disableAsyncGC;
|
|
||||||
jint verbose;
|
|
||||||
jboolean debugging;
|
|
||||||
jint debugPort;
|
|
||||||
} JDK1_1InitArgs;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int ac, const char** av)
|
main(int ac, const char** av)
|
||||||
{
|
{
|
||||||
JDK1_1InitArgs vmArgs;
|
JavaVMInitArgs vmArgs;
|
||||||
vmArgs.version = 0x00010001;
|
vmArgs.version = JNI_VERSION_1_2;
|
||||||
JNI_GetDefaultJavaVMInitArgs(&vmArgs);
|
vmArgs.nOptions = 1;
|
||||||
|
vmArgs.ignoreUnrecognized = JNI_TRUE;
|
||||||
|
|
||||||
vmArgs.classpath = const_cast<char*>("[bootJar]");
|
JavaVMOption options[vmArgs.nOptions];
|
||||||
|
vmArgs.options = options;
|
||||||
|
|
||||||
|
options[0].optionString = const_cast<char*>("-Djava.class.path=[bootJar]");
|
||||||
|
|
||||||
JavaVM* vm;
|
JavaVM* vm;
|
||||||
void* env;
|
void* env;
|
||||||
|
@ -23,8 +23,10 @@
|
|||||||
#undef JNIEXPORT
|
#undef JNIEXPORT
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
# define JNIEXPORT __declspec(dllexport)
|
# define JNIEXPORT __declspec(dllexport)
|
||||||
|
# define PATH_SEPARATOR ';'
|
||||||
#else
|
#else
|
||||||
# define JNIEXPORT __attribute__ ((visibility("default")))
|
# define JNIEXPORT __attribute__ ((visibility("default")))
|
||||||
|
# define PATH_SEPARATOR ':'
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __i386__
|
#ifdef __i386__
|
||||||
|
118
src/jnienv.cpp
118
src/jnienv.cpp
@ -1845,30 +1845,39 @@ IsSameObject(Thread* t, jobject a, jobject b)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct JDK1_1InitArgs {
|
struct JavaVMOption {
|
||||||
|
char* optionString;
|
||||||
|
void* extraInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JavaVMInitArgs {
|
||||||
jint version;
|
jint version;
|
||||||
|
|
||||||
const char** properties;
|
jint nOptions;
|
||||||
jint checkSource;
|
JavaVMOption* options;
|
||||||
jint nativeStackSize;
|
jboolean ignoreUnrecognized;
|
||||||
jint javaStackSize;
|
|
||||||
jint minHeapSize;
|
|
||||||
jint maxHeapSize;
|
|
||||||
jint verifyMode;
|
|
||||||
const char* classpath;
|
|
||||||
|
|
||||||
jint (JNICALL *vfprintf)(FILE* fp, const char* format, va_list args);
|
|
||||||
void (JNICALL *exit)(jint code);
|
|
||||||
void (JNICALL *abort)(void);
|
|
||||||
|
|
||||||
jint enableClassGC;
|
|
||||||
jint enableVerboseGC;
|
|
||||||
jint disableAsyncGC;
|
|
||||||
jint verbose;
|
|
||||||
jboolean debugging;
|
|
||||||
jint debugPort;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
parseSize(const char* s)
|
||||||
|
{
|
||||||
|
unsigned length = strlen(s);
|
||||||
|
char buffer[length + 1];
|
||||||
|
if (length == 0) {
|
||||||
|
return 0;
|
||||||
|
} else if (s[length - 1] == 'k') {
|
||||||
|
memcpy(buffer, s, length - 1);
|
||||||
|
buffer[length] = 0;
|
||||||
|
return atoi(buffer) * 1024;
|
||||||
|
} else if (s[length - 1] == 'm') {
|
||||||
|
memcpy(buffer, s, length - 1);
|
||||||
|
buffer[length] = 0;
|
||||||
|
return atoi(buffer) * 1024 * 1024;
|
||||||
|
} else {
|
||||||
|
return atoi(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
@ -2040,43 +2049,74 @@ populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable)
|
|||||||
|
|
||||||
} // namespace vm
|
} // namespace vm
|
||||||
|
|
||||||
extern "C" JNIEXPORT jint JNICALL
|
|
||||||
JNI_GetDefaultJavaVMInitArgs(void* args)
|
|
||||||
{
|
|
||||||
JDK1_1InitArgs* a = static_cast<JDK1_1InitArgs*>(args);
|
|
||||||
a->maxHeapSize = 128 * 1024 * 1024;
|
|
||||||
a->classpath = ".";
|
|
||||||
a->properties = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define BUILTINS_PROPERTY "avian.builtins"
|
#define BUILTINS_PROPERTY "avian.builtins"
|
||||||
#define BOOTSTRAP_PROPERTY "avian.bootstrap"
|
#define BOOTSTRAP_PROPERTY "avian.bootstrap"
|
||||||
|
#define CLASSPATH_PROPERTY "java.class.path"
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT jint JNICALL
|
||||||
|
JNI_GetDefaultJavaVMInitArgs(void*)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT jint JNICALL
|
extern "C" JNIEXPORT jint JNICALL
|
||||||
JNI_CreateJavaVM(Machine** m, Thread** t, void* args)
|
JNI_CreateJavaVM(Machine** m, Thread** t, void* args)
|
||||||
{
|
{
|
||||||
JDK1_1InitArgs* a = static_cast<JDK1_1InitArgs*>(args);
|
JavaVMInitArgs* a = static_cast<JavaVMInitArgs*>(args);
|
||||||
|
|
||||||
|
unsigned heapLimit = 0;
|
||||||
const char* builtins = 0;
|
const char* builtins = 0;
|
||||||
const char* bootLibrary = 0;
|
const char* bootLibrary = 0;
|
||||||
if (a->properties) {
|
const char* classpath = 0;
|
||||||
for (const char** p = a->properties; *p; ++p) {
|
const char* bootClasspath = 0;
|
||||||
if (strncmp(*p, BUILTINS_PROPERTY "=",
|
|
||||||
|
for (int i = 0; i < a->nOptions; ++i) {
|
||||||
|
if (strncmp(a->options[i].optionString, "-Xmx", 4) == 0) {
|
||||||
|
heapLimit = parseSize(a->options[i].optionString + 4);
|
||||||
|
} else if (strncmp(a->options[i].optionString,
|
||||||
|
"-Xbootclasspath:", 16) == 0)
|
||||||
|
{
|
||||||
|
bootClasspath = a->options[i].optionString + 16;
|
||||||
|
} else if (strncmp(a->options[i].optionString, "-D", 2) == 0) {
|
||||||
|
const char* p = a->options[i].optionString + 2;
|
||||||
|
if (strncmp(p, BUILTINS_PROPERTY "=",
|
||||||
sizeof(BUILTINS_PROPERTY)) == 0)
|
sizeof(BUILTINS_PROPERTY)) == 0)
|
||||||
{
|
{
|
||||||
builtins = (*p) + sizeof(BUILTINS_PROPERTY);
|
builtins = p + sizeof(BUILTINS_PROPERTY);
|
||||||
} else if (strncmp(*p, BOOTSTRAP_PROPERTY "=",
|
} else if (strncmp(p, BOOTSTRAP_PROPERTY "=",
|
||||||
sizeof(BOOTSTRAP_PROPERTY)) == 0)
|
sizeof(BOOTSTRAP_PROPERTY)) == 0)
|
||||||
{
|
{
|
||||||
bootLibrary = (*p) + sizeof(BOOTSTRAP_PROPERTY);
|
bootLibrary = p + sizeof(BOOTSTRAP_PROPERTY);
|
||||||
|
} else if (strncmp(p, CLASSPATH_PROPERTY "=",
|
||||||
|
sizeof(CLASSPATH_PROPERTY)) == 0)
|
||||||
|
{
|
||||||
|
classpath = p + sizeof(CLASSPATH_PROPERTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: add properties to VM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (heapLimit == 0) heapLimit = 128 * 1024 * 1024;
|
||||||
|
|
||||||
|
if (classpath == 0) classpath = ".";
|
||||||
|
|
||||||
|
unsigned bcpl = bootClasspath ? strlen(bootClasspath) : 0;
|
||||||
|
unsigned cpl = strlen(classpath);
|
||||||
|
|
||||||
|
unsigned classpathBufferSize = bcpl + cpl + 2;
|
||||||
|
char classpathBuffer[classpathBufferSize];
|
||||||
|
|
||||||
|
if (bootClasspath) {
|
||||||
|
snprintf(classpathBuffer, classpathBufferSize, "%s%c%s",
|
||||||
|
bootClasspath, PATH_SEPARATOR, classpath);
|
||||||
|
} else {
|
||||||
|
memcpy(classpathBuffer, classpath, cpl + 1);
|
||||||
|
}
|
||||||
|
|
||||||
System* s = makeSystem();
|
System* s = makeSystem();
|
||||||
Heap* h = makeHeap(s, a->maxHeapSize);
|
Heap* h = makeHeap(s, heapLimit);
|
||||||
Finder* f = makeFinder(s, a->classpath, bootLibrary);
|
Finder* f = makeFinder(s, classpathBuffer, bootLibrary);
|
||||||
Processor* p = makeProcessor(s, h);
|
Processor* p = makeProcessor(s, h);
|
||||||
|
|
||||||
*m = new (h->allocate(sizeof(Machine)))
|
*m = new (h->allocate(sizeof(Machine)))
|
||||||
|
109
src/main.cpp
109
src/main.cpp
@ -20,33 +20,6 @@
|
|||||||
# define PATH_SEPARATOR ':'
|
# define PATH_SEPARATOR ':'
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef JNI_VERSION_1_6
|
|
||||||
// todo: use JavaVMInitArgs instead
|
|
||||||
typedef struct JDK1_1InitArgs {
|
|
||||||
jint version;
|
|
||||||
|
|
||||||
char **properties;
|
|
||||||
jint checkSource;
|
|
||||||
jint nativeStackSize;
|
|
||||||
jint javaStackSize;
|
|
||||||
jint minHeapSize;
|
|
||||||
jint maxHeapSize;
|
|
||||||
jint verifyMode;
|
|
||||||
char *classpath;
|
|
||||||
|
|
||||||
jint (JNICALL *vfprintf)(FILE *fp, const char *format, va_list args);
|
|
||||||
void (JNICALL *exit)(jint code);
|
|
||||||
void (JNICALL *abort)(void);
|
|
||||||
|
|
||||||
jint enableClassGC;
|
|
||||||
jint enableVerboseGC;
|
|
||||||
jint disableAsyncGC;
|
|
||||||
jint verbose;
|
|
||||||
jboolean debugging;
|
|
||||||
jint debugPort;
|
|
||||||
} JDK1_1InitArgs;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -62,22 +35,25 @@ usageAndExit(const char* name)
|
|||||||
int
|
int
|
||||||
main(int ac, const char** av)
|
main(int ac, const char** av)
|
||||||
{
|
{
|
||||||
JDK1_1InitArgs vmArgs;
|
JavaVMInitArgs vmArgs;
|
||||||
vmArgs.version = 0x00010001;
|
vmArgs.version = JNI_VERSION_1_2;
|
||||||
JNI_GetDefaultJavaVMInitArgs(&vmArgs);
|
vmArgs.nOptions = 1;
|
||||||
|
vmArgs.ignoreUnrecognized = JNI_TRUE;
|
||||||
|
|
||||||
const char* class_ = 0;
|
const char* class_ = 0;
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
const char** argv = 0;
|
const char** argv = 0;
|
||||||
int propertyCount = 0;
|
const char* classpath = ".";
|
||||||
|
|
||||||
for (int i = 1; i < ac; ++i) {
|
for (int i = 1; i < ac; ++i) {
|
||||||
if (strcmp(av[i], "-cp") == 0) {
|
if (strcmp(av[i], "-cp") == 0
|
||||||
vmArgs.classpath = const_cast<char*>(av[++i]);
|
or strcmp(av[i], "-classpath") == 0)
|
||||||
} else if (strncmp(av[i], "-Xmx", 4) == 0) {
|
{
|
||||||
vmArgs.maxHeapSize = atoi(av[i] + 4);
|
classpath = av[++i];
|
||||||
} else if (strncmp(av[i], "-D", 2) == 0) {
|
} else if (strncmp(av[i], "-X", 2) == 0
|
||||||
++ propertyCount;
|
or strncmp(av[i], "-D", 2) == 0)
|
||||||
|
{
|
||||||
|
++ vmArgs.nOptions;
|
||||||
} else {
|
} else {
|
||||||
class_ = av[i++];
|
class_ = av[i++];
|
||||||
if (i < ac) {
|
if (i < ac) {
|
||||||
@ -88,35 +64,54 @@ main(int ac, const char** av)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BOOT_CLASSPATH
|
#ifdef BOOT_LIBRARY
|
||||||
unsigned size = sizeof(BOOT_CLASSPATH) + 1 + strlen(vmArgs.classpath);
|
++ vmArgs.nOptions;
|
||||||
char classpath[size];
|
|
||||||
snprintf(classpath, size, "%s%c%s",
|
|
||||||
BOOT_CLASSPATH, PATH_SEPARATOR, vmArgs.classpath);
|
|
||||||
vmArgs.classpath = classpath;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
JavaVMOption options[vmArgs.nOptions];
|
||||||
|
vmArgs.options = options;
|
||||||
|
|
||||||
|
#ifdef BOOT_CLASSPATH
|
||||||
|
unsigned classpathBufferSize
|
||||||
|
= sizeof(BOOT_CLASSPATH) + 1 + strlen(classpath);
|
||||||
|
char classpathBuffer[classpathBufferSize];
|
||||||
|
|
||||||
|
snprintf(classpathBuffer, classpathBufferSize, "%s%c%s",
|
||||||
|
BOOT_CLASSPATH, PATH_SEPARATOR, classpath);
|
||||||
|
classpath = classpathBuffer;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned optionIndex = 0;
|
||||||
|
|
||||||
#ifdef BOOT_LIBRARY
|
#ifdef BOOT_LIBRARY
|
||||||
const int BootPropertyCount = 1;
|
options[optionIndex++].optionString
|
||||||
#else
|
= const_cast<char*>("-Davian.bootstrap=" BOOT_LIBRARY);
|
||||||
const int BootPropertyCount = 0;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char* properties[propertyCount + BootPropertyCount + 1];
|
#define CLASSPATH_PROPERTY "-Djava.class.path="
|
||||||
properties[propertyCount + BootPropertyCount] = 0;
|
|
||||||
|
unsigned classpathSize = strlen(classpath);
|
||||||
|
unsigned classpathPropertyBufferSize
|
||||||
|
= sizeof(CLASSPATH_PROPERTY) + classpathSize;
|
||||||
|
|
||||||
|
char classpathPropertyBuffer[classpathPropertyBufferSize];
|
||||||
|
memcpy(classpathPropertyBuffer,
|
||||||
|
CLASSPATH_PROPERTY,
|
||||||
|
sizeof(CLASSPATH_PROPERTY) - 1);
|
||||||
|
memcpy(classpathPropertyBuffer + sizeof(CLASSPATH_PROPERTY) - 1,
|
||||||
|
classpath,
|
||||||
|
classpathSize + 1);
|
||||||
|
|
||||||
|
options[optionIndex++].optionString = classpathPropertyBuffer;
|
||||||
|
|
||||||
for (int i = 1; i < ac; ++i) {
|
for (int i = 1; i < ac; ++i) {
|
||||||
if (strncmp(av[i], "-D", 2) == 0) {
|
if (strncmp(av[i], "-X", 2) == 0
|
||||||
properties[--propertyCount] = av[i] + 2;
|
or strncmp(av[i], "-D", 2) == 0)
|
||||||
|
{
|
||||||
|
options[optionIndex++].optionString = const_cast<char*>(av[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BOOT_LIBRARY
|
|
||||||
properties[propertyCount + BootPropertyCount - 1]
|
|
||||||
= "avian.bootstrap=" BOOT_LIBRARY;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
vmArgs.properties = const_cast<char**>(properties);
|
|
||||||
|
|
||||||
if (class_ == 0) {
|
if (class_ == 0) {
|
||||||
usageAndExit(av[0]);
|
usageAndExit(av[0]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user