From 8acb32e4cbb6b3b36b9b0d166399f60bd0cfbf04 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 2 Jul 2007 07:11:51 -0600 Subject: [PATCH] store frame locals on stack and avoid need to copy parameters --- src/types.def | 3 +-- src/vm.cpp | 29 ++++++++++++----------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/types.def b/src/types.def index e71d0115b3..1cde38c649 100644 --- a/src/types.def +++ b/src/types.def @@ -70,8 +70,7 @@ (object method) (object next) (uint32_t ip) - (uint32_t stackBase) - (array object locals)) + (uint32_t stackBase)) (type reference (object class) diff --git a/src/vm.cpp b/src/vm.cpp index 230c5a62ba..0663207a6f 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -2471,6 +2471,12 @@ invokeNative(Thread* t, object method) } } +object +frameLocals(Thread* t, object frame, unsigned index) +{ + return t->stack[frameStackBase(t, frame) + index]; +} + namespace builtin { void @@ -4086,7 +4092,7 @@ run(Thread* t) unsigned base = sp - parameterCount; if (methodFlags(t, code) & ACC_NATIVE) { - frame = makeFrame(t, code, frame, 0, base, 0, false); + frame = makeFrame(t, code, frame, 0, base); object r = invokeNative(t, code); @@ -4103,7 +4109,8 @@ run(Thread* t) code = methodCode(t, frameMethod(t, frame)); } else { - if (UNLIKELY(codeMaxStack(t, methodCode(t, code)) + base + if (UNLIKELY(codeMaxStack(t, methodCode(t, code)) + + codeMaxLocals(t, methodCode(t, code)) + base > Thread::StackSizeInWords)) { exception = makeStackOverflowError(t); @@ -4113,21 +4120,10 @@ run(Thread* t) frameIp(t, frame) = ip; ip = 0; - frame = makeFrame(t, code, frame, 0, base, - codeMaxLocals(t, methodCode(t, code)), false); + frame = makeFrame(t, code, frame, 0, base); code = methodCode(t, code); - if (parameterCount) { - memcpy(&frameLocals(t, frame, 0), stack + base, - parameterCount * BytesPerWord); - } - - if (frameLength(t, frame) - parameterCount) { - memset(&frameLocals(t, frame, 0) + parameterCount, 0, - (frameLength(t, frame) - parameterCount) * BytesPerWord); - } - - sp = base; + sp = base + codeMaxLocals(t, methodCode(t, code)); } } goto loop; @@ -4224,8 +4220,7 @@ run(Thread* t, const char* className, int argc, const char** argv) object method = findMethodInClass(t, class_, reference); if (LIKELY(t->exception == 0)) { t->code = methodCode(t, method); - t->frame = makeFrame - (t, method, 0, 0, 0, codeMaxLocals(t, t->code), true); + t->frame = makeFrame(t, method, 0, 0, 0); object args = makeObjectArray (t, arrayBody(t, t->vm->types, Machine::StringType), argc, true);