Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion com.oracle.max.vm.native/hosted/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "os.h"
#if !os_WINDOWS
#include <unistd.h>
#else
#include <windows.h>
#include <io.h>
#endif
#include "word.h"
#include "isa.h"
#include "jni.h"
#include <string.h>
#include <stdlib.h>
#include <errno.h>



JNIEXPORT void JNICALL
JVM_OnLoad(JavaVM *vm, char *options, void *arg)
Expand Down Expand Up @@ -54,7 +63,14 @@ Java_com_sun_max_platform_Platform_nativeGetOS(JNIEnv *env, jclass c)

JNIEXPORT jint JNICALL
Java_com_sun_max_platform_Platform_nativeGetPageSize(JNIEnv *env, jclass c) {
return (jint) sysconf(_SC_PAGESIZE);
#if os_WINDOWS
SYSTEM_INFO systemInfo = {0};
GetSystemInfo(&systemInfo);
return systemInfo.dwAllocationGranularity ; //Windows do not care about page alignment but about memory allocatio granularity

#else
return (jint) sysconf(_SC_PAGESIZE);
#endif
}


Expand Down
7 changes: 5 additions & 2 deletions com.oracle.max.vm.native/javatest/javatest.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ LIB = javatest

include $(PROJECT)/platform/platform.mk

SOURCES = jvmni.c tests.c threads.c jnitests.c

ifeq ($(OS),windows)
SOURCES = jvmni.c tests.c threads.c jnitests.c jvm.c jni.c threadLocals.c image.c log.c virtualMemory.c mutex.c c.c trap.c time.c jmm.c jvmti.c relocation.c signal.c dataio.c
else
SOURCES = jvmni.c tests.c threads.c jnitests.c
endif
SOURCE_DIRS = javatest jni platform hosted share substrate

include $(PROJECT)/share/share.mk
Expand Down
36 changes: 29 additions & 7 deletions com.oracle.max.vm.native/javatest/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
* JNI code for any of the JavaTester tests that use native methods.
*/
#include "os.h"

#if !os_WINDOWS
#include <pthread.h>
#else
#include <windows.h>
#endif
#include "jni.h"

JNIEXPORT void JNICALL
Expand Down Expand Up @@ -96,23 +99,42 @@ void upcall(jclass cls) {
(*env)->DeleteGlobalRef(env, cls);
(*vm)->DetachCurrentThread(vm);
}

#if os_WINDOWS
DWORD WINAPI thread_function(void *arguments) {//we prefer this signature in order to avoid compiler waring on Windows.
#else
void *thread_function(void *arguments) {
#endif
upcall((jclass) arguments);
return NULL;
#if os_WINDOWS
return 0;
#else
return NULL;
#endif
}

JNIEXPORT void JNICALL
Java_test_output_AttachThread_callHelloWorldOnAttachedThread(JNIEnv *env, jclass clazz) {
pthread_t thread_id;
pthread_attr_t attributes;

#if !os_WINDOWS
pthread_t thread_id;
pthread_attr_t attributes;

#endif
/* Convert argument to be a global handle as it is going to the new thread */
clazz = (*env)->NewGlobalRef(env, clazz);
void *arguments = clazz;
#if os_WINDOWS
LPVOID
#else
void *
#endif
arguments = clazz;
#if !os_WINDOWS

pthread_attr_init(&attributes);
pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_JOINABLE);
pthread_create(&thread_id, &attributes, thread_function, arguments);
pthread_attr_destroy(&attributes);
#else
CreateThread(NULL, 0, thread_function, arguments, 0, NULL);

#endif
}
4 changes: 4 additions & 0 deletions com.oracle.max.vm.native/launch/launch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ SOURCES = maxvm.c
SOURCE_DIRS = jni platform share substrate launch

include $(PROJECT)/platform/platform.mk
ifeq ($(OS),windows)
MAIN = maxvm.exe #some cp implementations for windows require .exe at the end, while other work without it

endif
include $(PROJECT)/share/share.mk

all : $(MAIN)
Expand Down
40 changes: 37 additions & 3 deletions com.oracle.max.vm.native/launch/maxvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "os.h"
#if os_WINDOWS
#include <windows.h>
char last_dl_error [100]; //emulating dlerror() function not available on Windows

#else
#include <dlfcn.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>

#include "os.h"
#include "maxine.h"

typedef int (*MaxineFunction)(int argc, char *argv[], char *executablePath);
Expand Down Expand Up @@ -58,6 +64,15 @@ typedef int (*MaxineFunction)(int argc, char *argv[], char *executablePath);
#include <CoreFoundation/CoreFoundation.h>
const CFNullRef initializeCoreFoundationOnMainThread;

