Merge remote-tracking branch 'github/master' into dicej

Conflicts:
	src/classpath-openjdk.cpp
This commit is contained in:
Joel Dice 2013-02-22 14:43:20 -07:00
commit 9060a31348
66 changed files with 747 additions and 565 deletions

View File

@ -15,7 +15,7 @@
#include "stdlib.h" #include "stdlib.h"
#include "string.h" #include "string.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
#undef JNIEXPORT #undef JNIEXPORT

View File

@ -12,6 +12,9 @@
#define AVIAN_TOOLS_H_ #define AVIAN_TOOLS_H_
#include <stdlib.h> #include <stdlib.h>
#include <avian/util/string.h>
#include "environment.h" #include "environment.h"
namespace avian { namespace avian {
@ -38,24 +41,12 @@ public:
virtual void write(uint8_t byte); virtual void write(uint8_t byte);
}; };
class String {
public:
const char* text;
size_t length;
String(const char* text);
inline String(const char* text, size_t length):
text(text),
length(length) {}
};
class SymbolInfo { class SymbolInfo {
public: public:
unsigned addr; unsigned addr;
String name; util::String name;
inline SymbolInfo(uint64_t addr, const String& name): inline SymbolInfo(uint64_t addr, const util::String& name):
addr(addr), addr(addr),
name(name) {} name(name) {}
@ -78,7 +69,7 @@ public:
class StringTable : public Buffer { class StringTable : public Buffer {
public: public:
unsigned add(String str); unsigned add(util::String str);
}; };
template<class T> template<class T>

View File

@ -11,6 +11,9 @@
#ifndef AVIAN_UTIL_ABORT_H #ifndef AVIAN_UTIL_ABORT_H
#define AVIAN_UTIL_ABORT_H #define AVIAN_UTIL_ABORT_H
namespace avian {
namespace util {
class Aborter { class Aborter {
public: public:
virtual void NO_RETURN abort() = 0; virtual void NO_RETURN abort() = 0;
@ -37,5 +40,8 @@ inline void assert(T t, bool v) {
expect(t, v); expect(t, v);
} }
#endif #endif
} // namespace util
} // namespace avian
#endif // AVIAN_UTIL_ABORT_H #endif // AVIAN_UTIL_ABORT_H

53
include/avian/util/math.h Normal file
View File

@ -0,0 +1,53 @@
/* Copyright (c) 2008-2012, 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_UTIL_MATH_H
#define AVIAN_UTIL_MATH_H
namespace avian {
namespace util {
inline unsigned max(unsigned a, unsigned b) {
return (a > b ? a : b);
}
inline unsigned min(unsigned a, unsigned b) {
return (a < b ? a : b);
}
inline unsigned avg(unsigned a, unsigned b) {
return (a + b) / 2;
}
inline unsigned ceilingDivide(unsigned n, unsigned d) {
return (n + d - 1) / d;
}
inline bool powerOfTwo(unsigned n) {
for (; n > 2; n >>= 1) if (n & 1) return false;
return true;
}
inline unsigned nextPowerOfTwo(unsigned n) {
unsigned r = 1;
while (r < n) r <<= 1;
return r;
}
inline unsigned log(unsigned n) {
unsigned r = 0;
for (unsigned i = 1; i < n; ++r) i <<= 1;
return r;
}
} // namespace util
} // namespace avian
#endif // AVIAN_UTIL_MATH_H

View File

@ -32,9 +32,9 @@ class RuntimeArray {
#else // not _MSC_VER #else // not _MSC_VER
# define RUNTIME_ARRAY(type, name, size) type name[size]; # define RUNTIME_ARRAY(type, name, size) type name##_body[size];
# define RUNTIME_ARRAY_BODY(name) name # define RUNTIME_ARRAY_BODY(name) name##_body
#endif #endif
#endif // AVIAN_UTIL_RUNTIME_ARRAY_H #endif // AVIAN_UTIL_RUNTIME_ARRAY_H

View File

@ -8,27 +8,37 @@
There is NO WARRANTY for this software. See license.txt for There is NO WARRANTY for this software. See license.txt for
details. */ details. */
#ifndef TOKENIZER_H #ifndef AVIAN_UTIL_STRING_H
#define TOKENIZER_H #define AVIAN_UTIL_STRING_H
namespace vm { #include <string.h>
namespace avian {
namespace util {
class String {
public:
const char* text;
size_t length;
String(const char* text):
text(text),
length(strlen(text)) {}
inline String(const char* text, size_t length):
text(text),
length(length) {}
};
class Tokenizer { class Tokenizer {
public: public:
class Token {
public:
Token(const char* s, unsigned length): s(s), length(length) { }
const char* s;
unsigned length;
};
Tokenizer(const char* s, char delimiter): Tokenizer(const char* s, char delimiter):
s(s), limit(0), delimiter(delimiter) s(s), limit(0), delimiter(delimiter)
{ } { }
Tokenizer(const char* s, unsigned length, char delimiter): Tokenizer(String str, char delimiter):
s(s), limit(s + length), delimiter(delimiter) s(str.text), limit(str.text + str.length), delimiter(delimiter)
{ } { }
bool hasMore() { bool hasMore() {
@ -36,10 +46,10 @@ class Tokenizer {
return s != limit and *s != 0; return s != limit and *s != 0;
} }
Token next() { String next() {
const char* p = s; const char* p = s;
while (s != limit and *s and *s != delimiter) ++s; while (s != limit and *s and *s != delimiter) ++s;
return Token(p, s - p); return String(p, s - p);
} }
const char* s; const char* s;
@ -47,6 +57,7 @@ class Tokenizer {
char delimiter; char delimiter;
}; };
} // namespace } // namespace util
} // namespace avain
#endif//TOKENIZER_H #endif//AVIAN_UTIL_STRING_H

View File

@ -11,11 +11,11 @@
#ifndef AVIAN_CODEGEN_ASSEMBLER_H #ifndef AVIAN_CODEGEN_ASSEMBLER_H
#define AVIAN_CODEGEN_ASSEMBLER_H #define AVIAN_CODEGEN_ASSEMBLER_H
#include "system.h" #include <avian/vm/system/system.h>
#include "zone.h" #include "zone.h"
#include "codegen/lir.h" #include <avian/vm/codegen/lir.h>
#include "codegen/promise.h" #include <avian/vm/codegen/promise.h>
namespace avian { namespace avian {
namespace codegen { namespace codegen {

View File

@ -11,7 +11,7 @@
#ifndef AVIAN_CODEGEN_COMPILER_H #ifndef AVIAN_CODEGEN_COMPILER_H
#define AVIAN_CODEGEN_COMPILER_H #define AVIAN_CODEGEN_COMPILER_H
#include "system.h" #include <avian/vm/system/system.h>
#include "zone.h" #include "zone.h"
#include "assembler.h" #include "assembler.h"

View File

@ -11,7 +11,7 @@
#ifndef AVIAN_CODEGEN_TARGETS_H #ifndef AVIAN_CODEGEN_TARGETS_H
#define AVIAN_CODEGEN_TARGETS_H #define AVIAN_CODEGEN_TARGETS_H
#include "codegen/assembler.h" #include <avian/vm/codegen/assembler.h>
namespace avian { namespace avian {
namespace codegen { namespace codegen {

View File

@ -11,7 +11,7 @@
#ifndef HEAP_H #ifndef HEAP_H
#define HEAP_H #define HEAP_H
#include "system.h" #include <avian/vm/system/system.h>
#include "allocator.h" #include "allocator.h"
namespace vm { namespace vm {

View File

@ -13,11 +13,11 @@
#include "common.h" #include "common.h"
#include "allocator.h" #include "allocator.h"
#include "util/abort.h" #include <avian/util/abort.h>
namespace vm { namespace vm {
class System : public Aborter { class System : public avian::util::Aborter {
public: public:
typedef intptr_t Status; typedef intptr_t Status;
@ -165,7 +165,7 @@ allocate(System* s, unsigned size)
#define ACQUIRE_MONITOR(t, m) \ #define ACQUIRE_MONITOR(t, m) \
System::MonitorResource MAKE_NAME(monitorResource_) (t, m) System::MonitorResource MAKE_NAME(monitorResource_) (t, m)
inline Aborter* getAborter(System* s) { inline avian::util::Aborter* getAborter(System* s) {
return s; return s;
} }

View File

@ -257,7 +257,7 @@ warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self \
target-cflags = -DTARGET_BYTES_PER_WORD=$(pointer-size) target-cflags = -DTARGET_BYTES_PER_WORD=$(pointer-size)
common-cflags = $(warnings) -fno-rtti -fno-exceptions -I$(classpath-src) \ common-cflags = $(warnings) -fno-rtti -fno-exceptions -I$(classpath-src) \
"-I$(JAVA_HOME)/include" -idirafter $(src) -I$(build) $(classpath-cflags) \ "-I$(JAVA_HOME)/include" -idirafter $(src) -I$(build) -Iinclude $(classpath-cflags) \
-D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DAVIAN_VERSION=\"$(version)\" \ -D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DAVIAN_VERSION=\"$(version)\" \
-DAVIAN_INFO="\"$(info)\"" \ -DAVIAN_INFO="\"$(info)\"" \
-DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \ -DUSE_ATOMIC_OPERATIONS -DAVIAN_JAVA_HOME=\"$(javahome)\" \
@ -275,7 +275,7 @@ 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 -Isrc/ \ converter-cflags = -D__STDC_CONSTANT_MACROS -Iinclude/ -Isrc/ \
-fno-rtti -fno-exceptions \ -fno-rtti -fno-exceptions \
-DAVIAN_TARGET_ARCH=AVIAN_ARCH_UNKNOWN \ -DAVIAN_TARGET_ARCH=AVIAN_ARCH_UNKNOWN \
-DAVIAN_TARGET_FORMAT=AVIAN_FORMAT_UNKNOWN \ -DAVIAN_TARGET_FORMAT=AVIAN_FORMAT_UNKNOWN \
@ -982,10 +982,11 @@ generated-code = \
$(build)/type-name-initializations.cpp \ $(build)/type-name-initializations.cpp \
$(build)/type-maps.cpp $(build)/type-maps.cpp
vm-depends := $(generated-code) $(wildcard $(src)/*.h) $(wildcard $(src)/codegen/*.h) $(wildcard $(src)/codegen/compiler/*.h) vm-depends := $(generated-code) \
$(shell find src include -name '*.h' -or -name '*.inc.cpp')
vm-sources = \ vm-sources = \
$(src)/$(system).cpp \ $(src)/vm/system/$(system).cpp \
$(src)/finder.cpp \ $(src)/finder.cpp \
$(src)/machine.cpp \ $(src)/machine.cpp \
$(src)/util.cpp \ $(src)/util.cpp \
@ -1062,7 +1063,7 @@ heapwalk-sources = $(src)/heapwalk.cpp
heapwalk-objects = \ heapwalk-objects = \
$(call cpp-objects,$(heapwalk-sources),$(src),$(build)) $(call cpp-objects,$(heapwalk-sources),$(src),$(build))
unittest-objects = $(call cpp-objects,$(unittest-sources),$(unittest),$(build)/unittest/) unittest-objects = $(call cpp-objects,$(unittest-sources),$(unittest),$(build)/unittest)
ifeq ($(heapdump),true) ifeq ($(heapdump),true)
vm-sources += $(src)/heapdump.cpp vm-sources += $(src)/heapdump.cpp
@ -1079,7 +1080,7 @@ ifeq ($(continuations),true)
asmflags += -DAVIAN_CONTINUATIONS asmflags += -DAVIAN_CONTINUATIONS
endif endif
bootimage-generator-sources = $(src)/bootimage.cpp bootimage-generator-sources = $(src)/tools/bootimage-generator/main.cpp
ifneq ($(lzma),) ifneq ($(lzma),)
bootimage-generator-sources += $(src)/lzma-encode.cpp bootimage-generator-sources += $(src)/lzma-encode.cpp
endif endif
@ -1114,8 +1115,8 @@ boot-object = $(build)/boot.o
generator-depends := $(wildcard $(src)/*.h) generator-depends := $(wildcard $(src)/*.h)
generator-sources = \ generator-sources = \
$(src)/type-generator.cpp \ $(src)/tools/type-generator/main.cpp \
$(src)/$(build-system).cpp \ $(src)/vm/system/$(build-system).cpp \
$(src)/finder.cpp $(src)/finder.cpp
ifneq ($(lzma),) ifneq ($(lzma),)
@ -1169,18 +1170,20 @@ generator-lzma-objects = \
$(call generator-c-objects,$(lzma-decode-sources),$(lzma)/C,$(build)) $(call generator-c-objects,$(lzma-decode-sources),$(lzma)/C,$(build))
generator = $(build)/generator generator = $(build)/generator
converter-depends = \ all-depends = $(shell find include -name '*.h')
$(src)/binaryToObject/tools.h \
$(src)/binaryToObject/endianness.h
converter-sources = \ object-writer-depends = $(shell find $(src)/tools/object-writer -name '*.h')
$(src)/binaryToObject/tools.cpp \ object-writer-sources = $(shell find $(src)/tools/object-writer -name '*.cpp')
$(src)/binaryToObject/elf.cpp \ object-writer-objects = $(call cpp-objects,$(object-writer-sources),$(src),$(build))
$(src)/binaryToObject/mach-o.cpp \
$(src)/binaryToObject/pe.cpp
converter-tool-sources = \ binary-to-object-depends = $(shell find $(src)/tools/binary-to-object/ -name '*.h')
$(src)/binaryToObject/main.cpp binary-to-object-sources = $(shell find $(src)/tools/binary-to-object/ -name '*.cpp')
binary-to-object-objects = $(call cpp-objects,$(binary-to-object-sources),$(src),$(build))
converter-sources = $(object-writer-sources)
converter-tool-depends = $(binary-to-object-depends) $(all-depends)
converter-tool-sources = $(binary-to-object-sources)
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-tool-objects = $(call cpp-objects,$(converter-tool-sources),$(src),$(build))
@ -1580,11 +1583,12 @@ $(boot-object): $(boot-source)
$(boot-javahome-object): $(src)/boot-javahome.cpp $(boot-javahome-object): $(src)/boot-javahome.cpp
$(compile-object) $(compile-object)
$(converter-objects) $(converter-tool-objects): $(build)/binaryToObject/%.o: $(src)/binaryToObject/%.cpp $(converter-depends) $(object-writer-objects) $(binary-to-object-objects): $(build)/%.o: $(src)/%.cpp $(binary-to-object-depends) $(object-writer-depends) $(all-depends)
@mkdir -p $(dir $(@)) @mkdir -p $(dir $(@))
$(build-cxx) $(converter-cflags) -c $(<) -o $(@) $(build-cxx) $(converter-cflags) -c $(<) -o $(@)
$(converter): $(converter-objects) $(converter-tool-objects) $(converter): $(converter-objects) $(converter-tool-objects)
@mkdir -p $(dir $(@))
$(build-cc) $(^) -g -o $(@) $(build-cc) $(^) -g -o $(@)
$(lzma-encoder-objects): $(build)/lzma/%.o: $(src)/lzma/%.cpp $(lzma-encoder-objects): $(build)/lzma/%.o: $(src)/lzma/%.cpp

View File

@ -11,9 +11,11 @@
#ifndef VECTOR_H #ifndef VECTOR_H
#define VECTOR_H #define VECTOR_H
#include "system.h" #include <avian/vm/system/system.h>
#include "target.h" #include "target.h"
#include <avian/util/math.h>
namespace vm { namespace vm {
class Vector { class Vector {
@ -51,8 +53,8 @@ class Vector {
if (position + space > capacity) { if (position + space > capacity) {
assert(s, minimumCapacity >= 0); assert(s, minimumCapacity >= 0);
unsigned newCapacity = max unsigned newCapacity = avian::util::max
(position + space, max(minimumCapacity, capacity * 2)); (position + space, avian::util::max(minimumCapacity, capacity * 2));
uint8_t* newData = static_cast<uint8_t*> uint8_t* newData = static_cast<uint8_t*>
(allocator->allocate(newCapacity)); (allocator->allocate(newCapacity));
if (data) { if (data) {

View File

@ -13,7 +13,7 @@
#include "types.h" #include "types.h"
#include "common.h" #include "common.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
#ifdef __APPLE__ #ifdef __APPLE__
# include "libkern/OSAtomic.h" # include "libkern/OSAtomic.h"
@ -206,7 +206,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes,
++ stackIndex; ++ stackIndex;
} }
memcpy(stack + stackIndex, arguments + ai, 8); memcpy(RUNTIME_ARRAY_BODY(stack) + stackIndex, arguments + ai, 8);
stackIndex += 8 / BytesPerWord; stackIndex += 8 / BytesPerWord;
} }
ai += 8 / BytesPerWord; ai += 8 / BytesPerWord;
@ -219,7 +219,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes,
} else if (vfpIndex < VfpCount) { } else if (vfpIndex < VfpCount) {
vfpTable[vfpIndex++] = arguments[ai]; vfpTable[vfpIndex++] = arguments[ai];
} else { } else {
stack[stackIndex++] = arguments[ai]; RUNTIME_ARRAY_BODY(stack)[stackIndex++] = arguments[ai];
} }
++ ai; ++ ai;
break; break;
@ -231,7 +231,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes,
and gprIndex + Alignment == GprCount) and gprIndex + Alignment == GprCount)
{ {
gprTable[gprIndex++] = arguments[ai]; gprTable[gprIndex++] = arguments[ai];
stack[stackIndex++] = arguments[ai + 1]; RUNTIME_ARRAY_BODY(stack)[stackIndex++] = arguments[ai + 1];
} else { } else {
if (gprIndex % Alignment) { if (gprIndex % Alignment) {
++gprIndex; ++gprIndex;
@ -246,7 +246,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes,
++stackIndex; ++stackIndex;
} }
memcpy(stack + stackIndex, arguments + ai, 8); memcpy(RUNTIME_ARRAY_BODY(stack) + stackIndex, arguments + ai, 8);
stackIndex += 8 / BytesPerWord; stackIndex += 8 / BytesPerWord;
} }
ai += 8 / BytesPerWord; ai += 8 / BytesPerWord;
@ -256,7 +256,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes,
if (gprIndex < GprCount) { if (gprIndex < GprCount) {
gprTable[gprIndex++] = arguments[ai]; gprTable[gprIndex++] = arguments[ai];
} else { } else {
stack[stackIndex++] = arguments[ai]; RUNTIME_ARRAY_BODY(stack)[stackIndex++] = arguments[ai];
} }
++ ai; ++ ai;
} break; } break;
@ -274,7 +274,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes,
unsigned stackSize = stackIndex*BytesPerWord + ((stackIndex & 1) << 2); unsigned stackSize = stackIndex*BytesPerWord + ((stackIndex & 1) << 2);
return vmNativeCall return vmNativeCall
(function, stackSize, stack, stackIndex * BytesPerWord, (function, stackSize, RUNTIME_ARRAY_BODY(stack), stackIndex * BytesPerWord,
(gprIndex ? gprTable : 0), (gprIndex ? gprTable : 0),
(vfpIndex ? vfpTable : 0), returnType); (vfpIndex ? vfpTable : 0), returnType);
} }

View File

@ -9,13 +9,13 @@ const unsigned NAME(BootHeapOffset) = 1 << (NAME(BootShift) + 1);
inline unsigned inline unsigned
LABEL(codeMapSize)(unsigned codeSize) LABEL(codeMapSize)(unsigned codeSize)
{ {
return ceilingDivide(codeSize, TargetBitsPerWord) * TargetBytesPerWord; return avian::util::ceilingDivide(codeSize, TargetBitsPerWord) * TargetBytesPerWord;
} }
inline unsigned inline unsigned
LABEL(heapMapSize)(unsigned heapSize) LABEL(heapMapSize)(unsigned heapSize)
{ {
return ceilingDivide(heapSize, TargetBitsPerWord * TargetBytesPerWord) return avian::util::ceilingDivide(heapSize, TargetBitsPerWord * TargetBytesPerWord)
* TargetBytesPerWord; * TargetBytesPerWord;
} }

View File

@ -12,9 +12,12 @@
#define BOOTIMAGE_H #define BOOTIMAGE_H
#include "common.h" #include "common.h"
#include "java-common.h"
#include "target.h" #include "target.h"
#include "machine.h" #include "machine.h"
#include <avian/util/math.h>
namespace vm { namespace vm {
class BootImage { class BootImage {

View File

@ -13,7 +13,7 @@
#include "processor.h" #include "processor.h"
#include "util.h" #include "util.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
using namespace vm; using namespace vm;

View File

@ -12,7 +12,7 @@
#include "classpath-common.h" #include "classpath-common.h"
#include "process.h" #include "process.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
using namespace vm; using namespace vm;

View File

@ -11,9 +11,10 @@
#ifndef CLASSPATH_COMMON_H #ifndef CLASSPATH_COMMON_H
#define CLASSPATH_COMMON_H #define CLASSPATH_COMMON_H
#include "tokenizer.h" #include <avian/util/string.h>
#include <avian/util/runtime-array.h>
#include "util/runtime-array.h" using namespace avian::util;
namespace vm { namespace vm {
@ -217,13 +218,13 @@ loadLibrary(Thread* t, const char* path, const char* name, bool mapName,
for (Tokenizer tokenizer(path, t->m->system->pathSeparator()); for (Tokenizer tokenizer(path, t->m->system->pathSeparator());
tokenizer.hasMore();) tokenizer.hasMore();)
{ {
Tokenizer::Token token(tokenizer.next()); String token(tokenizer.next());
unsigned fullNameLength = token.length + 1 + nameLength; unsigned fullNameLength = token.length + 1 + nameLength;
THREAD_RUNTIME_ARRAY(t, char, fullName, fullNameLength + 1); THREAD_RUNTIME_ARRAY(t, char, fullName, fullNameLength + 1);
snprintf(RUNTIME_ARRAY_BODY(fullName), fullNameLength + 1, snprintf(RUNTIME_ARRAY_BODY(fullName), fullNameLength + 1,
"%.*s/%s", token.length, token.s, name); "%.*s/%s", token.length, token.text, name);
lib = loadLibrary(t, RUNTIME_ARRAY_BODY(fullName)); lib = loadLibrary(t, RUNTIME_ARRAY_BODY(fullName));
if (lib) break; if (lib) break;

View File

@ -339,7 +339,7 @@ makeClassNameString(Thread* t, object name)
replace('/', '.', RUNTIME_ARRAY_BODY(s), replace('/', '.', RUNTIME_ARRAY_BODY(s),
reinterpret_cast<char*>(&byteArrayBody(t, name, 0))); reinterpret_cast<char*>(&byteArrayBody(t, name, 0)));
return makeString(t, "%s", s); return makeString(t, "%s", RUNTIME_ARRAY_BODY(s));
} }
object object
@ -761,7 +761,8 @@ class MyClasspath : public Classpath {
length); length);
RUNTIME_ARRAY_BODY(packageName)[length] = 0; RUNTIME_ARRAY_BODY(packageName)[length] = 0;
object key = vm::makeByteArray(t, "%s", packageName); object key = vm::makeByteArray
(t, "%s", RUNTIME_ARRAY_BODY(packageName));
PROTECT(t, key); PROTECT(t, key);
hashMapRemove hashMapRemove
@ -781,7 +782,7 @@ class MyClasspath : public Classpath {
&byteArrayBody(t, source, PrefixLength), &byteArrayBody(t, source, PrefixLength),
sourceNameLength); sourceNameLength);
source = vm::makeByteArray(t, "%s", sourceName); source = vm::makeByteArray(t, "%s", RUNTIME_ARRAY_BODY(sourceName));
} else { } else {
source = vm::makeByteArray(t, "avian-dummy-package-source"); source = vm::makeByteArray(t, "avian-dummy-package-source");
} }
@ -1575,7 +1576,8 @@ getZipFileEntry(Thread* t, object method, uintptr_t* arguments)
RUNTIME_ARRAY_BODY(p)[byteArrayLength(t, path) + 1] = 0; RUNTIME_ARRAY_BODY(p)[byteArrayLength(t, path) + 1] = 0;
} }
return reinterpret_cast<int64_t>(find(file, p, byteArrayLength(t, path))); return reinterpret_cast<int64_t>
(find(file, RUNTIME_ARRAY_BODY(p), byteArrayLength(t, path)));
} else { } else {
int64_t entry = longValue int64_t entry = longValue
(t, t->m->processor->invoke (t, t->m->processor->invoke
@ -3269,8 +3271,8 @@ jvmInitProperties(Thread* t, uintptr_t* arguments)
if (*p == '=') { if (*p == '=') {
THREAD_RUNTIME_ARRAY(t, char, name, (p - start) + 1); THREAD_RUNTIME_ARRAY(t, char, name, (p - start) + 1);
memcpy(name, start, p - start); memcpy(RUNTIME_ARRAY_BODY(name), start, p - start);
name[p - start] = 0; RUNTIME_ARRAY_BODY(name)[p - start] = 0;
local::setProperty local::setProperty
(t, method, *properties, RUNTIME_ARRAY_BODY(name), p + 1); (t, method, *properties, RUNTIME_ARRAY_BODY(name), p + 1);
} }
@ -4654,6 +4656,86 @@ jvmInvokeMethod(Thread* t, uintptr_t* arguments)
(t, jclassVmClass(t, jmethodClazz(t, *method))), (t, jclassVmClass(t, jmethodClazz(t, *method))),
jmethodSlot(t, *method)); jmethodSlot(t, *method));
<<<<<<< HEAD
=======
if (methodFlags(t, vmMethod) & ACC_STATIC) {
instance = 0;
}
if ((args == 0 ? 0 : objectArrayLength(t, *args))
!= methodParameterCount(t, vmMethod))
{
throwNew(t, Machine::IllegalArgumentExceptionType);
}
if (methodParameterCount(t, vmMethod)) {
PROTECT(t, vmMethod);
unsigned specLength = byteArrayLength(t, methodSpec(t, vmMethod));
THREAD_RUNTIME_ARRAY(t, char, spec, specLength);
memcpy(RUNTIME_ARRAY_BODY(spec),
&byteArrayBody(t, methodSpec(t, vmMethod), 0), specLength);
unsigned i = 0;
for (MethodSpecIterator it(t, RUNTIME_ARRAY_BODY(spec)); it.hasNext();) {
object type;
bool objectType = false;
const char* p = it.next();
switch (*p) {
case 'Z': type = vm::type(t, Machine::BooleanType); break;
case 'B': type = vm::type(t, Machine::ByteType); break;
case 'S': type = vm::type(t, Machine::ShortType); break;
case 'C': type = vm::type(t, Machine::CharType); break;
case 'I': type = vm::type(t, Machine::IntType); break;
case 'F': type = vm::type(t, Machine::FloatType); break;
case 'J': type = vm::type(t, Machine::LongType); break;
case 'D': type = vm::type(t, Machine::DoubleType); break;
case 'L': ++ p;
case '[': {
objectType = true;
unsigned nameLength = it.s - p;
THREAD_RUNTIME_ARRAY(t, char, name, nameLength);
memcpy(RUNTIME_ARRAY_BODY(name), p, nameLength - 1);
RUNTIME_ARRAY_BODY(name)[nameLength - 1] = 0;
type = resolveClass
(t, classLoader(t, methodClass(t, vmMethod)),
RUNTIME_ARRAY_BODY(name));
} break;
default:
abort();
}
object arg = objectArrayBody(t, *args, i++);
if ((arg == 0 and (not objectType))
or (arg and (not instanceOf(t, type, arg))))
{
// fprintf(stderr, "%s is not a %s\n", arg ? &byteArrayBody(t, className(t, objectClass(t, arg)), 0) : reinterpret_cast<const int8_t*>("<null>"), &byteArrayBody(t, className(t, type), 0));
throwNew(t, Machine::IllegalArgumentExceptionType);
}
}
}
unsigned returnCode = methodReturnCode(t, vmMethod);
THREAD_RESOURCE0(t, {
if (t->exception) {
object exception = t->exception;
t->exception = makeThrowable
(t, Machine::InvocationTargetExceptionType, 0, 0, exception);
}
});
object result;
if (args) {
result = t->m->processor->invokeArray
(t, vmMethod, instance ? *instance : 0, *args);
} else {
result = t->m->processor->invoke(t, vmMethod, instance ? *instance : 0);
}
>>>>>>> github/master
return reinterpret_cast<uint64_t> return reinterpret_cast<uint64_t>
(makeLocalReference (makeLocalReference
(t, invoke (t, invoke

View File

@ -8,13 +8,13 @@
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 "codegen/assembler.h" #include <avian/vm/codegen/assembler.h>
#include "codegen/registers.h" #include <avian/vm/codegen/registers.h>
#include "alloc-vector.h" #include "alloc-vector.h"
#include "util/abort.h" #include <avian/util/abort.h>
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
#define CAST1(x) reinterpret_cast<UnaryOperationType>(x) #define CAST1(x) reinterpret_cast<UnaryOperationType>(x)
#define CAST2(x) reinterpret_cast<BinaryOperationType>(x) #define CAST2(x) reinterpret_cast<BinaryOperationType>(x)
@ -23,6 +23,7 @@
using namespace vm; using namespace vm;
using namespace avian::codegen; using namespace avian::codegen;
using namespace avian::util;
namespace local { namespace local {
@ -2235,14 +2236,6 @@ class MyArchitecture: public Assembler::Architecture {
virtual int framePointerOffset() { virtual int framePointerOffset() {
return 0; return 0;
} }
virtual lir::BinaryOperation hasBinaryIntrinsic(Thread*, object) {
return lir::NoBinaryOperation;
}
virtual lir::TernaryOperation hasTernaryIntrinsic(Thread*, object) {
return lir::NoTernaryOperation;
}
virtual bool alwaysCondensed(lir::BinaryOperation) { virtual bool alwaysCondensed(lir::BinaryOperation) {
return false; return false;

View File

@ -10,11 +10,11 @@
#include "target.h" #include "target.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
#include "codegen/compiler.h" #include <avian/vm/codegen/compiler.h>
#include "codegen/assembler.h" #include <avian/vm/codegen/assembler.h>
#include "codegen/promise.h" #include <avian/vm/codegen/promise.h>
#include "codegen/compiler/regalloc.h" #include "codegen/compiler/regalloc.h"
#include "codegen/compiler/context.h" #include "codegen/compiler/context.h"

View File

@ -11,10 +11,12 @@
#ifndef AVIAN_CODEGEN_COMPILER_CONTEXT_H #ifndef AVIAN_CODEGEN_COMPILER_CONTEXT_H
#define AVIAN_CODEGEN_COMPILER_CONTEXT_H #define AVIAN_CODEGEN_COMPILER_CONTEXT_H
#include "codegen/assembler.h" #include <avian/vm/codegen/assembler.h>
#include "codegen/compiler.h" #include <avian/vm/codegen/compiler.h>
#include "codegen/compiler/regalloc.h" #include "regalloc.h"
using namespace avian::util;
namespace avian { namespace avian {
namespace codegen { namespace codegen {

View File

@ -9,7 +9,8 @@
details. */ details. */
#include "target.h" #include "target.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
#include <avian/util/math.h>
#include "codegen/compiler/context.h" #include "codegen/compiler/context.h"
#include "codegen/compiler/event.h" #include "codegen/compiler/event.h"
@ -20,6 +21,8 @@
#include "codegen/compiler/frame.h" #include "codegen/compiler/frame.h"
#include "codegen/compiler/ir.h" #include "codegen/compiler/ir.h"
using namespace avian::util;
namespace avian { namespace avian {
namespace codegen { namespace codegen {
namespace compiler { namespace compiler {
@ -921,11 +924,11 @@ appendCombine(Context* c, lir::TernaryOperation type,
intptr_t handler = c->client->getThunk intptr_t handler = c->client->getThunk
(type, firstSize, resultSize, &threadParameter); (type, firstSize, resultSize, &threadParameter);
unsigned stackSize = vm::ceilingDivide(secondSize, vm::TargetBytesPerWord) unsigned stackSize = ceilingDivide(secondSize, vm::TargetBytesPerWord)
+ vm::ceilingDivide(firstSize, vm::TargetBytesPerWord); + ceilingDivide(firstSize, vm::TargetBytesPerWord);
compiler::push(c, vm::ceilingDivide(secondSize, vm::TargetBytesPerWord), second); compiler::push(c, ceilingDivide(secondSize, vm::TargetBytesPerWord), second);
compiler::push(c, vm::ceilingDivide(firstSize, vm::TargetBytesPerWord), first); compiler::push(c, ceilingDivide(firstSize, vm::TargetBytesPerWord), first);
if (threadParameter) { if (threadParameter) {
++ stackSize; ++ stackSize;
@ -1047,7 +1050,7 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize,
if (thunk) { if (thunk) {
Stack* oldStack = c->stack; Stack* oldStack = c->stack;
compiler::push(c, vm::ceilingDivide(firstSize, vm::TargetBytesPerWord), first); compiler::push(c, ceilingDivide(firstSize, vm::TargetBytesPerWord), first);
Stack* argumentStack = c->stack; Stack* argumentStack = c->stack;
c->stack = oldStack; c->stack = oldStack;
@ -1057,7 +1060,7 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize,
(c, lir::ValueGeneral, constantSite (c, lir::ValueGeneral, constantSite
(c, c->client->getThunk(type, firstSize, resultSize))), (c, c->client->getThunk(type, firstSize, resultSize))),
0, 0, result, resultSize, argumentStack, 0, 0, result, resultSize, argumentStack,
vm::ceilingDivide(firstSize, vm::TargetBytesPerWord), 0); ceilingDivide(firstSize, vm::TargetBytesPerWord), 0);
} else { } else {
append(c, new(c->zone) append(c, new(c->zone)
TranslateEvent TranslateEvent
@ -1404,8 +1407,8 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first
assert(c, not threadParameter); assert(c, not threadParameter);
compiler::push(c, vm::ceilingDivide(size, vm::TargetBytesPerWord), second); compiler::push(c, ceilingDivide(size, vm::TargetBytesPerWord), second);
compiler::push(c, vm::ceilingDivide(size, vm::TargetBytesPerWord), first); compiler::push(c, ceilingDivide(size, vm::TargetBytesPerWord), first);
Stack* argumentStack = c->stack; Stack* argumentStack = c->stack;
c->stack = oldStack; c->stack = oldStack;
@ -1414,7 +1417,7 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first
appendCall appendCall
(c, value (c, value
(c, lir::ValueGeneral, constantSite(c, handler)), 0, 0, result, 4, (c, lir::ValueGeneral, constantSite(c, handler)), 0, 0, result, 4,
argumentStack, vm::ceilingDivide(size, vm::TargetBytesPerWord) * 2, 0); argumentStack, ceilingDivide(size, vm::TargetBytesPerWord) * 2, 0);
appendBranch(c, thunkBranch(c, type), 4, value appendBranch(c, thunkBranch(c, type), 4, value
(c, lir::ValueGeneral, constantSite(c, static_cast<int64_t>(0))), (c, lir::ValueGeneral, constantSite(c, static_cast<int64_t>(0))),

View File

@ -13,15 +13,20 @@
#include "common.h" #include "common.h"
#include "codegen/lir.h" #include <avian/vm/codegen/lir.h>
#include "codegen/registers.h" #include <avian/vm/codegen/registers.h>
class Aborter;
namespace avian { namespace avian {
namespace util {
class Aborter;
} // namespace util
namespace codegen { namespace codegen {
namespace compiler { namespace compiler {
using namespace avian::util;
class Context; class Context;
class Value; class Value;
class SiteMask; class SiteMask;

View File

@ -11,9 +11,8 @@
#ifndef AVIAN_CODEGEN_COMPILER_VALUE_H #ifndef AVIAN_CODEGEN_COMPILER_VALUE_H
#define AVIAN_CODEGEN_COMPILER_VALUE_H #define AVIAN_CODEGEN_COMPILER_VALUE_H
#include "codegen/lir.h" #include <avian/vm/codegen/lir.h>
#include <avian/vm/codegen/compiler.h>
#include "codegen/compiler.h"
namespace avian { namespace avian {
namespace codegen { namespace codegen {

View File

@ -8,11 +8,11 @@
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 "codegen/assembler.h" #include <avian/vm/codegen/assembler.h>
#include "codegen/registers.h" #include <avian/vm/codegen/registers.h>
#include "alloc-vector.h" #include "alloc-vector.h"
#include "util/abort.h" #include <avian/util/abort.h>
#define CAST1(x) reinterpret_cast<UnaryOperationType>(x) #define CAST1(x) reinterpret_cast<UnaryOperationType>(x)
#define CAST2(x) reinterpret_cast<BinaryOperationType>(x) #define CAST2(x) reinterpret_cast<BinaryOperationType>(x)
@ -21,6 +21,7 @@
using namespace vm; using namespace vm;
using namespace avian::codegen; using namespace avian::codegen;
using namespace avian::util;
namespace { namespace {
@ -2239,14 +2240,6 @@ class MyArchitecture: public Assembler::Architecture {
virtual int framePointerOffset() { virtual int framePointerOffset() {
return 0; return 0;
} }
virtual lir::BinaryOperation hasBinaryIntrinsic(Thread*, object) {
return lir::NoBinaryOperation;
}
virtual lir::TernaryOperation hasTernaryIntrinsic(Thread*, object) {
return lir::NoTernaryOperation;
}
virtual bool alwaysCondensed(lir::BinaryOperation) { virtual bool alwaysCondensed(lir::BinaryOperation) {
return false; return false;

View File

@ -8,7 +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 "codegen/registers.h" #include <avian/vm/codegen/registers.h>
namespace avian { namespace avian {
namespace codegen { namespace codegen {

View File

@ -8,7 +8,8 @@
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 "codegen/targets.h" #include <avian/vm/codegen/targets.h>
#include "environment.h" #include "environment.h"
namespace avian { namespace avian {

View File

@ -12,11 +12,11 @@
#include "target.h" #include "target.h"
#include "alloc-vector.h" #include "alloc-vector.h"
#include "codegen/assembler.h" #include <avian/vm/codegen/assembler.h>
#include "codegen/registers.h" #include <avian/vm/codegen/registers.h>
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
#include "util/abort.h" #include <avian/util/abort.h>
#define CAST1(x) reinterpret_cast<UnaryOperationType>(x) #define CAST1(x) reinterpret_cast<UnaryOperationType>(x)
#define CAST2(x) reinterpret_cast<BinaryOperationType>(x) #define CAST2(x) reinterpret_cast<BinaryOperationType>(x)
@ -24,6 +24,7 @@
using namespace vm; using namespace vm;
using namespace avian::codegen; using namespace avian::codegen;
using namespace avian::util;
namespace { namespace {

View File

@ -296,24 +296,6 @@ const uintptr_t PointerMask
const unsigned LikelyPageSizeInBytes = 4 * 1024; const unsigned LikelyPageSizeInBytes = 4 * 1024;
inline unsigned
max(unsigned a, unsigned b)
{
return (a > b ? a : b);
}
inline unsigned
min(unsigned a, unsigned b)
{
return (a < b ? a : b);
}
inline unsigned
avg(unsigned a, unsigned b)
{
return (a + b) / 2;
}
inline unsigned inline unsigned
pad(unsigned n, unsigned alignment) pad(unsigned n, unsigned alignment)
{ {
@ -338,35 +320,6 @@ padWord(uintptr_t n)
return padWord(n, BytesPerWord); return padWord(n, BytesPerWord);
} }
inline unsigned
ceilingDivide(unsigned n, unsigned d)
{
return (n + d - 1) / d;
}
inline bool
powerOfTwo(unsigned n)
{
for (; n > 2; n >>= 1) if (n & 1) return false;
return true;
}
inline unsigned
nextPowerOfTwo(unsigned n)
{
unsigned r = 1;
while (r < n) r <<= 1;
return r;
}
inline unsigned
log(unsigned n)
{
unsigned r = 0;
for (unsigned i = 1; i < n; ++r) i <<= 1;
return r;
}
template <class T> template <class T>
inline unsigned inline unsigned
wordOf(unsigned i) wordOf(unsigned i)
@ -582,57 +535,6 @@ equal(const void* a, unsigned al, const void* b, unsigned bl)
} }
} }
class Machine;
class Thread;
struct Object { };
typedef Object* object;
typedef uint8_t jboolean;
typedef int8_t jbyte;
typedef uint16_t jchar;
typedef int16_t jshort;
typedef int32_t jint;
typedef int64_t jlong;
typedef float jfloat;
typedef double jdouble;
typedef jint jsize;
typedef object* jobject;
typedef jobject jclass;
typedef jobject jthrowable;
typedef jobject jstring;
typedef jobject jweak;
typedef jobject jarray;
typedef jarray jbooleanArray;
typedef jarray jbyteArray;
typedef jarray jcharArray;
typedef jarray jshortArray;
typedef jarray jintArray;
typedef jarray jlongArray;
typedef jarray jfloatArray;
typedef jarray jdoubleArray;
typedef jarray jobjectArray;
typedef uintptr_t jfieldID;
typedef uintptr_t jmethodID;
union jvalue {
jboolean z;
jbyte b;
jchar c;
jshort s;
jint i;
jlong j;
jfloat f;
jdouble d;
jobject l;
};
} // namespace vm } // namespace vm
#endif//COMMON_H #endif // COMMON_H

View File

@ -13,12 +13,13 @@
#include "alloc-vector.h" #include "alloc-vector.h"
#include "process.h" #include "process.h"
#include "target.h" #include "target.h"
#include "codegen/assembler.h"
#include "codegen/compiler.h"
#include "codegen/targets.h"
#include "arch.h" #include "arch.h"
#include "util/runtime-array.h" #include <avian/vm/codegen/assembler.h>
#include <avian/vm/codegen/compiler.h>
#include <avian/vm/codegen/targets.h>
#include <avian/util/runtime-array.h>
using namespace vm; using namespace vm;

View File

@ -8,15 +8,17 @@
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 <avian/vm/system/system.h>
#include <avian/util/string.h>
#include <avian/util/runtime-array.h>
#include "zlib-custom.h" #include "zlib-custom.h"
#include "system.h"
#include "tokenizer.h"
#include "finder.h" #include "finder.h"
#include "lzma.h" #include "lzma.h"
#include "util/runtime-array.h"
using namespace vm; using namespace vm;
using namespace avian::util;
namespace { namespace {
@ -658,12 +660,12 @@ addTokens(System* s, Element** first, Element** last, Allocator* allocator,
const char* jarName, unsigned jarNameBase, const char* tokens, const char* jarName, unsigned jarNameBase, const char* tokens,
unsigned tokensLength, const char* bootLibrary) unsigned tokensLength, const char* bootLibrary)
{ {
for (Tokenizer t(tokens, tokensLength, ' '); t.hasMore();) { for (Tokenizer t(String(tokens, tokensLength), ' '); t.hasMore();) {
Tokenizer::Token token(t.next()); String token(t.next());
RUNTIME_ARRAY(char, n, jarNameBase + token.length + 1); RUNTIME_ARRAY(char, n, jarNameBase + token.length + 1);
memcpy(RUNTIME_ARRAY_BODY(n), jarName, jarNameBase); memcpy(RUNTIME_ARRAY_BODY(n), jarName, jarNameBase);
memcpy(RUNTIME_ARRAY_BODY(n) + jarNameBase, token.s, token.length); memcpy(RUNTIME_ARRAY_BODY(n) + jarNameBase, token.text, token.length);
RUNTIME_ARRAY_BODY(n)[jarNameBase + token.length] = 0; RUNTIME_ARRAY_BODY(n)[jarNameBase + token.length] = 0;
add(s, first, last, allocator, RUNTIME_ARRAY_BODY(n), add(s, first, last, allocator, RUNTIME_ARRAY_BODY(n),
@ -813,9 +815,9 @@ parsePath(System* s, Allocator* allocator, const char* path,
Element* first = 0; Element* first = 0;
Element* last = 0; Element* last = 0;
for (Tokenizer t(path, s->pathSeparator()); t.hasMore();) { for (Tokenizer t(path, s->pathSeparator()); t.hasMore();) {
Tokenizer::Token token(t.next()); String token(t.next());
add(s, &first, &last, allocator, token.s, token.length, bootLibrary); add(s, &first, &last, allocator, token.text, token.length, bootLibrary);
} }
return first; return first;

View File

@ -12,7 +12,7 @@
#define FINDER_H #define FINDER_H
#include "common.h" #include "common.h"
#include "system.h" #include <avian/vm/system/system.h>
#include "allocator.h" #include "allocator.h"
namespace vm { namespace vm {

View File

@ -8,12 +8,15 @@
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 "heap/heap.h" #include <avian/vm/heap/heap.h>
#include "system.h" #include <avian/vm/system/system.h>
#include "common.h" #include "common.h"
#include "arch.h" #include "arch.h"
#include <avian/util/math.h>
using namespace vm; using namespace vm;
using namespace avian::util;
namespace { namespace {

View File

@ -12,6 +12,7 @@
#define HEAPWALK_H #define HEAPWALK_H
#include "common.h" #include "common.h"
#include "java-common.h"
namespace vm { namespace vm {

View File

@ -9,14 +9,14 @@
details. */ details. */
#include "common.h" #include "common.h"
#include "system.h" #include <avian/vm/system/system.h>
#include "constants.h" #include "constants.h"
#include "machine.h" #include "machine.h"
#include "processor.h" #include "processor.h"
#include "process.h" #include "process.h"
#include "arch.h" #include "arch.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
using namespace vm; using namespace vm;
@ -2325,19 +2325,20 @@ interpret3(Thread* t, const int base)
THREAD_RUNTIME_ARRAY(t, int32_t, counts, dimensions); THREAD_RUNTIME_ARRAY(t, int32_t, counts, dimensions);
for (int i = dimensions - 1; i >= 0; --i) { for (int i = dimensions - 1; i >= 0; --i) {
counts[i] = popInt(t); RUNTIME_ARRAY_BODY(counts)[i] = popInt(t);
if (UNLIKELY(counts[i] < 0)) { if (UNLIKELY(RUNTIME_ARRAY_BODY(counts)[i] < 0)) {
exception = makeThrowable exception = makeThrowable
(t, Machine::NegativeArraySizeExceptionType, "%d", counts[i]); (t, Machine::NegativeArraySizeExceptionType, "%d",
RUNTIME_ARRAY_BODY(counts)[i]);
goto throw_; goto throw_;
} }
} }
object array = makeArray(t, counts[0]); object array = makeArray(t, RUNTIME_ARRAY_BODY(counts)[0]);
setObjectClass(t, array, class_); setObjectClass(t, array, class_);
PROTECT(t, array); PROTECT(t, array);
populateMultiArray(t, array, counts, 0, dimensions); populateMultiArray(t, array, RUNTIME_ARRAY_BODY(counts), 0, dimensions);
pushObject(t, array); pushObject(t, array);
} goto loop; } goto loop;

69
src/java-common.h Normal file
View File

@ -0,0 +1,69 @@
/* Copyright (c) 2008-2012, 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 JAVA_COMMON_H
#define JAVA_COMMON_H
namespace vm {
class Machine;
class Thread;
struct Object { };
typedef Object* object;
typedef uint8_t jboolean;
typedef int8_t jbyte;
typedef uint16_t jchar;
typedef int16_t jshort;
typedef int32_t jint;
typedef int64_t jlong;
typedef float jfloat;
typedef double jdouble;
typedef jint jsize;
typedef object* jobject;
typedef jobject jclass;
typedef jobject jthrowable;
typedef jobject jstring;
typedef jobject jweak;
typedef jobject jarray;
typedef jarray jbooleanArray;
typedef jarray jbyteArray;
typedef jarray jcharArray;
typedef jarray jshortArray;
typedef jarray jintArray;
typedef jarray jlongArray;
typedef jarray jfloatArray;
typedef jarray jdoubleArray;
typedef jarray jobjectArray;
typedef uintptr_t jfieldID;
typedef uintptr_t jmethodID;
union jvalue {
jboolean z;
jbyte b;
jchar c;
jshort s;
jint i;
jlong j;
jfloat f;
jdouble d;
jobject l;
};
} // namespace vm
#endif // JAVA_COMMON_H

View File

@ -14,7 +14,7 @@
#include "processor.h" #include "processor.h"
#include "constants.h" #include "constants.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
using namespace vm; using namespace vm;

View File

@ -13,7 +13,7 @@
#include "lzma.h" #include "lzma.h"
#include "C/Types.h" #include "C/Types.h"
#include "system.h" #include <avian/vm/system/system.h>
#include "allocator.h" #include "allocator.h"
namespace vm { namespace vm {

View File

@ -11,7 +11,7 @@
#ifndef LZMA_H #ifndef LZMA_H
#define LZMA_H #define LZMA_H
#include "system.h" #include <avian/vm/system/system.h>
#include "allocator.h" #include "allocator.h"
namespace vm { namespace vm {

View File

@ -11,13 +11,14 @@
#include "jnienv.h" #include "jnienv.h"
#include "machine.h" #include "machine.h"
#include "util.h" #include "util.h"
#include "stream.h" #include <avian/util/stream.h>
#include "constants.h" #include "constants.h"
#include "processor.h" #include "processor.h"
#include "arch.h" #include "arch.h"
#include "lzma.h" #include "lzma.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
#include <avian/util/math.h>
#if defined(PLATFORM_WINDOWS) #if defined(PLATFORM_WINDOWS)
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
@ -25,6 +26,7 @@
#endif #endif
using namespace vm; using namespace vm;
using namespace avian::util;
namespace { namespace {
@ -4796,13 +4798,13 @@ logTrace(FILE* f, const char* fmt, ...)
RUNTIME_ARRAY(char, buffer, length + 1); RUNTIME_ARRAY(char, buffer, length + 1);
va_start(a, fmt); va_start(a, fmt);
vsnprintf(&buffer[0], length + 1, fmt, a); vsnprintf(RUNTIME_ARRAY_BODY(buffer), length + 1, fmt, a);
va_end(a); va_end(a);
buffer[length] = 0; RUNTIME_ARRAY_BODY(buffer)[length] = 0;
::fprintf(f, "%s", &buffer[0]); ::fprintf(f, "%s", RUNTIME_ARRAY_BODY(buffer));
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
::OutputDebugStringA(&buffer[0]); ::OutputDebugStringA(RUNTIME_ARRAY_BODY(buffer));
#endif #endif
} }

View File

@ -12,13 +12,16 @@
#define MACHINE_H #define MACHINE_H
#include "common.h" #include "common.h"
#include "system.h" #include "java-common.h"
#include "heap/heap.h" #include <avian/vm/system/system.h>
#include <avian/vm/heap/heap.h>
#include "finder.h" #include "finder.h"
#include "processor.h" #include "processor.h"
#include "constants.h" #include "constants.h"
#include "arch.h" #include "arch.h"
using namespace avian::util;
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
# define JNICALL __stdcall # define JNICALL __stdcall
#else #else
@ -1614,7 +1617,8 @@ class ThreadRuntimeArray: public Thread::Resource {
#else // not _MSC_VER #else // not _MSC_VER
# define THREAD_RUNTIME_ARRAY(thread, type, name, size) type name[size]; # define THREAD_RUNTIME_ARRAY(thread, type, name, size) \
type name##_body[size];
#endif // not _MSC_VER #endif // not _MSC_VER

View File

@ -13,10 +13,10 @@
#include "string.h" #include "string.h"
#include "jni.h" #include "jni.h"
#include "system.h" #include <avian/vm/system/system.h>
#include "finder.h" #include "finder.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
#if (defined __MINGW32__) || (defined _MSC_VER) #if (defined __MINGW32__) || (defined _MSC_VER)
# define PATH_SEPARATOR ';' # define PATH_SEPARATOR ';'

View File

@ -10,7 +10,7 @@
#include "process.h" #include "process.h"
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
using namespace vm; using namespace vm;

View File

@ -12,7 +12,7 @@
#define PROCESS_H #define PROCESS_H
#include "common.h" #include "common.h"
#include "system.h" #include <avian/vm/system/system.h>
#include "machine.h" #include "machine.h"
#include "constants.h" #include "constants.h"

View File

@ -12,8 +12,8 @@
#define PROCESSOR_H #define PROCESSOR_H
#include "common.h" #include "common.h"
#include "system.h" #include <avian/vm/system/system.h>
#include "heap/heap.h" #include <avian/vm/heap/heap.h>
#include "bootimage.h" #include "bootimage.h"
#include "heapwalk.h" #include "heapwalk.h"
#include "zone.h" #include "zone.h"

View File

@ -22,7 +22,7 @@
#endif #endif
#include <fcntl.h> #include <fcntl.h>
#include "tools.h" #include <avian/tools/object-writer/tools.h>
extern "C" extern "C"
void __cxa_pure_virtual() { void __cxa_pure_virtual() {

View File

@ -8,16 +8,17 @@
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 "heap/heap.h" #include <avian/vm/heap/heap.h>
#include "heapwalk.h" #include "heapwalk.h"
#include "common.h" #include "common.h"
#include "machine.h" #include "machine.h"
#include "util.h" #include "util.h"
#include "stream.h" #include <avian/util/stream.h>
#include "codegen/assembler.h" #include <avian/vm/codegen/assembler.h>
#include "codegen/promise.h" #include <avian/vm/codegen/promise.h>
#include "target.h" #include "target.h"
#include "binaryToObject/tools.h" #include <avian/tools/object-writer/tools.h>
#include <avian/util/runtime-array.h>
#include "lzma.h" #include "lzma.h"
// since we aren't linking against libstdc++, we must implement this // since we aren't linking against libstdc++, we must implement this
@ -345,20 +346,20 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
unsigned count = s.read2() - 1; unsigned count = s.read2() - 1;
if (count) { if (count) {
THREAD_RUNTIME_ARRAY(t, Type, types, count + 2); THREAD_RUNTIME_ARRAY(t, Type, types, count + 2);
types[0] = Type_object; RUNTIME_ARRAY_BODY(types)[0] = Type_object;
types[1] = Type_intptr_t; RUNTIME_ARRAY_BODY(types)[1] = Type_intptr_t;
for (unsigned i = 2; i < count + 2; ++i) { for (unsigned i = 2; i < count + 2; ++i) {
switch (s.read1()) { switch (s.read1()) {
case CONSTANT_Class: case CONSTANT_Class:
case CONSTANT_String: case CONSTANT_String:
types[i] = Type_object; RUNTIME_ARRAY_BODY(types)[i] = Type_object;
s.skip(2); s.skip(2);
break; break;
case CONSTANT_Integer: case CONSTANT_Integer:
case CONSTANT_Float: case CONSTANT_Float:
types[i] = Type_int32_t; RUNTIME_ARRAY_BODY(types)[i] = Type_int32_t;
s.skip(4); s.skip(4);
break; break;
@ -366,24 +367,24 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
case CONSTANT_Fieldref: case CONSTANT_Fieldref:
case CONSTANT_Methodref: case CONSTANT_Methodref:
case CONSTANT_InterfaceMethodref: case CONSTANT_InterfaceMethodref:
types[i] = Type_object; RUNTIME_ARRAY_BODY(types)[i] = Type_object;
s.skip(4); s.skip(4);
break; break;
case CONSTANT_Long: case CONSTANT_Long:
types[i++] = Type_int64_t; RUNTIME_ARRAY_BODY(types)[i++] = Type_int64_t;
types[i] = Type_int64_t_pad; RUNTIME_ARRAY_BODY(types)[i] = Type_int64_t_pad;
s.skip(8); s.skip(8);
break; break;
case CONSTANT_Double: case CONSTANT_Double:
types[i++] = Type_double; RUNTIME_ARRAY_BODY(types)[i++] = Type_double;
types[i] = Type_double_pad; RUNTIME_ARRAY_BODY(types)[i] = Type_double_pad;
s.skip(8); s.skip(8);
break; break;
case CONSTANT_Utf8: case CONSTANT_Utf8:
types[i] = Type_object; RUNTIME_ARRAY_BODY(types)[i] = Type_object;
s.skip(s.read2()); s.skip(s.read2());
break; break;
@ -403,7 +404,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
map->targetFixedOffsets()[i * BytesPerWord] map->targetFixedOffsets()[i * BytesPerWord]
= i * TargetBytesPerWord; = i * TargetBytesPerWord;
init(new (map->fixedFields() + i) Field, types[i], init(new (map->fixedFields() + i) Field, RUNTIME_ARRAY_BODY(types)[i],
i * BytesPerWord, BytesPerWord, i * TargetBytesPerWord, i * BytesPerWord, BytesPerWord, i * TargetBytesPerWord,
TargetBytesPerWord); TargetBytesPerWord);
} }
@ -439,15 +440,15 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
for (unsigned j = 0; j < map->fixedFieldCount; ++j) { for (unsigned j = 0; j < map->fixedFieldCount; ++j) {
Field* f = map->fixedFields() + j; Field* f = map->fixedFields() + j;
memberFields[memberIndex] = *f; RUNTIME_ARRAY_BODY(memberFields)[memberIndex] = *f;
targetMemberOffset = f->targetOffset + f->targetSize; targetMemberOffset = f->targetOffset + f->targetSize;
++ memberIndex; ++ memberIndex;
} }
} else { } else {
init(new (&memberFields[0]) Field, Type_object, 0, BytesPerWord, 0, init(new (RUNTIME_ARRAY_BODY(memberFields)) Field, Type_object, 0,
TargetBytesPerWord); BytesPerWord, 0, TargetBytesPerWord);
memberIndex = 1; memberIndex = 1;
buildMemberOffset = BytesPerWord; buildMemberOffset = BytesPerWord;
@ -458,14 +459,16 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
THREAD_RUNTIME_ARRAY(t, Field, staticFields, count + StaticHeader); THREAD_RUNTIME_ARRAY(t, Field, staticFields, count + StaticHeader);
init(new (&staticFields[0]) Field, Type_object, 0, BytesPerWord, 0, init(new (RUNTIME_ARRAY_BODY(staticFields)) Field, Type_object, 0,
BytesPerWord, 0, TargetBytesPerWord);
init(new (RUNTIME_ARRAY_BODY(staticFields) + 1) Field, Type_intptr_t,
BytesPerWord, BytesPerWord, TargetBytesPerWord,
TargetBytesPerWord); TargetBytesPerWord);
init(new (&staticFields[1]) Field, Type_intptr_t, BytesPerWord, init(new (RUNTIME_ARRAY_BODY(staticFields) + 2) Field, Type_object,
BytesPerWord, TargetBytesPerWord, TargetBytesPerWord); BytesPerWord * 2, BytesPerWord, TargetBytesPerWord * 2,
TargetBytesPerWord);
init(new (&staticFields[2]) Field, Type_object, BytesPerWord * 2,
BytesPerWord, TargetBytesPerWord * 2, TargetBytesPerWord);
unsigned staticIndex = StaticHeader; unsigned staticIndex = StaticHeader;
unsigned buildStaticOffset = BytesPerWord * StaticHeader; unsigned buildStaticOffset = BytesPerWord * StaticHeader;
@ -514,8 +517,8 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
buildStaticOffset = fieldOffset(t, field); buildStaticOffset = fieldOffset(t, field);
init(new (&staticFields[staticIndex]) Field, type, init(new (RUNTIME_ARRAY_BODY(staticFields) + staticIndex) Field,
buildStaticOffset, buildSize, targetStaticOffset, type, buildStaticOffset, buildSize, targetStaticOffset,
targetSize); targetSize);
targetStaticOffset += targetSize; targetStaticOffset += targetSize;
@ -528,8 +531,8 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
buildMemberOffset = fieldOffset(t, field); buildMemberOffset = fieldOffset(t, field);
init(new (&memberFields[memberIndex]) Field, type, init(new (RUNTIME_ARRAY_BODY(memberFields) + memberIndex) Field,
buildMemberOffset, buildSize, targetMemberOffset, type, buildMemberOffset, buildSize, targetMemberOffset,
targetSize); targetSize);
targetMemberOffset += targetSize; targetMemberOffset += targetSize;
@ -551,7 +554,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
ceilingDivide(targetMemberOffset, TargetBytesPerWord), memberIndex); ceilingDivide(targetMemberOffset, TargetBytesPerWord), memberIndex);
for (unsigned i = 0; i < memberIndex; ++i) { for (unsigned i = 0; i < memberIndex; ++i) {
Field* f = &memberFields[i]; Field* f = RUNTIME_ARRAY_BODY(memberFields) + i;
expect(t, f->buildOffset expect(t, f->buildOffset
< map->buildFixedSizeInWords * BytesPerWord); < map->buildFixedSizeInWords * BytesPerWord);
@ -575,7 +578,7 @@ makeCodeImage(Thread* t, Zone* zone, BootImage* image, uint8_t* code,
TypeMap::SingletonKind); TypeMap::SingletonKind);
for (unsigned i = 0; i < staticIndex; ++i) { for (unsigned i = 0; i < staticIndex; ++i) {
Field* f = &staticFields[i]; Field* f = RUNTIME_ARRAY_BODY(staticFields) + i;
expect(t, f->buildOffset expect(t, f->buildOffset
< map->buildFixedSizeInWords * BytesPerWord); < map->buildFixedSizeInWords * BytesPerWord);
@ -1338,8 +1341,8 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
THREAD_RUNTIME_ARRAY(t, Field, fields, count); THREAD_RUNTIME_ARRAY(t, Field, fields, count);
init(new (&fields[0]) Field, Type_object, 0, BytesPerWord, 0, init(new (RUNTIME_ARRAY_BODY(fields)) Field, Type_object, 0,
TargetBytesPerWord); BytesPerWord, 0, TargetBytesPerWord);
unsigned buildOffset = BytesPerWord; unsigned buildOffset = BytesPerWord;
unsigned targetOffset = TargetBytesPerWord; unsigned targetOffset = TargetBytesPerWord;
@ -1416,8 +1419,8 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
++ targetOffset; ++ targetOffset;
} }
init(new (&fields[j]) Field, type, buildOffset, buildSize, init(new (RUNTIME_ARRAY_BODY(fields) + j) Field, type, buildOffset,
targetOffset, targetSize); buildSize, targetOffset, targetSize);
buildOffset += buildSize; buildOffset += buildSize;
targetOffset += targetSize; targetOffset += targetSize;
@ -1451,7 +1454,7 @@ writeBootImage2(Thread* t, OutputStream* bootimageOutput, OutputStream* codeOutp
targetArrayElementSize, arrayElementType); targetArrayElementSize, arrayElementType);
for (unsigned j = 0; j < fixedFieldCount; ++j) { for (unsigned j = 0; j < fixedFieldCount; ++j) {
Field* f = &fields[j]; Field* f = RUNTIME_ARRAY_BODY(fields) + j;
expect(t, f->buildOffset expect(t, f->buildOffset
< map->buildFixedSizeInWords * BytesPerWord); < map->buildFixedSizeInWords * BytesPerWord);

View File

@ -15,7 +15,7 @@
#include "endianness.h" #include "endianness.h"
#include "tools.h" #include <avian/tools/object-writer/tools.h>
#define EI_NIDENT 16 #define EI_NIDENT 16
@ -72,6 +72,7 @@
namespace { namespace {
using namespace avian::tools; using namespace avian::tools;
using namespace avian::util;
template<class AddrTy> template<class AddrTy>
struct ElfTypes { struct ElfTypes {

View File

@ -14,7 +14,7 @@
#include "endianness.h" #include "endianness.h"
#include "tools.h" #include <avian/tools/object-writer/tools.h>
#define MH_MAGIC_64 0xfeedfacf #define MH_MAGIC_64 0xfeedfacf
#define MH_MAGIC 0xfeedface #define MH_MAGIC 0xfeedface
@ -43,6 +43,7 @@
namespace { namespace {
using namespace avian::tools; using namespace avian::tools;
using namespace avian::util;
typedef int cpu_type_t; typedef int cpu_type_t;
typedef int cpu_subtype_t; typedef int cpu_subtype_t;

View File

@ -13,7 +13,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "tools.h" #include <avian/tools/object-writer/tools.h>
namespace { namespace {
@ -86,6 +86,7 @@ pad(unsigned n)
} }
using namespace avian::tools; using namespace avian::tools;
using namespace avian::util;
template<unsigned BytesPerWord, PlatformInfo::Architecture Architecture> template<unsigned BytesPerWord, PlatformInfo::Architecture Architecture>
class WindowsPlatform : public Platform { class WindowsPlatform : public Platform {

View File

@ -13,16 +13,14 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "tools.h" #include <avian/tools/object-writer/tools.h>
using namespace avian::util;
namespace avian { namespace avian {
namespace tools { namespace tools {
String::String(const char* text):
text(text),
length(strlen(text)) {}
Buffer::Buffer(): Buffer::Buffer():
capacity(100), capacity(100),
length(0), length(0),

View File

@ -0,0 +1,149 @@
/* 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. */
#include "assert.h"
#ifndef AVIAN_TOOLS_TYPE_GENERATOR_IO_H
#define AVIAN_TOOLS_TYPE_GENERATOR_IO_H
namespace avian {
namespace tools {
namespace typegenerator {
class Input {
public:
virtual ~Input() { }
virtual void dispose() = 0;
virtual int peek() = 0;
virtual int read() = 0;
virtual unsigned line() = 0;
virtual unsigned column() = 0;
void skipSpace() {
bool quit = false;
while (not quit) {
int c = peek();
switch (c) {
case ' ': case '\t': case '\n':
read();
break;
default: quit = true;
}
}
}
};
class FileInput : public Input {
public:
const char* file;
FILE* stream;
unsigned line_;
unsigned column_;
bool close;
FileInput(const char* file, FILE* stream = 0, bool close = true):
file(file), stream(stream), line_(1), column_(1), close(close)
{ }
virtual ~FileInput() {
dispose();
}
virtual void dispose() {
if (stream and close) {
fclose(stream);
stream = 0;
}
}
virtual int peek() {
int c = getc(stream);
ungetc(c, stream);
return c;
}
virtual int read() {
int c = getc(stream);
if (c == '\n') {
++ line_;
column_ = 1;
} else {
++ column_;
}
return c;
}
virtual unsigned line() {
return line_;
}
virtual unsigned column() {
return column_;
}
};
class Output {
public:
virtual ~Output() { }
virtual void dispose() = 0;
virtual void write(const char* s) = 0;
void write(int i) {
static const int Size = 32;
char s[Size];
int c UNUSED = ::snprintf(s, Size, "%d", i);
assert(c > 0 and c < Size);
write(s);
}
};
class FileOutput : public Output {
public:
const char* file;
FILE* stream;
bool close;
FileOutput(const char* file, FILE* stream = 0, bool close = true):
file(file), stream(stream), close(close)
{ }
virtual ~FileOutput() {
dispose();
}
virtual void dispose() {
if (stream and close) {
fclose(stream);
stream = 0;
}
}
virtual void write(const char* s) {
fputs(s, stream);
}
const char* filename() {
return file;
}
};
} // namespace typegenerator
} // namespace tools
} // namespace avian
#endif // AVIAN_TOOLS_TYPE_GENERATOR_IO_H

View File

@ -16,7 +16,10 @@
#include "constants.h" #include "constants.h"
#include "finder.h" #include "finder.h"
#include "stream.h" #include <avian/util/stream.h>
#include "io.h"
#include "sexpr.h"
#include "assert.h" #include "assert.h"
@ -29,6 +32,7 @@ inline void operator delete(void*) { abort(); }
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::typegenerator;
namespace { namespace {
@ -55,15 +59,6 @@ pad(unsigned n)
return (extra ? n + BytesPerWord - extra : n); return (extra ? n + BytesPerWord - extra : n);
} }
template <class T>
T*
allocate()
{
T* t = static_cast<T*>(malloc(sizeof(T)));
assert(t);
return t;
}
inline bool inline bool
equal(const char* a, const char* b) equal(const char* a, const char* b)
{ {
@ -88,214 +83,6 @@ take(unsigned n, const char* c)
return r; return r;
} }
class Input {
public:
virtual ~Input() { }
virtual void dispose() = 0;
virtual int peek() = 0;
virtual int read() = 0;
virtual unsigned line() = 0;
virtual unsigned column() = 0;
void skipSpace() {
bool quit = false;
while (not quit) {
int c = peek();
switch (c) {
case ' ': case '\t': case '\n':
read();
break;
default: quit = true;
}
}
}
};
class FileInput : public Input {
public:
const char* file;
FILE* stream;
unsigned line_;
unsigned column_;
bool close;
FileInput(const char* file, FILE* stream = 0, bool close = true):
file(file), stream(stream), line_(1), column_(1), close(close)
{ }
virtual ~FileInput() {
dispose();
}
virtual void dispose() {
if (stream and close) {
fclose(stream);
stream = 0;
}
}
virtual int peek() {
int c = getc(stream);
ungetc(c, stream);
return c;
}
virtual int read() {
int c = getc(stream);
if (c == '\n') {
++ line_;
column_ = 1;
} else {
++ column_;
}
return c;
}
virtual unsigned line() {
return line_;
}
virtual unsigned column() {
return column_;
}
};
class Output {
public:
virtual ~Output() { }
virtual void dispose() = 0;
virtual void write(const char* s) = 0;
void write(int i) {
static const int Size = 32;
char s[Size];
int c UNUSED = ::snprintf(s, Size, "%d", i);
assert(c > 0 and c < Size);
write(s);
}
};
class FileOutput : public Output {
public:
const char* file;
FILE* stream;
bool close;
FileOutput(const char* file, FILE* stream = 0, bool close = true):
file(file), stream(stream), close(close)
{ }
virtual ~FileOutput() {
dispose();
}
virtual void dispose() {
if (stream and close) {
fclose(stream);
stream = 0;
}
}
virtual void write(const char* s) {
fputs(s, stream);
}
const char* filename() {
return file;
}
};
class Object {
public:
typedef enum {
Scalar,
Array,
Method,
Type,
Pair,
Number,
Character,
String,
Eos
} ObjectType;
ObjectType type;
};
class Pair : public Object {
public:
Object* car;
Object* cdr;
static Pair* make(Object* car, Object* cdr) {
Pair* o = allocate<Pair>();
o->type = Object::Pair;
o->car = car;
o->cdr = cdr;
return o;
}
};
Object*
cons(Object* car, Object* cdr)
{
return Pair::make(car, cdr);
}
Object*&
car(Object* o)
{
assert(o->type == Object::Pair);
return static_cast<Pair*>(o)->car;
}
void
setCar(Object* o, Object* v)
{
assert(o->type == Object::Pair);
static_cast<Pair*>(o)->car = v;
}
Object*&
cdr(Object* o)
{
assert(o->type == Object::Pair);
return static_cast<Pair*>(o)->cdr;
}
void
setCdr(Object* o, Object* v)
{
assert(o->type == Object::Pair);
static_cast<Pair*>(o)->cdr = v;
}
class List {
public:
Object* first;
Object* last;
List(): first(0), last(0) { }
void append(Object* o) {
Object* p = cons(o, 0);
if (last) {
setCdr(last, p);
last = p;
} else {
first = last = p;
}
}
};
class Scalar : public Object { class Scalar : public Object {
public: public:
Object* owner; Object* owner;
@ -2176,9 +1963,9 @@ main(int ac, char** av)
fprintf(stderr, "unable to open %s: %s\n", av[2], strerror(errno)); fprintf(stderr, "unable to open %s: %s\n", av[2], strerror(errno));
return -1; return -1;
} }
local::FileInput in(0, inStream, false); FileInput in(0, inStream, false);
local::Object* declarations = local::parse(finder, &in); Object* declarations = local::parse(finder, &in);
finder->dispose(); finder->dispose();
system->dispose(); system->dispose();
@ -2188,7 +1975,7 @@ main(int ac, char** av)
fprintf(stderr, "unable to open %s: %s\n", av[3], strerror(errno)); fprintf(stderr, "unable to open %s: %s\n", av[3], strerror(errno));
return -1; return -1;
} }
local::FileOutput out(0, outStream, false); FileOutput out(0, outStream, false);
if (local::equal(av[4], "enums")) { if (local::equal(av[4], "enums")) {
local::writeEnums(&out, declarations); local::writeEnums(&out, declarations);

View File

@ -0,0 +1,102 @@
/* 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_TOOLS_TYPE_GENERATOR_SEXPR_H
#define AVIAN_TOOLS_TYPE_GENERATOR_SEXPR_H
namespace avian {
namespace tools {
namespace typegenerator {
template <class T>
inline T* allocate() {
T* t = static_cast<T*>(malloc(sizeof(T)));
assert(t);
return t;
}
class Object {
public:
typedef enum {
Scalar,
Array,
Method,
Type,
Pair,
Number,
Character,
String,
Eos
} ObjectType;
ObjectType type;
};
class Pair : public Object {
public:
Object* car;
Object* cdr;
static Pair* make(Object* car, Object* cdr) {
Pair* o = allocate<Pair>();
o->type = Object::Pair;
o->car = car;
o->cdr = cdr;
return o;
}
};
inline Object* cons(Object* car, Object* cdr) {
return Pair::make(car, cdr);
}
inline Object*& car(Object* o) {
assert(o->type == Object::Pair);
return static_cast<Pair*>(o)->car;
}
inline void setCar(Object* o, Object* v) {
assert(o->type == Object::Pair);
static_cast<Pair*>(o)->car = v;
}
inline Object*& cdr(Object* o) {
assert(o->type == Object::Pair);
return static_cast<Pair*>(o)->cdr;
}
inline void setCdr(Object* o, Object* v) {
assert(o->type == Object::Pair);
static_cast<Pair*>(o)->cdr = v;
}
class List {
public:
Object* first;
Object* last;
List(): first(0), last(0) { }
void append(Object* o) {
Object* p = cons(o, 0);
if (last) {
setCdr(last, p);
last = p;
} else {
first = last = p;
}
}
};
} // namespace typegenerator
} // namespace tools
} // namespace avian
#endif // AVIAN_TOOLS_TYPE_GENERATOR_SEXPR_H

View File

@ -49,12 +49,15 @@
#include "dirent.h" #include "dirent.h"
#include "sched.h" #include "sched.h"
#include "arch.h" #include "arch.h"
#include "system.h" #include <avian/vm/system/system.h>
#include <avian/util/math.h>
#define ACQUIRE(x) MutexResource MAKE_NAME(mutexResource_) (x) #define ACQUIRE(x) MutexResource MAKE_NAME(mutexResource_) (x)
using namespace vm; using namespace vm;
using namespace avian::util;
namespace { namespace {

View File

@ -24,8 +24,8 @@
#undef min #undef min
#include "arch.h" #include "arch.h"
#include "system.h" #include <avian/vm/system/system.h>
#include "util/runtime-array.h" #include <avian/util/runtime-array.h>
#if defined(WINAPI_FAMILY) #if defined(WINAPI_FAMILY)
@ -806,12 +806,12 @@ class MySystem: public System {
Status status = 1; Status status = 1;
size_t nameLen = strlen(name) * 2; size_t nameLen = strlen(name) * 2;
RUNTIME_ARRAY(wchar_t, wideName, nameLen + 1); RUNTIME_ARRAY(wchar_t, wideName, nameLen + 1);
MultiByteToWideChar(CP_UTF8, 0, name, -1, wideName, nameLen + 1); MultiByteToWideChar(CP_UTF8, 0, name, -1, RUNTIME_ARRAY_BODY(wideName), nameLen + 1);
#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
HANDLE file = CreateFileW(wideName, FILE_READ_DATA, FILE_SHARE_READ, 0, HANDLE file = CreateFileW(RUNTIME_ARRAY_BODY(wideName), FILE_READ_DATA, FILE_SHARE_READ, 0,
OPEN_EXISTING, 0, 0); OPEN_EXISTING, 0, 0);
#else #else
HANDLE file = CreateFile2(wideName, GENERIC_READ, FILE_SHARE_READ, HANDLE file = CreateFile2(RUNTIME_ARRAY_BODY(wideName), GENERIC_READ, FILE_SHARE_READ,
OPEN_EXISTING, 0); OPEN_EXISTING, 0);
#endif #endif
if (file != INVALID_HANDLE_VALUE) { if (file != INVALID_HANDLE_VALUE) {
@ -883,10 +883,10 @@ class MySystem: public System {
virtual FileType stat(const char* name, unsigned* length) { virtual FileType stat(const char* name, unsigned* length) {
size_t nameLen = strlen(name) * 2; size_t nameLen = strlen(name) * 2;
RUNTIME_ARRAY(wchar_t, wideName, nameLen + 1); RUNTIME_ARRAY(wchar_t, wideName, nameLen + 1);
MultiByteToWideChar(CP_UTF8, 0, name, -1, wideName, nameLen + 1); MultiByteToWideChar(CP_UTF8, 0, name, -1, RUNTIME_ARRAY_BODY(wideName), nameLen + 1);
WIN32_FILE_ATTRIBUTE_DATA data; WIN32_FILE_ATTRIBUTE_DATA data;
if (GetFileAttributesExW if (GetFileAttributesExW
(wideName, GetFileExInfoStandard, &data)) (RUNTIME_ARRAY_BODY(wideName), GetFileExInfoStandard, &data))
{ {
if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
return TypeDirectory; return TypeDirectory;
@ -935,12 +935,12 @@ class MySystem: public System {
if (name) { if (name) {
size_t nameLen = nameLength * 2; size_t nameLen = nameLength * 2;
RUNTIME_ARRAY(wchar_t, wideName, nameLen + 1); RUNTIME_ARRAY(wchar_t, wideName, nameLen + 1);
MultiByteToWideChar(CP_UTF8, 0, name, -1, wideName, nameLen + 1); MultiByteToWideChar(CP_UTF8, 0, name, -1, RUNTIME_ARRAY_BODY(wideName), nameLen + 1);
#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
handle = LoadLibraryW(wideName); handle = LoadLibraryW(RUNTIME_ARRAY_BODY(wideName));
#else #else
handle = LoadPackagedLibrary(wideName, 0); handle = LoadPackagedLibrary(RUNTIME_ARRAY_BODY(wideName), 0);
#endif #endif
} else { } else {
#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #if !defined(WINAPI_FAMILY) || WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

View File

@ -11,9 +11,11 @@
#ifndef ZONE_H #ifndef ZONE_H
#define ZONE_H #define ZONE_H
#include "system.h" #include <avian/vm/system/system.h>
#include "allocator.h" #include "allocator.h"
#include <avian/util/math.h>
namespace vm { namespace vm {
class Zone: public Allocator { class Zone: public Allocator {
@ -59,8 +61,8 @@ class Zone: public Allocator {
bool tryEnsure(unsigned space) { bool tryEnsure(unsigned space) {
if (segment == 0 or segment->position + space > segment->size) { if (segment == 0 or segment->position + space > segment->size) {
unsigned size = padToPage unsigned size = padToPage
(max (avian::util::max
(space, max (space, avian::util::max
(minimumFootprint, segment == 0 ? 0 : segment->size * 2)) (minimumFootprint, segment == 0 ? 0 : segment->size * 2))
+ sizeof(Segment)); + sizeof(Segment));

View File

@ -11,13 +11,13 @@
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
#include "heap/heap.h" #include <avian/vm/heap/heap.h>
#include "system.h" #include <avian/vm/system/system.h>
#include "target.h" #include "target.h"
#include "codegen/assembler.h" #include <avian/vm/codegen/assembler.h>
#include "codegen/targets.h" #include <avian/vm/codegen/targets.h>
#include "codegen/lir.h" #include <avian/vm/codegen/lir.h>
#include "test-harness.h" #include "test-harness.h"