various performance tweaks and bugfixes

This commit is contained in:
Joel Dice 2007-08-19 13:45:51 -06:00
parent 747e7b0371
commit 59638543c7
13 changed files with 123 additions and 82 deletions

View File

@ -15,7 +15,7 @@ public class SystemClassLoader extends ClassLoader {
protected URL findResource(String name) {
if (resourceExists(name)) {
try {
return new URL("resource://" + name);
return new URL("resource:" + name);
} catch (MalformedURLException ignored) { }
}
return null;

View File

@ -23,6 +23,10 @@ public final class URL {
}
}
public String toString() {
return handler.toExternalForm(this);
}
public String getProtocol() {
return protocol;
}

View File

@ -52,9 +52,9 @@ public abstract class URLStreamHandler {
protected String toExternalForm(URL url) {
StringBuilder sb = new StringBuilder();
sb.append(url.getProtocol()).append("://");
sb.append(url.getProtocol()).append(":");
if (url.getHost() != null) {
sb.append(url.getHost());
sb.append("//").append(url.getHost());
if (url.getPort() >= 0) {
sb.append(":").append(url.getPort());
}

View File

@ -1,4 +1,4 @@
MAKEFLAGS = -s
#MAKEFLAGS = -s
arch = $(shell uname -m)
ifeq ($(arch),i586)
@ -15,7 +15,7 @@ cls = build/classes
src = src
classpath = classpath
test = test
jscheme = /tmp/jscheme
jscheme = $(HOME)/p/jscheme-7.2/src
input = $(cls)/References.class
@ -23,7 +23,10 @@ cxx = g++
cc = gcc
vg = nice valgrind --leak-check=full --num-callers=32 --db-attach=yes \
--freelist-vol=100000000
db = gdb --args
javac = javac
strip = :
show-size = :
warnings = -Wall -Wextra -Werror -Wold-style-cast -Wunused-parameter \
-Winit-self -Wconversion
@ -46,11 +49,9 @@ ifeq ($(mode),stress-major)
cflags += -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR
endif
ifeq ($(mode),fast)
cflags += -Os -DNDEBUG -DMONOLITHIC
endif
ifeq ($(mode),profile)
cflags += -Os -pg -DNDEBUG -DMONOLITHIC
lflags += -pg
cflags += -O3 -DNDEBUG
#strip = strip
#show-size = ls -l
endif
cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(bld)/%.o,$(x)))
@ -136,6 +137,8 @@ class-names = $(foreach x,$(1),$(call class-name,$(x)))
flags = -cp $(cls)
args = $(flags) $(call class-name,$(input))
jscheme-command = jscheme/REPL build/make.scm -main commandMain ""
.PHONY: build
build: $(executable)
@ -145,43 +148,41 @@ $(input): $(classpath-objects)
run: $(executable) $(input)
LD_LIBRARY_PATH=$(bld) $(<) $(args)
.PHONY: run-jscheme
run-jscheme: $(executable) $(input)
LD_LIBRARY_PATH=$(bld) $(<) -cp $(cls):$(jscheme) jscheme/REPL
.PHONY: debug
debug: $(executable) $(input)
LD_LIBRARY_PATH=$(bld) gdb --args $(<) $(args)
.PHONY: debug-jscheme
debug-jscheme: $(executable) $(input)
LD_LIBRARY_PATH=$(bld) gdb --args $(<) -cp $(cls):$(jscheme) \
jscheme/REPL
.PHONY: vg
vg: $(executable) $(input)
LD_LIBRARY_PATH=$(bld) $(vg) $(<) $(args)
.PHONY: vg-jscheme
vg-jscheme: $(executable) $(input)
LD_LIBRARY_PATH=$(bld) $(vg) $(<) -cp $(cls):$(jscheme) \
jscheme/REPL
.PHONY: profile-jscheme
profile-jscheme: $(executable) $(input)
echo '(+ 5 6)' | LD_LIBRARY_PATH=$(bld) $(<) -cp $(cls):$(jscheme) \
jscheme/REPL
.PHONY: test
test: $(executable) $(classpath-objects) $(test-classes)
LD_LIBRARY_PATH=$(bld) /bin/bash $(test)/test.sh \
$(<) $(mode) "$(flags)" $(call class-names,$(test-classes))
.PHONY: run-jscheme
run-jscheme: $(executable) $(input)
LD_LIBRARY_PATH=$(bld) $(<) -cp $(cls):$(jscheme) $(jscheme-command)
.PHONY: debug-jscheme
debug-jscheme: $(executable) $(input)
LD_LIBRARY_PATH=$(bld) $(db) $(<) -cp $(cls):$(jscheme) $(jscheme-command)
.PHONY: vg-jscheme
vg-jscheme: $(executable) $(input)
LD_LIBRARY_PATH=$(bld) $(vg) $(<) -cp $(cls):$(jscheme) $(jscheme-command)
.PHONY: clean
clean:
@echo "removing build"
rm -rf build
.PHONY: clean-native
clean-native:
@echo "removing $(bld)"
rm -rf $(bld)
gen-arg = $(shell echo $(1) | sed -e 's:$(bld)/type-\(.*\)\.cpp:\1:')
$(generated-code): %.cpp: $(src)/types.def $(generator-executable)
@echo "generating $(@)"
@ -232,6 +233,8 @@ $(jni-library): $(jni-objects)
$(executable): $(interpreter-objects) $(stdcpp-objects)
@echo "linking $(@)"
$(cc) $(lflags) $(^) -o $(@)
$(strip) --strip-all $(@)
$(show-size) $(@)
.PHONY: generator
generator: $(generator-executable)

View File

@ -618,8 +618,10 @@ populateBuiltinMap(Thread* t, object map)
reinterpret_cast<void*>(::Runtime_loadLibrary) },
{ "Java_java_lang_Runtime_gc",
reinterpret_cast<void*>(::Runtime_gc) },
{ "Java_java_lang_Runtiime_exit",
{ "Java_java_lang_Runtime_exit",
reinterpret_cast<void*>(::Runtime_exit) },
{ "Java_java_lang_Runtime_freeMemory",
reinterpret_cast<void*>(::Runtime_freeMemory) },
{ "Java_java_lang_String_intern",
reinterpret_cast<void*>(::String_intern) },
@ -689,9 +691,9 @@ populateBuiltinMap(Thread* t, object map)
{ "Java_java_net_URL_00024ResourceInputStream_open",
reinterpret_cast<void*>(::ResourceInputStream_open) },
{ "Java_java_net_URL_00024ResourceInputStream_read_JI",
{ "Java_java_net_URL_00024ResourceInputStream_read__JI",
reinterpret_cast<void*>(::ResourceInputStream_read) },
{ "Java_java_net_URL_00024ResourceInputStream_read_JI_3BII",
{ "Java_java_net_URL_00024ResourceInputStream_read__JI_3BII",
reinterpret_cast<void*>(::ResourceInputStream_read2) },
{ "Java_java_net_URL_00024ResourceInputStream_close",
reinterpret_cast<void*>(::ResourceInputStream_close) },

View File

@ -10,11 +10,12 @@
#include "math.h"
#ifdef __i386__
# define LD "%d"
# define LLD "%lld"
# define LD "d"
# define LLD "lld"
#elif defined __x86_64__
# define LD "%ld"
# define LLD "%ld"
# define LD "ld"
# define LLD "ld"
# define LLD "ld"
#endif
#define NO_RETURN __attribute__((noreturn))
@ -26,6 +27,8 @@
#define MACRO_MakeNameXY(FX, LINE) MACRO_XY(FX, LINE)
#define MAKE_NAME(FX) MACRO_MakeNameXY(FX, __LINE__)
#define UNUSED __attribute__((unused))
inline void* operator new(size_t, void* p) throw() { return p; }
namespace vm {

View File

@ -21,7 +21,9 @@ const bool Debug = false;
class Context;
void NO_RETURN abort(Context*);
#ifndef NDEBUG
void assert(Context*, bool);
#endif
System* system(Context*);
@ -410,7 +412,11 @@ class Context {
tenureFootprint(0),
gen1padding(0),
gen2padding(0),
mode(Heap::MinorCollection)
mode(Heap::MinorCollection),
lastCollectionTime(system->now()),
totalCollectionTime(0),
totalTime(0)
{ }
void dispose() {
@ -446,6 +452,10 @@ class Context {
unsigned gen2padding;
Heap::CollectionType mode;
int64_t lastCollectionTime;
int64_t totalCollectionTime;
int64_t totalTime;
};
inline System*
@ -476,11 +486,13 @@ abort(Context* c)
abort(c->system);
}
#ifndef NDEBUG
inline void
assert(Context* c, bool v)
{
assert(c->system, v);
}
#endif
inline void
initNextGen1(Context* c, unsigned footprint)
@ -540,21 +552,21 @@ wasCollected(Context* c, object o)
}
inline object
follow(Context* c, object o)
follow(Context* c UNUSED, object o)
{
assert(c, wasCollected(c, o));
return cast<object>(o, 0);
}
inline object&
parent(Context* c, object o)
parent(Context* c UNUSED, object o)
{
assert(c, wasCollected(c, o));
return cast<object>(o, BytesPerWord);
}
inline uintptr_t*
bitset(Context* c, object o)
bitset(Context* c UNUSED, object o)
{
assert(c, wasCollected(c, o));
return &cast<uintptr_t>(o, BytesPerWord * 2);
@ -982,7 +994,7 @@ collect(Context* c, object* p)
void
collect(Context* c, Segment::Map* map, unsigned start, unsigned end,
bool* dirty, bool expectDirty)
bool* dirty, bool expectDirty UNUSED)
{
bool wasDirty = false;
for (Segment::Map::Iterator it(map, start, end); it.hasMore();) {
@ -1060,9 +1072,9 @@ collect(Context* c, unsigned footprint)
int64_t then;
if (Verbose) {
if (c->mode == Heap::MajorCollection) {
fprintf(stderr, "major collection ");
fprintf(stderr, "major collection\n");
} else {
fprintf(stderr, "minor collection ");
fprintf(stderr, "minor collection\n");
}
then = c->system->now();
@ -1081,7 +1093,22 @@ collect(Context* c, unsigned footprint)
}
if (Verbose) {
fprintf(stderr, "- " LLD "ms\n", (c->system->now() - then));
int64_t now = c->system->now();
int64_t collection = now - then;
int64_t run = then - c->lastCollectionTime;
c->totalCollectionTime += collection;
c->totalTime += collection + run;
c->lastCollectionTime = now;
fprintf(stderr,
" - collect: %4"LLD"ms; "
"total: %4"LLD"ms; "
"run: %4"LLD"ms; "
"total: %4"LLD"ms\n",
collection,
c->totalCollectionTime,
run,
c->totalTime - c->totalCollectionTime);
}
}

View File

@ -2136,7 +2136,7 @@ parseClass(Thread* t, const uint8_t* data, unsigned size)
Stream s(&client, data, size);
uint32_t magic = s.read4();
assert(t, magic == 0xCAFEBABE);
expect(t, magic == 0xCAFEBABE);
s.read2(); // minor version
s.read2(); // major version

View File

@ -1193,7 +1193,7 @@ class Thread {
Thread* t;
};
static const unsigned HeapSizeInBytes = 64 * 1024;
static const unsigned HeapSizeInBytes = 512 * 1024;
static const unsigned StackSizeInBytes = 64 * 1024;
static const unsigned HeapSizeInWords = HeapSizeInBytes / BytesPerWord;
@ -1339,11 +1339,13 @@ abort(Thread* t)
abort(t->vm->system);
}
#ifndef NDEBUG
inline void
assert(Thread* t, bool v)
{
assert(t->vm->system, v);
}
#endif // not NDEBUG
inline void
expect(Thread* t, bool v)
@ -1601,7 +1603,7 @@ inline void
pushLong(Thread* t, uint64_t v)
{
if (DebugStack) {
fprintf(stderr, "push long " LLD " at %d\n", v, t->sp);
fprintf(stderr, "push long %"LLD" at %d\n", v, t->sp);
}
pushInt(t, v >> 32);
@ -1632,7 +1634,7 @@ inline uint32_t
popInt(Thread* t)
{
if (DebugStack) {
fprintf(stderr, "pop int " LD " at %d\n",
fprintf(stderr, "pop int %"LD" at %d\n",
t->stack[((t->sp - 1) * 2) + 1],
t->sp - 1);
}
@ -1653,7 +1655,7 @@ inline uint64_t
popLong(Thread* t)
{
if (DebugStack) {
fprintf(stderr, "pop long " LLD " at %d\n",
fprintf(stderr, "pop long %"LLD" at %d\n",
(static_cast<uint64_t>(t->stack[((t->sp - 2) * 2) + 1]) << 32)
| static_cast<uint64_t>(t->stack[((t->sp - 1) * 2) + 1]),
t->sp - 2);
@ -1690,7 +1692,7 @@ inline uint32_t
peekInt(Thread* t, unsigned index)
{
if (DebugStack) {
fprintf(stderr, "peek int " LD " at %d\n",
fprintf(stderr, "peek int %"LD" at %d\n",
t->stack[(index * 2) + 1],
index);
}
@ -1704,7 +1706,7 @@ inline uint64_t
peekLong(Thread* t, unsigned index)
{
if (DebugStack) {
fprintf(stderr, "peek long " LLD " at %d\n",
fprintf(stderr, "peek long %"LLD" at %d\n",
(static_cast<uint64_t>(t->stack[(index * 2) + 1]) << 32)
| static_cast<uint64_t>(t->stack[((index + 1) * 2) + 1]),
index);
@ -1740,7 +1742,7 @@ inline void
pokeLong(Thread* t, unsigned index, uint64_t value)
{
if (DebugStack) {
fprintf(stderr, "poke long " LLD " at %d\n", value, index);
fprintf(stderr, "poke long %"LLD" at %d\n", value, index);
}
pokeInt(t, index, value >> 32);
@ -1862,7 +1864,7 @@ objectExtended(Thread*, object o)
}
inline uintptr_t&
extendedWord(Thread* t, object o, unsigned baseSize)
extendedWord(Thread* t UNUSED, object o, unsigned baseSize)
{
assert(t, objectExtended(t, o));
return cast<uintptr_t>(o, baseSize * BytesPerWord);
@ -2107,7 +2109,7 @@ object
makeObjectArray(Thread* t, object elementClass, unsigned count, bool clear);
inline unsigned
objectArrayLength(Thread* t, object array)
objectArrayLength(Thread* t UNUSED, object array)
{
assert(t, classFixedSize(t, objectClass(t, array)) == BytesPerWord * 2);
assert(t, classArrayElementSize(t, objectClass(t, array)) == BytesPerWord);
@ -2115,7 +2117,7 @@ objectArrayLength(Thread* t, object array)
}
inline object&
objectArrayBody(Thread* t, object array, unsigned index)
objectArrayBody(Thread* t UNUSED, object array, unsigned index)
{
assert(t, classFixedSize(t, objectClass(t, array)) == BytesPerWord * 2);
assert(t, classArrayElementSize(t, objectClass(t, array)) == BytesPerWord);
@ -2186,7 +2188,7 @@ wait(Thread* t, object o, int64_t milliseconds)
System::Monitor* m = objectMonitor(t, o);
if (DebugMonitors) {
fprintf(stderr, "thread %p waits " LLD " millis on %p for %x\n",
fprintf(stderr, "thread %p waits %"LLD" millis on %p for %x\n",
t, milliseconds, m, objectHash(t, o));
}

View File

@ -130,17 +130,19 @@ find(Thread* t, object table, object reference,
object& (*name)(Thread*, object),
object& (*spec)(Thread*, object))
{
object n = referenceName(t, reference);
object s = referenceSpec(t, reference);
for (unsigned i = 0; i < arrayLength(t, table); ++i) {
object o = arrayBody(t, table, i);
if (table) {
object n = referenceName(t, reference);
object s = referenceSpec(t, reference);
for (unsigned i = 0; i < arrayLength(t, table); ++i) {
object o = arrayBody(t, table, i);
if (strcmp(&byteArrayBody(t, name(t, o), 0),
&byteArrayBody(t, n, 0)) == 0 and
strcmp(&byteArrayBody(t, spec(t, o), 0),
&byteArrayBody(t, s, 0)) == 0)
{
return o;
if (strcmp(&byteArrayBody(t, name(t, o), 0),
&byteArrayBody(t, n, 0)) == 0 and
strcmp(&byteArrayBody(t, spec(t, o), 0),
&byteArrayBody(t, s, 0)) == 0)
{
return o;
}
}
}
@ -478,7 +480,7 @@ invokeNative(Thread* t, object method)
case FloatField:
case IntField:
if (DebugRun) {
fprintf(stderr, "result: " LLD "\n", result);
fprintf(stderr, "result: %"LLD"\n", result);
}
pushInt(t, result);
break;
@ -486,7 +488,7 @@ invokeNative(Thread* t, object method)
case LongField:
case DoubleField:
if (DebugRun) {
fprintf(stderr, "result: " LLD "\n", result);
fprintf(stderr, "result: %"LLD"\n", result);
}
pushLong(t, result);
break;
@ -2470,7 +2472,7 @@ run(Thread* t, const char* className, int argc, const char** argv)
PROTECT(t, args);
for (int i = 0; i < argc; ++i) {
object arg = makeString(t, "%s", argv);
object arg = makeString(t, "%s", argv[i]);
set(t, objectArrayBody(t, args, i), arg);
}

View File

@ -149,7 +149,7 @@ class MySystem: public System {
}
virtual void join() {
int rv = pthread_join(thread, 0);
int rv UNUSED = pthread_join(thread, 0);
assert(s, rv == 0);
}
@ -262,11 +262,11 @@ class MySystem: public System {
if (time) {
int64_t then = s->now() + time;
timespec ts = { then / 1000, (then % 1000) * 1000 * 1000 };
int rv = pthread_cond_timedwait
int rv UNUSED = pthread_cond_timedwait
(&(t->condition), &(t->mutex), &ts);
assert(s, rv == 0 or rv == ETIMEDOUT or rv == EINTR);
} else {
int rv = pthread_cond_wait(&(t->condition), &(t->mutex));
int rv UNUSED = pthread_cond_wait(&(t->condition), &(t->mutex));
assert(s, rv == 0 or rv == EINTR);
}
@ -296,7 +296,7 @@ class MySystem: public System {
ACQUIRE(t->mutex);
t->flags |= Notified;
int rv = pthread_cond_signal(&(t->condition));
int rv UNUSED = pthread_cond_signal(&(t->condition));
assert(s, rv == 0);
}
@ -399,7 +399,7 @@ class MySystem: public System {
sigemptyset(&(sa.sa_mask));
sa.sa_handler = handleSignal;
int rv = sigaction(InterruptSignal, &sa, 0);
int rv UNUSED = sigaction(InterruptSignal, &sa, 0);
assert(this, rv == 0);
}
@ -445,7 +445,7 @@ class MySystem: public System {
count -= *up;
if (Verbose) {
fprintf(stderr, "free " LD "; count: %d; limit: %d\n",
fprintf(stderr, "free %"LD"; count: %d; limit: %d\n",
*up, count, limit);
}
@ -465,7 +465,7 @@ class MySystem: public System {
virtual Status start(Runnable* r) {
Thread* t = new (System::allocate(sizeof(Thread))) Thread(this, r);
r->attach(t);
int rv = pthread_create(&(t->thread), 0, run, r);
int rv UNUSED = pthread_create(&(t->thread), 0, run, r);
assert(this, rv == 0);
return 0;
}

View File

@ -101,9 +101,7 @@ expect(System* s, bool v)
#ifdef NDEBUG
inline void
assert(System*, bool)
{ }
# define assert(a, b)
#else // not NDEBUG

View File

@ -1023,7 +1023,7 @@ writeAccessor(Output* out, Object* member, Object* offset, bool unsafe = false)
out->write(capitalize(::typeName(memberOwner(member))));
out->write("*");
} else {
out->write("(Thread* t, object");
out->write("(Thread* t UNUSED, object");
}
out->write(" o");
if (member->type != Object::Scalar) {