#elif os_WINDOWS
#define LIBRARY_NAME "jvm.dll"
#define MAIN_EXTRA_ARGS
#define PROG_PATH argv[0]
char *dlerror(){


return last_dl_error;
}
#else
#define LIBRARY_NAME "libjvm.so"
#define MAIN_EXTRA_ARGS
Expand Down Expand Up @@ -108,23 +123,42 @@ int main(int argc, char *argv[] MAIN_EXTRA_ARGS) {
strncpy(libraryPath, programPath, prefixLength);
strcpy(libraryPath + prefixLength, LIBRARY_NAME);
#endif
#if os_WINDOWS
void *result = LoadLibraryA(libraryPath);
if (result==NULL) {
sprintf(last_dl_error, "dl function : LoadLibraryA error code : %lu", GetLastError ());
fprintf(stderr, "could not load %s: %s %s\n", LIBRARY_NAME, dlerror(), libraryPath);
exit(1);

}
MaxineFunction maxine = (MaxineFunction) GetProcAddress(result, "maxine");
if (maxine == 0) {
sprintf(last_dl_error, "dl function : LoadLibraryA error code : %lu", GetLastError ());
fprintf(stderr, "could not find symbol 'maxine' in %s: %s %s\n", LIBRARY_NAME, dlerror(), libraryPath);
exit(1);
}

return (*maxine)(argc, argv, NULL);

#else
void *handle = dlopen(libraryPath, RTLD_LAZY | RTLD_GLOBAL);
if (handle == 0) {
fprintf(stderr, "could not load %s: %s\n", LIBRARY_NAME, dlerror());
fprintf(stderr, "could not load %s: %s %s\n", LIBRARY_NAME, dlerror(), libraryPath);
exit(1);
}

MaxineFunction maxine = (MaxineFunction) dlsym(handle, "maxine");
if (maxine == 0) {
fprintf(stderr, "could not find symbol 'maxine' in %s: %s\n", LIBRARY_NAME, dlerror());
fprintf(stderr, "could not find symbol 'maxine' in %s: %s %s\n", LIBRARY_NAME, dlerror(), libraryPath);
exit(1);
}
#endif

#if os_DARWIN
return (*maxine)(argc, argv, programPath);
#else
free(libraryPath);

return (*maxine)(argc, argv, NULL);
#endif
}
7 changes: 6 additions & 1 deletion com.oracle.max.vm.native/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@
# testing, inspecting (browsing, profiling and debugging) and running a Maxine VM.

include platform/platform.mk
ifeq ($(OS),windows)
all : hosted substrate launch javatest
else
all : hosted substrate launch javatest tele

all : hosted substrate launch tele javatest

endif

hosted : build/$(OS)/hosted/makefile
$(AT) (cd build/$(OS)/hosted; $(MAKE) all)
Expand Down
2 changes: 1 addition & 1 deletion com.oracle.max.vm.native/platform/aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

void isa_canonicalizeTeleIntegerRegisters(isa_OsTeleIntegerRegisters os, isa_CanonicalIntegerRegisters c) {

#if os_LINUX
#if os_LINUX || os_WINDOWS
#define CANONICALIZE(reg) c->r##reg = (Word) os->regs[reg]
#else
#define CANONICALIZE(reg, ucReg) c_UNIMPLEMENTED()
Expand Down
2 changes: 1 addition & 1 deletion com.oracle.max.vm.native/platform/aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "word.h"

#if os_LINUX
#if (os_LINUX || os_WINDOWS)
# include <sys/ucontext.h>
# include <sys/user.h>
typedef struct user_regs_struct *aarch64_OsTeleIntegerRegisters;
Expand Down
6 changes: 3 additions & 3 deletions com.oracle.max.vm.native/platform/amd64.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void isa_canonicalizeTeleIntegerRegisters(isa_OsTeleIntegerRegisters os, isa_Can

#if os_DARWIN
#define CANONICALIZE(reg, ucReg) c->reg = (Word) os->__##reg
#elif os_LINUX || os_MAXVE
#elif os_LINUX || os_MAXVE || os_WINDOWS
#define CANONICALIZE(reg, ucReg) c->reg = (Word) os->reg
#elif os_SOLARIS
#define CANONICALIZE(reg, ucReg) c->reg = (Word) os[REG_##ucReg]
Expand Down Expand Up @@ -58,7 +58,7 @@ void isa_canonicalizeTeleIntegerRegisters(isa_OsTeleIntegerRegisters os, isa_Can
void isa_canonicalizeTeleFloatingPointRegisters(isa_OsTeleFloatingPointRegisters os, isa_CanonicalFloatingPointRegisters c) {
#if os_DARWIN
#define CANONICALIZE(reg) c->xmm##reg = (*((Word *) (&os->__fpu_xmm##reg)))
#elif os_LINUX
#elif os_LINUX || os_WINDOWS
#define CANONICALIZE(reg) c->xmm##reg = (Word) ((XMMRegister *) &os->xmm_space)[reg].low
#elif os_SOLARIS
#define CANONICALIZE(reg) c->xmm##reg = (Word) *((Word *) &os->fp_reg_set.fpchip_state.xmm[reg])
Expand Down Expand Up @@ -92,7 +92,7 @@ void isa_canonicalizeTeleStateRegisters(isa_OsTeleStateRegisters os, isa_Canonic
#if os_DARWIN
c->rip = (Word) os->__rip;
c->flags = (Word) os->__rflags;
#elif os_LINUX
#elif os_LINUX || os_WINDOWS
c->rip = (Word) os->rip;
c->flags = (Word) os->eflags;
#elif os_SOLARIS
Expand Down
16 changes: 16 additions & 0 deletions com.oracle.max.vm.native/platform/amd64.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,29 @@
Word low;
Word high;
} XMMRegister;
#elif os_WINDOWS
//# include <sys/ucontext.h>
# include "usercygwinamd64.h"
typedef struct user_regs_struct *amd64_OsTeleIntegerRegisters;
typedef struct user_fpregs_struct *amd64_OsTeleFloatingPointRegisters;
typedef struct user_regs_struct *amd64_OsTeleStateRegisters;
typedef struct {
Word low;
Word high;
} XMMRegister;
#elif os_SOLARIS
# include <sys/procfs.h>
typedef prgreg_t *amd64_OsTeleIntegerRegisters;
typedef prfpregset_t *amd64_OsTeleFloatingPointRegisters;
typedef prgreg_t *amd64_OsTeleStateRegisters;
#elif os_MAXVE
# include <maxve_db.h>
# include <maxve.h>
typedef struct db_regs* amd64_OsTeleIntegerRegisters;
typedef struct db_regs* amd64_OsTeleStateRegisters;
typedef struct db_regs* amd64_OsTeleFloatingPointRegisters;
#elif os_WINDOWS
# include <maxve_db.h>
# include <maxve.h>
typedef struct db_regs* amd64_OsTeleIntegerRegisters;
typedef struct db_regs* amd64_OsTeleStateRegisters;
Expand Down
6 changes: 3 additions & 3 deletions com.oracle.max.vm.native/platform/arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void isa_canonicalizeTeleIntegerRegisters(isa_OsTeleIntegerRegisters os, isa_Can

#if os_DARWIN
#define CANONICALIZE(reg, ucReg) c->reg = (Word) os->__##reg
#elif os_LINUX || os_MAXVE
#elif os_LINUX || os_MAXVE || os_WINDOWS
#ifdef __arm__
#define CANONICALIZE(reg, intpos) c->reg = (Word) os->uregs[intpos]
#else
Expand Down Expand Up @@ -79,7 +79,7 @@ void isa_canonicalizeTeleIntegerRegisters(isa_OsTeleIntegerRegisters os, isa_Can
void isa_canonicalizeTeleFloatingPointRegisters(isa_OsTeleFloatingPointRegisters os, isa_CanonicalFloatingPointRegisters c) {
#if os_DARWIN
#define CANONICALIZE(reg) c->xmm##reg = (*((Word *) (&os->__fpu_xmm##reg)))
#elif os_LINUX
#elif os_LINUX || os_WINDOWS
#define CANONICALIZE(reg) c->xmm##reg = (Word) ((XMMRegister *) &os->xmm_space)[reg].low
#elif os_SOLARIS
#define CANONICALIZE(reg) c->xmm##reg = (Word) *((Word *) &os->fp_reg_set.fpchip_state.xmm[reg])
Expand Down Expand Up @@ -116,7 +116,7 @@ void isa_canonicalizeTeleStateRegisters(isa_OsTeleStateRegisters os, isa_Canonic
#if os_DARWIN
c->rip = (Word) os->__rip;
c->flags = (Word) os->__rflags;
#elif os_LINUX
#elif os_LINUX || os_WINDOWS
#ifdef __arm__
log_println("ARM: isa_canonicalizeTeleStateRegisters is not implemented!");
#else
Expand Down
Loading