Merge branch 'master' into jdk7

Conflicts:
	makefile
This commit is contained in:
Joel Dice 2012-05-04 11:33:16 -06:00
commit 19de383aae
12 changed files with 286 additions and 116 deletions

View File

@ -18,9 +18,11 @@ build-platform := \
| sed 's/^cygwin.*$$/cygwin/') | sed 's/^cygwin.*$$/cygwin/')
arch = $(build-arch) arch = $(build-arch)
target-arch = $(arch)
bootimage-platform = \ bootimage-platform = \
$(subst cygwin,windows,$(subst mingw32,windows,$(build-platform))) $(subst cygwin,windows,$(subst mingw32,windows,$(build-platform)))
platform = $(bootimage-platform) platform = $(bootimage-platform)
target-platform = $(platform)
mode = fast mode = fast
process = compile process = compile
@ -190,8 +192,10 @@ endif
build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \ build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \
"-I$(JAVA_HOME)/include/linux" -I$(src) -pthread "-I$(JAVA_HOME)/include/linux" -I$(src) -pthread
converter-cflags = -D__STDC_CONSTANT_MACROS -Isrc/binaryToObject \ converter-cflags = -D__STDC_CONSTANT_MACROS -Isrc/binaryToObject -Isrc/ \
-fno-rtti -fno-exceptions -fno-rtti -fno-exceptions \
-DAVIAN_TARGET_ARCH=AVIAN_ARCH_UNKNOWN \
-DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_UNKNOWN
cflags = $(build-cflags) cflags = $(build-cflags)
@ -231,6 +235,7 @@ endif
ifeq ($(arch),i386) ifeq ($(arch),i386)
pointer-size = 4 pointer-size = 4
endif endif
ifeq ($(arch),powerpc) ifeq ($(arch),powerpc)
asm = powerpc asm = powerpc
pointer-size = 4 pointer-size = 4
@ -249,9 +254,11 @@ ifeq ($(arch),powerpc)
endif endif
endif endif
endif endif
ifeq ($(arch),arm) ifeq ($(arch),arm)
asm = arm asm = arm
pointer-size = 4 pointer-size = 4
ifeq ($(build-platform),darwin) ifeq ($(build-platform),darwin)
ios = true ios = true
else else
@ -281,10 +288,6 @@ ifeq ($(ios),true)
cflags += -DAVIAN_IOS cflags += -DAVIAN_IOS
endif endif
ifeq ($(platform),linux)
bootimage-cflags += -DTARGET_PLATFORM_LINUX
endif
ifeq ($(build-platform),darwin) ifeq ($(build-platform),darwin)
build-cflags = $(common-cflags) -fPIC -fvisibility=hidden -I$(src) build-cflags = $(common-cflags) -fPIC -fvisibility=hidden -I$(src)
cflags += -I/System/Library/Frameworks/JavaVM.framework/Headers/ cflags += -I/System/Library/Frameworks/JavaVM.framework/Headers/
@ -292,8 +295,6 @@ ifeq ($(build-platform),darwin)
endif endif
ifeq ($(platform),darwin) ifeq ($(platform),darwin)
bootimage-cflags += -DTARGET_PLATFORM_DARWIN
ifeq (${OSX_SDK_SYSROOT},) ifeq (${OSX_SDK_SYSROOT},)
OSX_SDK_SYSROOT = 10.4u OSX_SDK_SYSROOT = 10.4u
endif endif
@ -371,8 +372,6 @@ ifeq ($(platform),darwin)
endif endif
ifeq ($(platform),windows) ifeq ($(platform),windows)
bootimage-cflags += -DTARGET_PLATFORM_WINDOWS
inc = "$(win32)/include" inc = "$(win32)/include"
lib = "$(win32)/lib" lib = "$(win32)/lib"
@ -385,7 +384,7 @@ ifeq ($(platform),windows)
exe-suffix = .exe exe-suffix = .exe
lflags = -L$(lib) $(common-lflags) -lws2_32 -liphlpapi -mwindows -mconsole lflags = -L$(lib) $(common-lflags) -lws2_32 -liphlpapi -mwindows -mconsole
cflags = -I$(inc) $(common-cflags) -DWINVER=0x0500 -DTARGET_PLATFORM_WINDOWS cflags = -I$(inc) $(common-cflags) -DWINVER=0x0500
ifeq (,$(filter mingw32 cygwin,$(build-platform))) ifeq (,$(filter mingw32 cygwin,$(build-platform)))
openjdk-extra-cflags += -I$(src)/openjdk/caseSensitive openjdk-extra-cflags += -I$(src)/openjdk/caseSensitive
@ -494,7 +493,7 @@ ifdef msvc
-DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \ -DAVIAN_EMBED_PREFIX=\"$(embed-prefix)\" \
-Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I"$(build)" \ -Fd$(build)/$(name).pdb -I"$(zlib)/include" -I$(src) -I"$(build)" \
-I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \ -I"$(windows-java-home)/include" -I"$(windows-java-home)/include/win32" \
-DTARGET_BYTES_PER_WORD=$(pointer-size) -DTARGET_PLATFORM_WINDOWS -DTARGET_BYTES_PER_WORD=$(pointer-size)
shared = -dll shared = -dll
lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \ lflags = -nologo -LIBPATH:"$(zlib)/lib" -DEFAULTLIB:ws2_32 \
-DEFAULTLIB:zlib -MANIFEST -debug -DEFAULTLIB:zlib -MANIFEST -debug
@ -585,10 +584,7 @@ bootimage-generator-objects = \
$(call cpp-objects,$(bootimage-generator-sources),$(src),$(build)) $(call cpp-objects,$(bootimage-generator-sources),$(src),$(build))
bootimage-generator = $(build)/bootimage-generator bootimage-generator = $(build)/bootimage-generator
bootimage-bin = $(build)/bootimage.bin
bootimage-object = $(build)/bootimage-bin.o bootimage-object = $(build)/bootimage-bin.o
codeimage-bin = $(build)/codeimage.bin
codeimage-object = $(build)/codeimage-bin.o codeimage-object = $(build)/codeimage-bin.o
ifeq ($(bootimage),true) ifeq ($(bootimage),true)
@ -630,13 +626,16 @@ converter-depends = \
converter-sources = \ converter-sources = \
$(src)/binaryToObject/main.cpp \
$(src)/binaryToObject/tools.cpp \ $(src)/binaryToObject/tools.cpp \
$(src)/binaryToObject/elf.cpp \ $(src)/binaryToObject/elf.cpp \
$(src)/binaryToObject/mach-o.cpp \ $(src)/binaryToObject/mach-o.cpp \
$(src)/binaryToObject/pe.cpp $(src)/binaryToObject/pe.cpp
converter-tool-sources = \
$(src)/binaryToObject/main.cpp
converter-objects = $(call cpp-objects,$(converter-sources),$(src),$(build)) converter-objects = $(call cpp-objects,$(converter-sources),$(src),$(build))
converter-tool-objects = $(call cpp-objects,$(converter-tool-sources),$(src),$(build))
converter = $(build)/binaryToObject/binaryToObject converter = $(build)/binaryToObject/binaryToObject
static-library = $(build)/lib$(name).a static-library = $(build)/lib$(name).a
@ -707,6 +706,34 @@ ifeq ($(tails),true)
extra.Tails extra.Tails
endif endif
ifeq ($(target-arch),i386)
cflags += -DAVIAN_TARGET_ARCH=AVIAN_ARCH_X86
endif
ifeq ($(target-arch),x86_64)
cflags += -DAVIAN_TARGET_ARCH=AVIAN_ARCH_X86_64
endif
ifeq ($(target-arch),powerpc)
cflags += -DAVIAN_TARGET_ARCH=AVIAN_ARCH_POWERPC
endif
ifeq ($(target-arch),arm)
cflags += -DAVIAN_TARGET_ARCH=AVIAN_ARCH_ARM
endif
ifeq ($(target-platform),linux)
cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_LINUX
endif
ifeq ($(target-platform),windows)
cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_WINDOWS
endif
ifeq ($(target-platform),darwin)
cflags += -DAVIAN_TARGET_PLATFORM=AVIAN_PLATFORM_DARWIN
endif
class-name = $(patsubst $(1)/%.class,%,$(2)) class-name = $(patsubst $(1)/%.class,%,$(2))
class-names = $(foreach x,$(2),$(call class-name,$(1),$(x))) class-names = $(foreach x,$(2),$(call class-name,$(1),$(x)))
@ -842,11 +869,11 @@ $(boot-object): $(boot-source)
$(boot-javahome-object): $(src)/boot-javahome.cpp $(boot-javahome-object): $(src)/boot-javahome.cpp
$(compile-object) $(compile-object)
$(converter-objects): $(build)/binaryToObject/%.o: $(src)/binaryToObject/%.cpp $(converter-depends) $(converter-objects) $(converter-tool-objects): $(build)/binaryToObject/%.o: $(src)/binaryToObject/%.cpp $(converter-depends)
@mkdir -p $(dir $(@)) @mkdir -p $(dir $(@))
$(build-cxx) $(converter-cflags) -c $(<) -o $(@) $(build-cxx) $(converter-cflags) -c $(<) -o $(@)
$(converter): $(converter-objects) $(converter): $(converter-objects) $(converter-tool-objects)
$(build-cc) $(^) -g -o $(@) $(build-cc) $(^) -g -o $(@)
$(build)/classpath.jar: $(classpath-dep) $(classpath-jar-dep) $(build)/classpath.jar: $(classpath-dep) $(classpath-jar-dep)
@ -888,20 +915,8 @@ $(static-library): $(vm-objects) $(classpath-objects) $(vm-heapwalk-objects) \
$(ar) cru $(@) $(^) $(ar) cru $(@) $(^)
$(ranlib) $(@) $(ranlib) $(@)
$(bootimage-bin): $(bootimage-generator) $(bootimage-object) $(codeimage-object): $(bootimage-generator)
$(<) $(classpath-build) $(@) $(codeimage-bin) $(<) $(classpath-build) $(bootimage-object) $(codeimage-object)
$(bootimage-object): $(bootimage-bin) $(converter)
@echo "creating $(@)"
$(converter) $(<) $(@) _binary_bootimage_bin_start \
_binary_bootimage_bin_end $(platform) $(arch) $(pointer-size) \
writable
$(codeimage-object): $(bootimage-bin) $(converter)
@echo "creating $(@)"
$(converter) $(codeimage-bin) $(@) _binary_codeimage_bin_start \
_binary_codeimage_bin_end $(platform) $(arch) $(pointer-size) \
executable
executable-objects = $(vm-objects) $(classpath-objects) $(driver-object) \ executable-objects = $(vm-objects) $(classpath-objects) $(driver-object) \
$(vm-heapwalk-objects) $(boot-object) $(vm-classpath-objects) \ $(vm-heapwalk-objects) $(boot-object) $(vm-classpath-objects) \
@ -924,10 +939,13 @@ else
endif endif
$(strip) $(strip-all) $(@) $(strip) $(strip-all) $(@)
$(bootimage-generator): $(bootimage-generator): $(bootimage-generator-objects)
echo arch=$(arch) platform=$(platform)
$(MAKE) mode=$(mode) \ $(MAKE) mode=$(mode) \
arch=$(build-arch) \ arch=$(build-arch) \
target-arch=$(arch) \
platform=$(bootimage-platform) \ platform=$(bootimage-platform) \
target-platform=$(platform) \
openjdk=$(openjdk) \ openjdk=$(openjdk) \
openjdk-src=$(openjdk-src) \ openjdk-src=$(openjdk-src) \
bootimage-generator= \ bootimage-generator= \
@ -938,7 +956,7 @@ $(bootimage-generator):
$(build-bootimage-generator): \ $(build-bootimage-generator): \
$(vm-objects) $(classpath-object) $(classpath-objects) \ $(vm-objects) $(classpath-object) $(classpath-objects) \
$(heapwalk-objects) $(bootimage-generator-objects) $(heapwalk-objects) $(bootimage-generator-objects) $(converter-objects)
@echo "linking $(@)" @echo "linking $(@)"
ifeq ($(platform),windows) ifeq ($(platform),windows)
ifdef msvc ifdef msvc

View File

@ -568,19 +568,7 @@ Step 6: Build the boot and code images.
$ ../build/linux-i386-bootimage/bootimage-generator stage2 \ $ ../build/linux-i386-bootimage/bootimage-generator stage2 \
bootimage.bin codeimage.bin bootimage.bin codeimage.bin
Step 7: Make an object file out of the boot and code images. Step 7: Write a driver which starts the VM and runs the desired main
$ ../build/linux-i386-bootimage/binaryToObject \
bootimage.bin bootimage-bin.o \
_binary_bootimage_bin_start _binary_bootimage_bin_end \
linux i386 8 writable
$ ../build/linux-i386-bootimage/binaryToObject \
codeimage.bin codeimage-bin.o \
_binary_codeimage_bin_start _binary_codeimage_bin_end \
linux i386 8 executable
Step 8: Write a driver which starts the VM and runs the desired main
method. Note the bootimageBin function, which will be called by the method. Note the bootimageBin function, which will be called by the
VM to get a handle to the embedded boot image. We tell the VM about VM to get a handle to the embedded boot image. We tell the VM about
this function via the "avian.bootimage" property. this function via the "avian.bootimage" property.

View File

@ -18,9 +18,9 @@
#include <windows.h> #include <windows.h>
#else #else
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h>
#endif #endif
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h>
#include "tools.h" #include "tools.h"
@ -45,18 +45,17 @@ writeObject(uint8_t* data, size_t size, OutputStream* out, const char* startName
const char* architecture, unsigned alignment, bool writable, const char* architecture, unsigned alignment, bool writable,
bool executable) bool executable)
{ {
Platform* platform = Platform::getPlatform(PlatformInfo(os, architecture)); Platform* platform = Platform::getPlatform(PlatformInfo(PlatformInfo::osFromString(os), PlatformInfo::archFromString(architecture)));
if(!platform) { if(!platform) {
fprintf(stderr, "unsupported platform: %s/%s\n", os, architecture); fprintf(stderr, "unsupported platform: %s/%s\n", os, architecture);
return false; return false;
} }
SymbolInfo symbols[2]; SymbolInfo symbols[] = {
symbols[0].name = startName; SymbolInfo(0, startName),
symbols[0].addr = 0; SymbolInfo(size, endName)
symbols[1].name = endName; };
symbols[1].addr = size;
unsigned accessFlags = (writable ? Platform::Writable : 0) | (executable ? Platform::Executable : 0); unsigned accessFlags = (writable ? Platform::Writable : 0) | (executable ? Platform::Executable : 0);

View File

@ -121,9 +121,7 @@ public:
void writeHeader(OutputStream* out) { void writeHeader(OutputStream* out) {
header.NumberOfSections = sectionCount; header.NumberOfSections = sectionCount;
header.PointerToSymbolTable = dataStart + dataOffset; header.PointerToSymbolTable = dataStart + dataOffset;
printf("symbol table start: 0x%x\n", header.PointerToSymbolTable);
dataOffset = pad(dataOffset + symbolCount * sizeof(IMAGE_SYMBOL)); dataOffset = pad(dataOffset + symbolCount * sizeof(IMAGE_SYMBOL));
printf("string table start: 0x%x\n", dataStart + dataOffset);
header.NumberOfSymbols = symbolCount; header.NumberOfSymbols = symbolCount;
out->writeChunk(&header, sizeof(IMAGE_FILE_HEADER)); out->writeChunk(&header, sizeof(IMAGE_FILE_HEADER));
} }
@ -188,7 +186,6 @@ public:
void writeHeader(OutputStream* out) { void writeHeader(OutputStream* out) {
header.PointerToRawData = dataOffset + file.dataStart; header.PointerToRawData = dataOffset + file.dataStart;
printf("section %s: data at 0x%x, ending at 0x%x\n", header.Name, header.PointerToRawData, header.PointerToRawData + header.SizeOfRawData);
out->writeChunk(&header, sizeof(IMAGE_SECTION_HEADER)); out->writeChunk(&header, sizeof(IMAGE_SECTION_HEADER));
} }

View File

@ -11,6 +11,9 @@
#ifndef AVIAN_TOOLS_H_ #ifndef AVIAN_TOOLS_H_
#define AVIAN_TOOLS_H_ #define AVIAN_TOOLS_H_
#include <stdlib.h>
#include "environment.h"
namespace avian { namespace avian {
namespace tools { namespace tools {
@ -41,6 +44,10 @@ public:
size_t length; size_t length;
String(const char* text); String(const char* text);
inline String(const char* text, size_t length):
text(text),
length(length) {}
}; };
class SymbolInfo { class SymbolInfo {
@ -84,6 +91,10 @@ public:
items(items), items(items),
count(count) {} count(count) {}
inline Slice(const Slice<T>& copy):
items(copy.items),
count(copy.count) {}
inline T* begin() { inline T* begin() {
return items; return items;
} }
@ -93,14 +104,46 @@ public:
} }
}; };
template<class T>
class DynamicArray : public Slice<T> {
public:
size_t capacity;
DynamicArray():
Slice<T>((T*)malloc(10 * sizeof(T)), 0),
capacity(10) {}
~DynamicArray() {
free(Slice<T>::items);
}
void ensure(size_t more) {
if(Slice<T>::count + more > capacity) {
capacity = capacity * 2 + more;
Slice<T>::items = (T*)realloc(Slice<T>::items, capacity * sizeof(T));
}
}
void add(const T& item) {
ensure(1);
Slice<T>::items[Slice<T>::count++] = item;
}
};
class PlatformInfo { class PlatformInfo {
public: public:
enum OperatingSystem { enum OperatingSystem {
Linux, Windows, Darwin, UnknownOS Linux = AVIAN_PLATFORM_LINUX,
Windows = AVIAN_PLATFORM_WINDOWS,
Darwin = AVIAN_PLATFORM_DARWIN,
UnknownOS = AVIAN_PLATFORM_UNKNOWN
}; };
enum Architecture { enum Architecture {
x86, x86_64, PowerPC, Arm, UnknownArch x86 = AVIAN_ARCH_X86,
x86_64 = AVIAN_ARCH_X86_64,
PowerPC = AVIAN_ARCH_POWERPC,
Arm = AVIAN_ARCH_ARM,
UnknownArch = AVIAN_ARCH_UNKNOWN
}; };
const OperatingSystem os; const OperatingSystem os;
@ -113,10 +156,6 @@ public:
os(os), os(os),
arch(arch) {} arch(arch) {}
inline PlatformInfo(const char* os, const char* arch):
os(osFromString(os)),
arch(archFromString(arch)) {}
inline bool operator == (const PlatformInfo& other) { inline bool operator == (const PlatformInfo& other) {
return os == other.os && arch == other.arch; return os == other.os && arch == other.arch;
} }

View File

@ -16,12 +16,14 @@
#include "stream.h" #include "stream.h"
#include "assembler.h" #include "assembler.h"
#include "target.h" #include "target.h"
#include "binaryToObject/tools.h"
// since we aren't linking against libstdc++, we must implement this // since we aren't linking against libstdc++, we must implement this
// ourselves: // ourselves:
extern "C" void __cxa_pure_virtual(void) { abort(); } extern "C" void __cxa_pure_virtual(void) { abort(); }
using namespace vm; using namespace vm;
using namespace avian::tools;
namespace { namespace {
@ -1283,7 +1285,7 @@ targetThunk(BootImage::Thunk t)
} }
void void
writeBootImage2(Thread* t, FILE* bootimageOutput, FILE* codeOutput, writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutput,
BootImage* image, uint8_t* code, const char* className, BootImage* image, uint8_t* code, const char* className,
const char* methodName, const char* methodSpec) const char* methodName, const char* methodSpec)
{ {
@ -1292,6 +1294,31 @@ writeBootImage2(Thread* t, FILE* bootimageOutput, FILE* codeOutput,
Zone zone(t->m->system, t->m->heap, 64 * 1024); Zone zone(t->m->system, t->m->heap, 64 * 1024);
class MyCompilationHandler : public Processor::CompilationHandler {
public:
virtual void compiled(const void* code, unsigned size UNUSED, unsigned frameSize UNUSED, const char* class_, const char* name, const char* spec) {
size_t classLen = strlen(class_);
size_t nameLen = strlen(name);
size_t specLen = strlen(spec);
char* completeName = (char*)malloc(classLen + nameLen + specLen + 2);
sprintf(completeName, "%s.%s%s", class_, name, spec);
uint64_t offset = reinterpret_cast<uint64_t>(code) - codeOffset;
symbols.add(SymbolInfo(offset, completeName));
// printf("%ld %ld %s.%s%s\n", offset, offset + size, class_, name, spec);
}
virtual void dispose() {}
DynamicArray<SymbolInfo> symbols;
uint64_t codeOffset;
MyCompilationHandler(uint64_t codeOffset):
codeOffset(codeOffset) {}
} compilationHandler(reinterpret_cast<uint64_t>(code));
t->m->processor->addCompilationHandler(&compilationHandler);
object classPoolMap; object classPoolMap;
object typeMaps; object typeMaps;
object constants; object constants;
@ -1578,6 +1605,8 @@ writeBootImage2(Thread* t, FILE* bootimageOutput, FILE* codeOutput,
image->bootClassCount, image->stringCount, image->callCount, image->bootClassCount, image->stringCount, image->callCount,
image->heapSize, image->codeSize); image->heapSize, image->codeSize);
Buffer bootimageData;
if (true) { if (true) {
{ BootImage targetImage; { BootImage targetImage;
@ -1594,19 +1623,15 @@ writeBootImage2(Thread* t, FILE* bootimageOutput, FILE* codeOutput,
#include "bootimage-fields.cpp" #include "bootimage-fields.cpp"
#undef THUNK_FIELD #undef THUNK_FIELD
fwrite(&targetImage, sizeof(BootImage), 1, bootimageOutput); bootimageData.write(&targetImage, sizeof(BootImage));
} }
fwrite(bootClassTable, image->bootClassCount * sizeof(unsigned), 1, bootimageData.write(bootClassTable, image->bootClassCount * sizeof(unsigned));
bootimageOutput); bootimageData.write(appClassTable, image->appClassCount * sizeof(unsigned));
fwrite(appClassTable, image->appClassCount * sizeof(unsigned), 1, bootimageData.write(stringTable, image->stringCount * sizeof(unsigned));
bootimageOutput); bootimageData.write(callTable, image->callCount * sizeof(unsigned) * 2);
fwrite(stringTable, image->stringCount * sizeof(unsigned), 1,
bootimageOutput);
fwrite(callTable, image->callCount * sizeof(unsigned) * 2, 1,
bootimageOutput);
unsigned offset = sizeof(BootImage) unsigned offset = sizeof(BootImage)
+ (image->bootClassCount * sizeof(unsigned)) + (image->bootClassCount * sizeof(unsigned))
+ (image->appClassCount * sizeof(unsigned)) + (image->appClassCount * sizeof(unsigned))
+ (image->stringCount * sizeof(unsigned)) + (image->stringCount * sizeof(unsigned))
@ -1614,24 +1639,46 @@ writeBootImage2(Thread* t, FILE* bootimageOutput, FILE* codeOutput,
while (offset % TargetBytesPerWord) { while (offset % TargetBytesPerWord) {
uint8_t c = 0; uint8_t c = 0;
fwrite(&c, 1, 1, bootimageOutput); bootimageData.write(&c, 1);
++ offset; ++ offset;
} }
fwrite(heapMap, pad(heapMapSize(image->heapSize), TargetBytesPerWord), 1, bootimageData.write(heapMap, pad(heapMapSize(image->heapSize), TargetBytesPerWord));
bootimageOutput);
fwrite(heap, pad(image->heapSize, TargetBytesPerWord), 1, bootimageOutput); bootimageData.write(heap, pad(image->heapSize, TargetBytesPerWord));
fwrite(code, pad(image->codeSize, TargetBytesPerWord), 1, codeOutput); // fwrite(code, pad(image->codeSize, TargetBytesPerWord), 1, codeOutput);
Platform* platform = Platform::getPlatform(PlatformInfo((PlatformInfo::OperatingSystem)AVIAN_TARGET_PLATFORM, (PlatformInfo::Architecture)AVIAN_TARGET_ARCH));
// if(!platform) {
// fprintf(stderr, "unsupported platform: %s/%s\n", os, architecture);
// return false;
// }
SymbolInfo bootimageSymbols[] = {
SymbolInfo(0, "_binary_bootimage_bin_start"),
SymbolInfo(bootimageData.length, "_binary_bootimage_bin_end")
};
platform->writeObject(bootimageOutput, Slice<SymbolInfo>(bootimageSymbols, 2), Slice<const uint8_t>(bootimageData.data, bootimageData.length), Platform::Writable, TargetBytesPerWord);
compilationHandler.symbols.add(SymbolInfo(0, strdup("_binary_codeimage_bin_start")));
compilationHandler.symbols.add(SymbolInfo(image->codeSize, strdup("_binary_codeimage_bin_end")));
platform->writeObject(codeOutput, Slice<SymbolInfo>(compilationHandler.symbols), Slice<const uint8_t>(code, image->codeSize), Platform::Executable, TargetBytesPerWord);
for(SymbolInfo* sym = compilationHandler.symbols.begin(); sym != compilationHandler.symbols.end(); sym++) {
free(const_cast<void*>((const void*)sym->name.text));
}
} }
} }
uint64_t uint64_t
writeBootImage(Thread* t, uintptr_t* arguments) writeBootImage(Thread* t, uintptr_t* arguments)
{ {
FILE* bootimageOutput = reinterpret_cast<FILE*>(arguments[0]); OutputStream* bootimageOutput = reinterpret_cast<OutputStream*>(arguments[0]);
FILE* codeOutput = reinterpret_cast<FILE*>(arguments[1]); OutputStream* codeOutput = reinterpret_cast<OutputStream*>(arguments[1]);
BootImage* image = reinterpret_cast<BootImage*>(arguments[2]); BootImage* image = reinterpret_cast<BootImage*>(arguments[2]);
uint8_t* code = reinterpret_cast<uint8_t*>(arguments[3]); uint8_t* code = reinterpret_cast<uint8_t*>(arguments[3]);
const char* className = reinterpret_cast<const char*>(arguments[4]); const char* className = reinterpret_cast<const char*>(arguments[4]);
@ -1684,20 +1731,20 @@ main(int ac, const char** av)
enter(t, Thread::ActiveState); enter(t, Thread::ActiveState);
enter(t, Thread::IdleState); enter(t, Thread::IdleState);
FILE* bootimageOutput = vm::fopen(av[2], "wb"); FileOutputStream bootimageOutput(av[2]);
if (bootimageOutput == 0) { if (!bootimageOutput.isValid()) {
fprintf(stderr, "unable to open %s\n", av[2]); fprintf(stderr, "unable to open %s\n", av[2]);
return -1; return -1;
} }
FILE* codeOutput = vm::fopen(av[3], "wb"); FileOutputStream codeOutput(av[3]);
if (codeOutput == 0) { if (!codeOutput.isValid()) {
fprintf(stderr, "unable to open %s\n", av[3]); fprintf(stderr, "unable to open %s\n", av[3]);
return -1; return -1;
} }
uintptr_t arguments[] = { reinterpret_cast<uintptr_t>(bootimageOutput), uintptr_t arguments[] = { reinterpret_cast<uintptr_t>(&bootimageOutput),
reinterpret_cast<uintptr_t>(codeOutput), reinterpret_cast<uintptr_t>(&codeOutput),
reinterpret_cast<uintptr_t>(&image), reinterpret_cast<uintptr_t>(&image),
reinterpret_cast<uintptr_t>(code), reinterpret_cast<uintptr_t>(code),
reinterpret_cast<uintptr_t>(ac > 4 ? av[4] : 0), reinterpret_cast<uintptr_t>(ac > 4 ? av[4] : 0),
@ -1706,9 +1753,6 @@ main(int ac, const char** av)
run(t, writeBootImage, arguments); run(t, writeBootImage, arguments);
fclose(codeOutput);
fclose(bootimageOutput);
if (t->exception) { if (t->exception) {
printTrace(t, t->exception); printTrace(t, t->exception);
return -1; return -1;

View File

@ -332,7 +332,8 @@ extern "C" JNIEXPORT int64_t JNICALL
Avian_sun_misc_Unsafe_allocateMemory Avian_sun_misc_Unsafe_allocateMemory
(Thread* t, object, uintptr_t* arguments) (Thread* t, object, uintptr_t* arguments)
{ {
void* p = malloc(arguments[1]); int64_t size; memcpy(&size, arguments + 1, 8);
void* p = malloc(size);
if (p) { if (p) {
return reinterpret_cast<int64_t>(p); return reinterpret_cast<int64_t>(p);
} else { } else {
@ -344,9 +345,9 @@ extern "C" JNIEXPORT void JNICALL
Avian_sun_misc_Unsafe_freeMemory Avian_sun_misc_Unsafe_freeMemory
(Thread*, object, uintptr_t* arguments) (Thread*, object, uintptr_t* arguments)
{ {
void* p = reinterpret_cast<void*>(arguments[1]); int64_t p; memcpy(&p, arguments + 1, 8);
if (p) { if (p) {
free(p); free(reinterpret_cast<void*>(p));
} }
} }

View File

@ -6149,25 +6149,7 @@ FILE* compileLog = 0;
void void
logCompile(MyThread* t, const void* code, unsigned size, const char* class_, logCompile(MyThread* t, const void* code, unsigned size, const char* class_,
const char* name, const char* spec) const char* name, const char* spec);
{
static bool open = false;
if (not open) {
open = true;
const char* path = findProperty(t, "avian.jit.log");
if (path) {
compileLog = vm::fopen(path, "wb");
} else if (DebugCompile) {
compileLog = stderr;
}
}
if (compileLog) {
fprintf(compileLog, "%p %p %s.%s%s\n",
code, static_cast<const uint8_t*>(code) + size,
class_, name, spec);
}
}
int int
resolveIpForwards(Context* context, int start, int end) resolveIpForwards(Context* context, int start, int end)
@ -8454,6 +8436,24 @@ processor(MyThread* t);
void void
compileThunks(MyThread* t, FixedAllocator* allocator); compileThunks(MyThread* t, FixedAllocator* allocator);
class CompilationHandlerList {
public:
CompilationHandlerList(CompilationHandlerList* next, Processor::CompilationHandler* handler):
next(next),
handler(handler) {}
void dispose(Allocator* allocator) {
if(this) {
next->dispose(allocator);
handler->dispose();
allocator->free(this, sizeof(*this));
}
}
CompilationHandlerList* next;
Processor::CompilationHandler* handler;
};
class MyProcessor: public Processor { class MyProcessor: public Processor {
public: public:
class Thunk { class Thunk {
@ -8497,7 +8497,8 @@ class MyProcessor: public Processor {
FixedSizeOfArithmeticException), FixedSizeOfArithmeticException),
codeAllocator(s, 0, 0), codeAllocator(s, 0, 0),
callTableSize(0), callTableSize(0),
useNativeFeatures(useNativeFeatures) useNativeFeatures(useNativeFeatures),
compilationHandlers(0)
{ {
thunkTable[compileMethodIndex] = voidPointer(local::compileMethod); thunkTable[compileMethodIndex] = voidPointer(local::compileMethod);
thunkTable[compileVirtualMethodIndex] = voidPointer(compileVirtualMethod); thunkTable[compileVirtualMethodIndex] = voidPointer(compileVirtualMethod);
@ -8803,6 +8804,7 @@ class MyProcessor: public Processor {
t->arch->release(); t->arch->release();
t->m->heap->free(t, sizeof(*t)); t->m->heap->free(t, sizeof(*t));
} }
virtual void dispose() { virtual void dispose() {
@ -8810,6 +8812,8 @@ class MyProcessor: public Processor {
s->freeExecutable(codeAllocator.base, codeAllocator.capacity); s->freeExecutable(codeAllocator.base, codeAllocator.capacity);
} }
compilationHandlers->dispose(allocator);
s->handleSegFault(0); s->handleSegFault(0);
allocator->free(this, sizeof(*this)); allocator->free(this, sizeof(*this));
@ -8906,6 +8910,10 @@ class MyProcessor: public Processor {
codeAllocator.capacity = capacity; codeAllocator.capacity = capacity;
} }
virtual void addCompilationHandler(CompilationHandler* handler) {
compilationHandlers = new(allocator->allocate(sizeof(CompilationHandlerList))) CompilationHandlerList(compilationHandlers, handler);
}
virtual void compileMethod(Thread* vmt, Zone* zone, object* constants, virtual void compileMethod(Thread* vmt, Zone* zone, object* constants,
object* calls, DelayedPromise** addresses, object* calls, DelayedPromise** addresses,
object method, OffsetResolver* resolver) object method, OffsetResolver* resolver)
@ -9061,8 +9069,36 @@ class MyProcessor: public Processor {
unsigned callTableSize; unsigned callTableSize;
bool useNativeFeatures; bool useNativeFeatures;
void* thunkTable[dummyIndex + 1]; void* thunkTable[dummyIndex + 1];
CompilationHandlerList* compilationHandlers;
}; };
void
logCompile(MyThread* t, const void* code, unsigned size, const char* class_,
const char* name, const char* spec)
{
static bool open = false;
if (not open) {
open = true;
const char* path = findProperty(t, "avian.jit.log");
if (path) {
compileLog = vm::fopen(path, "wb");
} else if (DebugCompile) {
compileLog = stderr;
}
}
if (compileLog) {
fprintf(compileLog, "%p %p %s.%s%s\n",
code, static_cast<const uint8_t*>(code) + size,
class_, name, spec);
}
MyProcessor* p = static_cast<MyProcessor*>(t->m->processor);
for(CompilationHandlerList* h = p->compilationHandlers; h; h = h->next) {
h->handler->compiled(code, 0, 0, class_, name, spec);
}
}
void* void*
compileMethod2(MyThread* t, void* ip) compileMethod2(MyThread* t, void* ip)
{ {

33
src/environment.h Normal file
View File

@ -0,0 +1,33 @@
/* Copyright (c) 2008-2011, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
#ifndef AVIAN_ENVIRONMENT_H
#define AVIAN_ENVIRONMENT_H
#ifndef AVIAN_TARGET_PLATFORM
#error build system should have defined AVIAN_TARGET_PLATFORM
#endif
#ifndef AVIAN_TARGET_ARCH
#error build system should have defined AVIAN_TARGET_ARCH
#endif
#define AVIAN_PLATFORM_UNKNOWN 0
#define AVIAN_PLATFORM_LINUX 1
#define AVIAN_PLATFORM_WINDOWS 2
#define AVIAN_PLATFORM_DARWIN 3
#define AVIAN_ARCH_UNKNOWN 0
#define AVIAN_ARCH_X86 (1 << 8)
#define AVIAN_ARCH_X86_64 (2 << 8)
#define AVIAN_ARCH_ARM (3 << 8)
#define AVIAN_ARCH_POWERPC (4 << 8)
#endif

View File

@ -3067,6 +3067,10 @@ class MyProcessor: public Processor {
abort(s); abort(s);
} }
virtual void addCompilationHandler(CompilationHandler* handler) {
abort(s);
}
virtual void compileMethod(vm::Thread*, Zone*, object*, object*, virtual void compileMethod(vm::Thread*, Zone*, object*, object*,
DelayedPromise**, object, OffsetResolver*) DelayedPromise**, object, OffsetResolver*)
{ {

View File

@ -41,6 +41,13 @@ class Processor {
virtual unsigned count() = 0; virtual unsigned count() = 0;
}; };
class CompilationHandler {
public:
virtual void compiled(const void* code, unsigned size, unsigned frameSize, const char* class_, const char* name, const char* spec) = 0;
virtual void dispose() = 0;
};
virtual Thread* virtual Thread*
makeThread(Machine* m, object javaThread, Thread* parent) = 0; makeThread(Machine* m, object javaThread, Thread* parent) = 0;
@ -120,6 +127,9 @@ class Processor {
virtual void virtual void
initialize(BootImage* image, uint8_t* code, unsigned capacity) = 0; initialize(BootImage* image, uint8_t* code, unsigned capacity) = 0;
virtual void
addCompilationHandler(CompilationHandler* handler) = 0;
virtual void virtual void
compileMethod(Thread* t, Zone* zone, object* constants, object* calls, compileMethod(Thread* t, Zone* zone, object* constants, object* calls,
DelayedPromise** addresses, object method, DelayedPromise** addresses, object method,

View File

@ -8,6 +8,7 @@
There is NO WARRANTY for this software. See license.txt for There is NO WARRANTY for this software. See license.txt for
details. */ details. */
#include "environment.h"
#include "assembler.h" #include "assembler.h"
#include "target.h" #include "target.h"
#include "vector.h" #include "vector.h"
@ -2816,7 +2817,7 @@ class MyArchitecture: public Assembler::Architecture {
} }
virtual unsigned frameFootprint(unsigned footprint) { virtual unsigned frameFootprint(unsigned footprint) {
#ifdef TARGET_PLATFORM_WINDOWS #if AVIAN_TARGET_PLATFORM == AVIAN_PLATFORM_WINDOWS
return max(footprint, StackAlignmentInWords); return max(footprint, StackAlignmentInWords);
#else #else
return max(footprint > argumentRegisterCount() ? return max(footprint > argumentRegisterCount() ?
@ -2838,7 +2839,7 @@ class MyArchitecture: public Assembler::Architecture {
} }
virtual unsigned argumentRegisterCount() { virtual unsigned argumentRegisterCount() {
#ifdef TARGET_PLATFORM_WINDOWS #if AVIAN_TARGET_PLATFORM == AVIAN_PLATFORM_WINDOWS
if (TargetBytesPerWord == 8) return 4; else if (TargetBytesPerWord == 8) return 4; else
#else #else
if (TargetBytesPerWord == 8) return 6; else if (TargetBytesPerWord == 8) return 6; else
@ -2849,7 +2850,7 @@ class MyArchitecture: public Assembler::Architecture {
virtual int argumentRegister(unsigned index) { virtual int argumentRegister(unsigned index) {
assert(&c, TargetBytesPerWord == 8); assert(&c, TargetBytesPerWord == 8);
switch (index) { switch (index) {
#ifdef TARGET_PLATFORM_WINDOWS #if AVIAN_TARGET_PLATFORM == AVIAN_PLATFORM_WINDOWS
case 0: case 0:
return rcx; return rcx;
case 1: case 1: