Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jruby/jruby
...
head fork: jruby/jruby
Checking mergeability… Don't worry, you can still create the pull request.
  • 12 commits
  • 43 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 03, 2012
@headius headius Remove unused/rarely used params to const lookup, use StaticScope.
In an effort to eliminate the deopt caused by const access from
Ruby code, I'm working toward making all constant access work
against StaticScope rather than against ThreadContext and the
current DynamicScope (which forces us to push dummy scopes where
we don't really need any). This commit starts pulling out calls to
ThreadContext.getConstant, which requires a DynamicScope to be
present, and also removes some unused or rarely-used arguments
from the const lookup call chain to simplify the transition.
d189840
@headius headius More decoupling of constant lookup from ThreadContext.
* setConstantInCurrent moved to StaticScope
* setConstantInModule moved to RuntimeHelpers
* setConstantInObject moved to RuntimeHelpers
* getConstantDefined moved to StaticScope#isConstantDefined
* A few more ThreadContext#getConstant calls eliminated
efd8a3d
@headius headius Modify compiler to use non-deprecated const lookup methods.
* Const lookup and defined pass in StaticScope
* AbstractScript/RuntimeCache receive StaticScope
* Compiled code uses context.getCurrentStaticScope for now
ad53c99
@headius headius Decouple compiler and class/module const assignment from TC.
* Compiled setConstant calls work against StaticScope
* Getting the namespace in which to define class/module uses StaticScope
4cf08e3
@headius headius Constant lookup/caching decoupling from ThreadContext for InDy. 27b60a2
@headius headius Modify scope and block creation to decouple them.
* Single method decodeScope for decoding all types of scopes
* New StaticScope::Type enum to indicate type of scope
* Closure creation receives StaticScope rather than instantiating
55c3b8f
@headius headius Pass parent StaticScope into creation.
This allows us to provide the parent scope without having it
pushed on ThreadContext.
12302a4
@headius headius Cache StaticScope for class bodies outside the body execution.
This helps decouple class/module creation from StaticScope init,
allowing us to move closer to getting the current scope from cache
in all cases.
f53f046
@headius headius Final modifications to get scopes loading from cache.
* For initial Script execution via __file__, must setRootScope
* Script.load impl will setRootScope
* All other method forms will receive scope index from parent compiler
3d12d1c
@headius headius Tweak cvar logic in compiler to use cached scope. d7ed0f8
@headius headius Fix defined?(@@cvar) to use cached scope and disably dummy scope.
With this commit, scopes that have classes, methods, constants,
and cvars no longer have a requirement that a dummy scope be
pushed. The scope is loaded from the same cache as other values,
and as a result those methods have no implicit cost over the same
code with no scope access.
1bfa8ef
@headius headius Indy optimization for constant lookup with cached scopes. ad5d072
Showing with 636 additions and 504 deletions.
  1. +2 −2 src/org/jruby/IncludedModuleWrapper.java
  2. +4 −1 src/org/jruby/Ruby.java
  3. +10 −10 src/org/jruby/RubyModule.java
  4. +1 −1  src/org/jruby/ast/Colon2Node.java
  5. +6 −5 src/org/jruby/ast/ConstDeclNode.java
  6. +2 −2 src/org/jruby/ast/ConstNode.java
  7. +61 −57 src/org/jruby/ast/executable/AbstractScript.java
  8. +19 −19 src/org/jruby/ast/executable/RuntimeCache.java
  9. +2 −0  src/org/jruby/ast/executable/Script.java
  10. +21 −15 src/org/jruby/compiler/ASTCompiler.java
  11. +3 −12 src/org/jruby/compiler/ASTInspector.java
  12. +48 −6 src/org/jruby/compiler/BodyCompiler.java
  13. +4 −2 src/org/jruby/compiler/CacheCompiler.java
  14. +3 −0  src/org/jruby/compiler/JITCompiler.java
  15. +7 −18 src/org/jruby/compiler/ScriptCompiler.java
  16. +1 −1  src/org/jruby/compiler/VariableCompiler.java
  17. +180 −142 src/org/jruby/compiler/impl/BaseBodyCompiler.java
  18. +1 −1  src/org/jruby/compiler/impl/ChainedChildBodyCompiler.java
  19. +1 −1  src/org/jruby/compiler/impl/ChainedRootBodyCompiler.java
  20. +2 −2 src/org/jruby/compiler/impl/ChildScopedBodyCompiler.java
  21. +2 −2 src/org/jruby/compiler/impl/ChildScopedBodyCompiler19.java
  22. +3 −3 src/org/jruby/compiler/impl/ClassBodyCompiler.java
  23. +1 −4 src/org/jruby/compiler/impl/HeapBasedVariableCompiler.java
  24. +32 −16 src/org/jruby/compiler/impl/InheritedCacheCompiler.java
  25. +17 −10 src/org/jruby/compiler/impl/InvokeDynamicCacheCompiler.java
  26. +2 −2 src/org/jruby/compiler/impl/MethodBodyCompiler.java
  27. +2 −2 src/org/jruby/compiler/impl/RootScopedBodyCompiler.java
  28. +1 −4 src/org/jruby/compiler/impl/StackBasedVariableCompiler.java
  29. +13 −12 src/org/jruby/compiler/impl/StandardASMCompiler.java
  30. +6 −1 src/org/jruby/evaluator/ASTInterpreter.java
  31. +4 −0 src/org/jruby/internal/runtime/methods/AliasMethod.java
  32. +1 −1  src/org/jruby/ir/instructions/LexicalSearchConstInstr.java
  33. +1 −1  src/org/jruby/ir/instructions/SearchConstInstr.java
  34. +1 −1  src/org/jruby/ir/targets/Bootstrap.java
  35. +4 −4 src/org/jruby/ir/targets/JVMVisitor.java
  36. +71 −96 src/org/jruby/javasupport/util/RuntimeHelpers.java
  37. +5 −0 src/org/jruby/parser/BlockStaticScope.java
  38. +5 −0 src/org/jruby/parser/EvalStaticScope.java
  39. +7 −0 src/org/jruby/parser/IRStaticScope.java
  40. +5 −0 src/org/jruby/parser/LocalStaticScope.java
  41. +33 −9 src/org/jruby/parser/StaticScope.java
  42. +14 −15 src/org/jruby/runtime/ThreadContext.java
  43. +28 −24 src/org/jruby/runtime/invokedynamic/InvokeDynamicSupport.java
View
4 src/org/jruby/IncludedModuleWrapper.java
@@ -230,8 +230,8 @@ protected IRubyObject constantTableRemove(String name) {
}
@Override
- public IRubyObject getAutoloadConstant(Ruby runtime, String name) {
- return delegate.getAutoloadConstant(runtime, name);
+ public IRubyObject getAutoloadConstant(String name) {
+ return delegate.getAutoloadConstant(name);
}
/** The module to which this include delegates. */
View
5 src/org/jruby/Ruby.java
@@ -571,7 +571,7 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
getGlobalVariables().set("$\\", getGlobalVariables().get("$/"));
}
- // we do preand post load outside the "body" versions to pre-prepare
+ // we do pre and post load outside the "body" versions to pre-prepare
// and pre-push the dynamic scope we need for lastline
RuntimeHelpers.preLoad(context, ((RootNode)scriptNode).getStaticScope().getVariables());
@@ -758,6 +758,9 @@ private Script tryCompile(Node node, String cachedClassName, JRubyClassLoader cl
}
script = (Script)asmCompiler.loadClass(classLoader).newInstance();
+ // __file__ method expects its scope at 0, so prepare that here
+ script.setRootScope(getCurrentContext().getCurrentStaticScope());
+
if (config.isJitLogging()) {
LOG.info("compiled: " + node.getPosition().getFile());
}
View
20 src/org/jruby/RubyModule.java
@@ -2903,7 +2903,7 @@ public IRubyObject getConstantAtSpecial(String name) {
value = fetchConstant(name);
}
- return value == UNDEF ? resolveUndefConstant(getRuntime(), name) : value;
+ return value == UNDEF ? resolveUndefConstant(name) : value;
}
public IRubyObject getConstantAt(String name) {
@@ -2913,7 +2913,7 @@ public IRubyObject getConstantAt(String name) {
public IRubyObject getConstantAt(String name, boolean includePrivate) {
IRubyObject value = fetchConstant(name, includePrivate);
- return value == UNDEF ? resolveUndefConstant(getRuntime(), name) : value;
+ return value == UNDEF ? resolveUndefConstant(name) : value;
}
@Deprecated
@@ -3011,7 +3011,7 @@ public IRubyObject getConstantFromNoConstMissing(String name, boolean includePri
while (p != null) {
if ((value = p.fetchConstant(name, false)) != null) {
if (value == UNDEF) {
- return p.resolveUndefConstant(runtime, name);
+ return p.resolveUndefConstant(name);
}
if (p == objectClass && this != objectClass) {
@@ -3036,14 +3036,14 @@ public IRubyObject getConstantFromConstMissing(String name) {
return callMethod(getRuntime().getCurrentContext(),
"const_missing", getRuntime().fastNewSymbol(name));
}
-
+
@Deprecated
public IRubyObject fastGetConstantFromConstMissing(String internedName) {
return getConstantFromConstMissing(internedName);
}
-
- public IRubyObject resolveUndefConstant(Ruby runtime, String name) {
- return getAutoloadConstant(runtime, name);
+
+ public IRubyObject resolveUndefConstant(String name) {
+ return getAutoloadConstant(name);
}
/**
@@ -3547,18 +3547,18 @@ protected IRubyObject finishAutoload(String name) {
}
return null;
}
-
+
/**
* Get autoload constant.
* If it's first resolution for the constant, it tries to require the defined feature and returns the defined value.
* Multi-threaded accesses are blocked and processed sequentially except if the caller is the autoloading thread.
*/
- public IRubyObject getAutoloadConstant(Ruby runtime, String name) {
+ public IRubyObject getAutoloadConstant(String name) {
Autoload autoload = getAutoloadMap().get(name);
if (autoload == null) {
return null;
}
- return autoload.getConstant(runtime.getCurrentContext());
+ return autoload.getConstant(getRuntime().getCurrentContext());
}
/**
View
2  src/org/jruby/ast/Colon2Node.java
@@ -86,6 +86,6 @@ public RubyModule getEnclosingModule(Ruby runtime, ThreadContext context, IRubyO
if (leftNode != null && leftNode instanceof NilNode) {
throw context.runtime.newTypeError("no outer class/module");
}
- return RuntimeHelpers.prepareClassNamespace(context, leftNode.interpret(runtime, context, self, aBlock));
+ return RuntimeHelpers.prepareClassNamespace(context, context.getCurrentStaticScope(), leftNode.interpret(runtime, context, self, aBlock));
}
}
View
11 src/org/jruby/ast/ConstDeclNode.java
@@ -37,6 +37,7 @@
import org.jruby.RubyModule;
import org.jruby.ast.types.INameNode;
import org.jruby.ast.visitor.NodeVisitor;
+import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
@@ -97,17 +98,17 @@ public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject se
IRubyObject result = getValueNode().interpret(runtime, context, self, aBlock);
if (constNode == null) {
- return context.setConstantInCurrent(name, result);
+ return context.getCurrentStaticScope().setConstant(name, result);
} else if (((Node)constNode).getNodeType() == NodeType.COLON2NODE) {
Node leftNode = ((Colon2Node) constNode).getLeftNode();
assert leftNode != null : "leftNode is not null";
IRubyObject obj = leftNode.interpret(runtime, context, self, aBlock);
-
- return context.setConstantInModule(constNode.getName(), obj, result);
+
+ return RuntimeHelpers.setConstantInModule(context, constNode.getName(), result, obj);
} else { // colon3
- return context.setConstantInObject(constNode.getName(), result);
+ return RuntimeHelpers.setConstantInModule(context, constNode.getName(), result, runtime.getObject());
}
}
@@ -116,7 +117,7 @@ public IRubyObject assign(Ruby runtime, ThreadContext context, IRubyObject self,
IRubyObject module;
if (constNode == null) {
- module = context.getCurrentScope().getStaticScope().getModule();
+ module = context.getCurrentStaticScope().getModule();
if (module == null) {
// TODO: wire into new exception handling mechanism
View
4 src/org/jruby/ast/ConstNode.java
@@ -96,7 +96,7 @@ public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject se
@Override
public RubyString definition(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
- return context.getConstantDefined(name) ? runtime.getDefinedMessage(DefinedMessage.CONSTANT) : null;
+ return context.getCurrentStaticScope().isConstantDefined(name) ? runtime.getDefinedMessage(DefinedMessage.CONSTANT) : null;
}
public IRubyObject getValue(ThreadContext context) {
@@ -111,7 +111,7 @@ private boolean isCached(ThreadContext context, IRubyObject value) {
public IRubyObject reCache(ThreadContext context, String name) {
Object newGeneration = context.runtime.getConstantInvalidator().getData();
- IRubyObject value = context.getConstant(name);
+ IRubyObject value = context.getCurrentStaticScope().getConstant(name);
cachedValue = value;
View
118 src/org/jruby/ast/executable/AbstractScript.java
@@ -67,17 +67,17 @@ public IRubyObject run(ThreadContext context, IRubyObject self, IRubyObject[] ar
public static final int NUMBERED_SCOPE_COUNT = 10;
- public final StaticScope getScope(ThreadContext context, String varNamesDescriptor, int i) {return runtimeCache.getScope(context, varNamesDescriptor, i);}
- public final StaticScope getScope0(ThreadContext context, String varNamesDescriptor) {return runtimeCache.getScope(context, varNamesDescriptor, 0);}
- public final StaticScope getScope1(ThreadContext context, String varNamesDescriptor) {return runtimeCache.getScope(context, varNamesDescriptor, 1);}
- public final StaticScope getScope2(ThreadContext context, String varNamesDescriptor) {return runtimeCache.getScope(context, varNamesDescriptor, 2);}
- public final StaticScope getScope3(ThreadContext context, String varNamesDescriptor) {return runtimeCache.getScope(context, varNamesDescriptor, 3);}
- public final StaticScope getScope4(ThreadContext context, String varNamesDescriptor) {return runtimeCache.getScope(context, varNamesDescriptor, 4);}
- public final StaticScope getScope5(ThreadContext context, String varNamesDescriptor) {return runtimeCache.getScope(context, varNamesDescriptor, 5);}
- public final StaticScope getScope6(ThreadContext context, String varNamesDescriptor) {return runtimeCache.getScope(context, varNamesDescriptor, 6);}
- public final StaticScope getScope7(ThreadContext context, String varNamesDescriptor) {return runtimeCache.getScope(context, varNamesDescriptor, 7);}
- public final StaticScope getScope8(ThreadContext context, String varNamesDescriptor) {return runtimeCache.getScope(context, varNamesDescriptor, 8);}
- public final StaticScope getScope9(ThreadContext context, String varNamesDescriptor) {return runtimeCache.getScope(context, varNamesDescriptor, 9);}
+ public final StaticScope getScope(ThreadContext context, StaticScope parent, String varNamesDescriptor, int i) {return runtimeCache.getScope(context, parent, varNamesDescriptor, i);}
+ public final StaticScope getScope0(ThreadContext context, StaticScope parent, String varNamesDescriptor) {return runtimeCache.getScope(context, parent, varNamesDescriptor, 0);}
+ public final StaticScope getScope1(ThreadContext context, StaticScope parent, String varNamesDescriptor) {return runtimeCache.getScope(context, parent, varNamesDescriptor, 1);}
+ public final StaticScope getScope2(ThreadContext context, StaticScope parent, String varNamesDescriptor) {return runtimeCache.getScope(context, parent, varNamesDescriptor, 2);}
+ public final StaticScope getScope3(ThreadContext context, StaticScope parent, String varNamesDescriptor) {return runtimeCache.getScope(context, parent, varNamesDescriptor, 3);}
+ public final StaticScope getScope4(ThreadContext context, StaticScope parent, String varNamesDescriptor) {return runtimeCache.getScope(context, parent, varNamesDescriptor, 4);}
+ public final StaticScope getScope5(ThreadContext context, StaticScope parent, String varNamesDescriptor) {return runtimeCache.getScope(context, parent, varNamesDescriptor, 5);}
+ public final StaticScope getScope6(ThreadContext context, StaticScope parent, String varNamesDescriptor) {return runtimeCache.getScope(context, parent, varNamesDescriptor, 6);}
+ public final StaticScope getScope7(ThreadContext context, StaticScope parent, String varNamesDescriptor) {return runtimeCache.getScope(context, parent, varNamesDescriptor, 7);}
+ public final StaticScope getScope8(ThreadContext context, StaticScope parent, String varNamesDescriptor) {return runtimeCache.getScope(context, parent, varNamesDescriptor, 8);}
+ public final StaticScope getScope9(ThreadContext context, StaticScope parent, String varNamesDescriptor) {return runtimeCache.getScope(context, parent, varNamesDescriptor, 9);}
public final StaticScope getScope(int i) {return runtimeCache.getScope(i);}
public final StaticScope getScope0() {return runtimeCache.getScope(0);}
@@ -107,29 +107,29 @@ public IRubyObject run(ThreadContext context, IRubyObject self, IRubyObject[] ar
public static final int NUMBERED_BLOCKBODY_COUNT = 10;
- public final BlockBody getBlockBody(ThreadContext context, int i, String descriptor) {return runtimeCache.getBlockBody(this, context, i, descriptor);}
- public final BlockBody getBlockBody0(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody(this, context, 0, descriptor);}
- public final BlockBody getBlockBody1(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody(this, context, 1, descriptor);}
- public final BlockBody getBlockBody2(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody(this, context, 2, descriptor);}
- public final BlockBody getBlockBody3(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody(this, context, 3, descriptor);}
- public final BlockBody getBlockBody4(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody(this, context, 4, descriptor);}
- public final BlockBody getBlockBody5(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody(this, context, 5, descriptor);}
- public final BlockBody getBlockBody6(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody(this, context, 6, descriptor);}
- public final BlockBody getBlockBody7(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody(this, context, 7, descriptor);}
- public final BlockBody getBlockBody8(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody(this, context, 8, descriptor);}
- public final BlockBody getBlockBody9(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody(this, context, 9, descriptor);}
-
- public final BlockBody getBlockBody19(ThreadContext context, int i, String descriptor) {return runtimeCache.getBlockBody19(this, context, i, descriptor);}
- public final BlockBody getBlockBody190(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody19(this, context, 0, descriptor);}
- public final BlockBody getBlockBody191(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody19(this, context, 1, descriptor);}
- public final BlockBody getBlockBody192(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody19(this, context, 2, descriptor);}
- public final BlockBody getBlockBody193(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody19(this, context, 3, descriptor);}
- public final BlockBody getBlockBody194(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody19(this, context, 4, descriptor);}
- public final BlockBody getBlockBody195(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody19(this, context, 5, descriptor);}
- public final BlockBody getBlockBody196(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody19(this, context, 6, descriptor);}
- public final BlockBody getBlockBody197(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody19(this, context, 7, descriptor);}
- public final BlockBody getBlockBody198(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody19(this, context, 8, descriptor);}
- public final BlockBody getBlockBody199(ThreadContext context, String descriptor) {return runtimeCache.getBlockBody19(this, context, 9, descriptor);}
+ public final BlockBody getBlockBody(ThreadContext context, StaticScope scope, int i, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, i, descriptor);}
+ public final BlockBody getBlockBody0(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 0, descriptor);}
+ public final BlockBody getBlockBody1(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 1, descriptor);}
+ public final BlockBody getBlockBody2(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 2, descriptor);}
+ public final BlockBody getBlockBody3(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 3, descriptor);}
+ public final BlockBody getBlockBody4(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 4, descriptor);}
+ public final BlockBody getBlockBody5(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 5, descriptor);}
+ public final BlockBody getBlockBody6(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 6, descriptor);}
+ public final BlockBody getBlockBody7(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 7, descriptor);}
+ public final BlockBody getBlockBody8(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 8, descriptor);}
+ public final BlockBody getBlockBody9(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody(this, context, scope, 9, descriptor);}
+
+ public final BlockBody getBlockBody19(ThreadContext context, StaticScope scope, int i, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, i, descriptor);}
+ public final BlockBody getBlockBody190(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 0, descriptor);}
+ public final BlockBody getBlockBody191(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 1, descriptor);}
+ public final BlockBody getBlockBody192(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 2, descriptor);}
+ public final BlockBody getBlockBody193(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 3, descriptor);}
+ public final BlockBody getBlockBody194(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 4, descriptor);}
+ public final BlockBody getBlockBody195(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 5, descriptor);}
+ public final BlockBody getBlockBody196(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 6, descriptor);}
+ public final BlockBody getBlockBody197(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 7, descriptor);}
+ public final BlockBody getBlockBody198(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 8, descriptor);}
+ public final BlockBody getBlockBody199(ThreadContext context, StaticScope scope, String descriptor) {return runtimeCache.getBlockBody19(this, context, scope, 9, descriptor);}
public static final int NUMBERED_BLOCKCALLBACK_COUNT = 10;
@@ -298,29 +298,29 @@ public IRubyObject run(ThreadContext context, IRubyObject self, IRubyObject[] ar
public static final int NUMBERED_CONSTANT_COUNT = 10;
- public final IRubyObject getConstant(ThreadContext context, String name, int i) {return runtimeCache.getConstant(context, name, i);}
- public final IRubyObject getConstant0(ThreadContext context, String name) {return runtimeCache.getConstant(context, name, 0);}
- public final IRubyObject getConstant1(ThreadContext context, String name) {return runtimeCache.getConstant(context, name, 1);}
- public final IRubyObject getConstant2(ThreadContext context, String name) {return runtimeCache.getConstant(context, name, 2);}
- public final IRubyObject getConstant3(ThreadContext context, String name) {return runtimeCache.getConstant(context, name, 3);}
- public final IRubyObject getConstant4(ThreadContext context, String name) {return runtimeCache.getConstant(context, name, 4);}
- public final IRubyObject getConstant5(ThreadContext context, String name) {return runtimeCache.getConstant(context, name, 5);}
- public final IRubyObject getConstant6(ThreadContext context, String name) {return runtimeCache.getConstant(context, name, 6);}
- public final IRubyObject getConstant7(ThreadContext context, String name) {return runtimeCache.getConstant(context, name, 7);}
- public final IRubyObject getConstant8(ThreadContext context, String name) {return runtimeCache.getConstant(context, name, 8);}
- public final IRubyObject getConstant9(ThreadContext context, String name) {return runtimeCache.getConstant(context, name, 9);}
-
- public final IRubyObject getConstantDefined(ThreadContext context, String name, int i) {return runtimeCache.getConstantDefined(context, name, i);}
- public final IRubyObject getConstantDefined0(ThreadContext context, String name) {return runtimeCache.getConstantDefined(context, name, 0);}
- public final IRubyObject getConstantDefined1(ThreadContext context, String name) {return runtimeCache.getConstantDefined(context, name, 1);}
- public final IRubyObject getConstantDefined2(ThreadContext context, String name) {return runtimeCache.getConstantDefined(context, name, 2);}
- public final IRubyObject getConstantDefined3(ThreadContext context, String name) {return runtimeCache.getConstantDefined(context, name, 3);}
- public final IRubyObject getConstantDefined4(ThreadContext context, String name) {return runtimeCache.getConstantDefined(context, name, 4);}
- public final IRubyObject getConstantDefined5(ThreadContext context, String name) {return runtimeCache.getConstantDefined(context, name, 5);}
- public final IRubyObject getConstantDefined6(ThreadContext context, String name) {return runtimeCache.getConstantDefined(context, name, 6);}
- public final IRubyObject getConstantDefined7(ThreadContext context, String name) {return runtimeCache.getConstantDefined(context, name, 7);}
- public final IRubyObject getConstantDefined8(ThreadContext context, String name) {return runtimeCache.getConstantDefined(context, name, 8);}
- public final IRubyObject getConstantDefined9(ThreadContext context, String name) {return runtimeCache.getConstantDefined(context, name, 9);}
+ public final IRubyObject getConstant(ThreadContext context, StaticScope scope, String name, int i) {return runtimeCache.getConstant(context, scope, name, i);}
+ public final IRubyObject getConstant0(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstant(context, scope, name, 0);}
+ public final IRubyObject getConstant1(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstant(context, scope, name, 1);}
+ public final IRubyObject getConstant2(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstant(context, scope, name, 2);}
+ public final IRubyObject getConstant3(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstant(context, scope, name, 3);}
+ public final IRubyObject getConstant4(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstant(context, scope, name, 4);}
+ public final IRubyObject getConstant5(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstant(context, scope, name, 5);}
+ public final IRubyObject getConstant6(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstant(context, scope, name, 6);}
+ public final IRubyObject getConstant7(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstant(context, scope, name, 7);}
+ public final IRubyObject getConstant8(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstant(context, scope, name, 8);}
+ public final IRubyObject getConstant9(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstant(context, scope, name, 9);}
+
+ public final IRubyObject getConstantDefined(ThreadContext context, StaticScope scope, String name, int i) {return runtimeCache.getConstantDefined(context, scope, name, i);}
+ public final IRubyObject getConstantDefined0(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstantDefined(context, scope, name, 0);}
+ public final IRubyObject getConstantDefined1(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstantDefined(context, scope, name, 1);}
+ public final IRubyObject getConstantDefined2(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstantDefined(context, scope, name, 2);}
+ public final IRubyObject getConstantDefined3(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstantDefined(context, scope, name, 3);}
+ public final IRubyObject getConstantDefined4(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstantDefined(context, scope, name, 4);}
+ public final IRubyObject getConstantDefined5(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstantDefined(context, scope, name, 5);}
+ public final IRubyObject getConstantDefined6(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstantDefined(context, scope, name, 6);}
+ public final IRubyObject getConstantDefined7(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstantDefined(context, scope, name, 7);}
+ public final IRubyObject getConstantDefined8(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstantDefined(context, scope, name, 8);}
+ public final IRubyObject getConstantDefined9(ThreadContext context, StaticScope scope, String name) {return runtimeCache.getConstantDefined(context, scope, name, 9);}
public static final int NUMBERED_CONSTANTFROM_COUNT = 10;
@@ -415,5 +415,9 @@ public final void initFromDescriptor(String descriptor) {
runtimeCache.initFromDescriptor(descriptor);
}
+ public void setRootScope(StaticScope scope) {
+ runtimeCache.scopes[0] = scope;
+ }
+
protected String filename;
}
View
38 src/org/jruby/ast/executable/RuntimeCache.java
@@ -34,10 +34,10 @@
public RuntimeCache() {
}
- public final StaticScope getScope(ThreadContext context, String varNamesDescriptor, int index) {
+ public final StaticScope getScope(ThreadContext context, StaticScope parent, String varNamesDescriptor, int index) {
StaticScope scope = scopes[index];
if (scope == null) {
- scopes[index] = scope = RuntimeHelpers.createScopeForClass(context, varNamesDescriptor);
+ scopes[index] = scope = RuntimeHelpers.decodeScopeAndDetermineModule(context, parent, varNamesDescriptor);
}
return scope;
}
@@ -60,10 +60,10 @@ public final CallSite getCallSite(int index) {
* @param descriptor
* @return
*/
- public final BlockBody getBlockBody(Object scriptObject, ThreadContext context, int index, String descriptor) {
+ public final BlockBody getBlockBody(Object scriptObject, ThreadContext context, StaticScope scope, int index, String descriptor) {
BlockBody body = blockBodies[index];
if (body == null) {
- return createBlockBody(scriptObject, context, index, descriptor);
+ return createBlockBody(scriptObject, context, scope, index, descriptor);
}
return body;
}
@@ -78,10 +78,10 @@ public final BlockBody getBlockBody(Object scriptObject, ThreadContext context,
* @param descriptor
* @return
*/
- public final BlockBody getBlockBody19(Object scriptObject, ThreadContext context, int index, String descriptor) {
+ public final BlockBody getBlockBody19(Object scriptObject, ThreadContext context, StaticScope scope, int index, String descriptor) {
BlockBody body = blockBodies[index];
if (body == null) {
- return createBlockBody19(scriptObject, context, index, descriptor);
+ return createBlockBody19(scriptObject, context, scope, index, descriptor);
}
return body;
}
@@ -394,29 +394,29 @@ public final void initMethodCache(int size) {
Arrays.fill(methodCache, CacheEntry.NULL_CACHE);
}
- public final IRubyObject getConstant(ThreadContext context, String name, int index) {
- IRubyObject value = getValue(context, name, index);
+ public final IRubyObject getConstant(ThreadContext context, StaticScope scope, String name, int index) {
+ IRubyObject value = getValue(context, scope, name, index);
// We can callsite cache const_missing if we want
- return value != null ? value : context.getCurrentScope().getStaticScope().getModule().callMethod(context, "const_missing", context.runtime.fastNewSymbol(name));
+ return value != null ? value : scope.getModule().callMethod(context, "const_missing", context.runtime.fastNewSymbol(name));
}
- public final IRubyObject getConstantDefined(ThreadContext context, String name, int index) {
- IRubyObject value = getValue(context, name, index);
+ public final IRubyObject getConstantDefined(ThreadContext context, StaticScope scope, String name, int index) {
+ IRubyObject value = getValue(context, scope, name, index);
return value == null ? null : context.runtime.getDefinedMessage(DefinedMessage.CONSTANT);
}
- public IRubyObject getValue(ThreadContext context, String name, int index) {
+ public IRubyObject getValue(ThreadContext context, StaticScope scope, String name, int index) {
IRubyObject value = constants[index]; // Store to temp so it does null out on us mid-stream
- return isCached(context, value, index) ? value : reCache(context, name, index);
+ return isCached(context, value, index) ? value : reCache(context, scope, name, index);
}
private boolean isCached(ThreadContext context, IRubyObject value, int index) {
return value != null && constantGenerations[index] == context.runtime.getConstantInvalidator().getData();
}
- public IRubyObject reCache(ThreadContext context, String name, int index) {
+ public IRubyObject reCache(ThreadContext context, StaticScope scope, String name, int index) {
Object newGeneration = context.runtime.getConstantInvalidator().getData();
- IRubyObject value = context.getConstant(name);
+ IRubyObject value = scope.getConstant(name);
constants[index] = value;
if (value != null) {
constantGenerations[index] = newGeneration;
@@ -450,13 +450,13 @@ public IRubyObject reCacheFrom(RubyModule target, ThreadContext context, String
return value;
}
- private BlockBody createBlockBody(Object scriptObject, ThreadContext context, int index, String descriptor) throws NumberFormatException {
- BlockBody body = RuntimeHelpers.createCompiledBlockBody(context, scriptObject, descriptor);
+ private BlockBody createBlockBody(Object scriptObject, ThreadContext context, StaticScope scope, int index, String descriptor) throws NumberFormatException {
+ BlockBody body = RuntimeHelpers.createCompiledBlockBody(context, scriptObject, scope, descriptor);
return blockBodies[index] = body;
}
- private BlockBody createBlockBody19(Object scriptObject, ThreadContext context, int index, String descriptor) throws NumberFormatException {
- BlockBody body = RuntimeHelpers.createCompiledBlockBody19(context, scriptObject, descriptor);
+ private BlockBody createBlockBody19(Object scriptObject, ThreadContext context, StaticScope scope, int index, String descriptor) throws NumberFormatException {
+ BlockBody body = RuntimeHelpers.createCompiledBlockBody19(context, scriptObject, scope, descriptor);
return blockBodies[index] = body;
}
View
2  src/org/jruby/ast/executable/Script.java
@@ -1,5 +1,6 @@
package org.jruby.ast.executable;
+import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
@@ -16,4 +17,5 @@
public IRubyObject load(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block);
public IRubyObject load(ThreadContext context, IRubyObject self, boolean wrap);
public void setFilename(String filename);
+ public void setRootScope(StaticScope scope);
}
View
36 src/org/jruby/compiler/ASTCompiler.java
@@ -1136,22 +1136,28 @@ public void compileClassVarDeclAssignment(Node node, BodyCompiler context, boole
public void compileConstDecl(Node node, BodyCompiler context, boolean expr) {
// TODO: callback for value would be more efficient, but unlikely to be a big cost (constants are rarely assigned)
- ConstDeclNode constDeclNode = (ConstDeclNode) node;
- Node constNode = constDeclNode.getConstNode();
+ final ConstDeclNode constDeclNode = (ConstDeclNode) node;
+ final Node constNode = constDeclNode.getConstNode();
if (constNode == null) {
- compile(constDeclNode.getValueNode(), context,true);
-
- context.assignConstantInCurrent(constDeclNode.getName());
+ context.assignConstantInCurrent(constDeclNode.getName(), new CompilerCallback() {
+ public void call(BodyCompiler context) {
+ compile(constDeclNode.getValueNode(), context, true);
+ }
+ });
} else if (constNode.getNodeType() == NodeType.COLON2NODE) {
- compile(constDeclNode.getValueNode(), context,true);
- compile(((Colon2Node) constNode).getLeftNode(), context,true);
-
- context.assignConstantInModule(constDeclNode.getName());
+ context.assignConstantInModule(constDeclNode.getName(), new CompilerCallback() {
+ public void call(BodyCompiler context) {
+ compile(constDeclNode.getValueNode(), context, true);
+ compile(((Colon2Node) constNode).getLeftNode(), context, true);
+ }
+ });
} else {// colon3, assign in Object
- compile(constDeclNode.getValueNode(), context,true);
-
- context.assignConstantInObject(constDeclNode.getName());
+ context.assignConstantInObject(constDeclNode.getName(), new CompilerCallback() {
+ public void call(BodyCompiler context) {
+ compile(constDeclNode.getValueNode(), context, true);
+ }
+ });
}
// TODO: don't require pop
if (!expr) context.consumeCurrentValue();
@@ -1163,12 +1169,12 @@ public void compileConstDeclAssignment(Node node, BodyCompiler context, boolean
Node constNode = constDeclNode.getConstNode();
if (constNode == null) {
- context.assignConstantInCurrent(constDeclNode.getName());
+ context.mAssignConstantInCurrent(constDeclNode.getName());
} else if (constNode.getNodeType() == NodeType.COLON2NODE) {
compile(((Colon2Node) constNode).getLeftNode(), context,true);
- context.assignConstantInModule(constDeclNode.getName());
+ context.mAssignConstantInModule(constDeclNode.getName());
} else {// colon3, assign in Object
- context.assignConstantInObject(constDeclNode.getName());
+ context.mAssignConstantInObject(constDeclNode.getName());
}
// TODO: don't require pop
if (!expr) context.consumeCurrentValue();
View
15 src/org/jruby/compiler/ASTInspector.java
@@ -144,23 +144,14 @@ public CallConfiguration getCallConfig() {
// The method also needs a scope, do both
return CallConfiguration.FrameFullScopeFull;
} else {
- if (hasConstant() || hasMethod() || hasClass() || hasClassVar()) {
- // The method doesn't need a scope, but has static scope needs; use a dummy scope
- return CallConfiguration.FrameFullScopeDummy;
- } else {
- // The method doesn't need a scope or static scope; frame only
- return CallConfiguration.FrameFullScopeNone;
- }
+ // The method doesn't need a scope or static scope; frame only
+ return CallConfiguration.FrameFullScopeNone;
}
} else {
if (hasClosure() || hasScopeAwareMethods()) {
return CallConfiguration.FrameNoneScopeFull;
} else {
- if (hasConstant() || hasMethod() || hasClass() || hasClassVar()) {
- return CallConfiguration.FrameNoneScopeDummy;
- } else {
- return CallConfiguration.FrameNoneScopeNone;
- }
+ return CallConfiguration.FrameNoneScopeNone;
}
}
}
View
54 src/org/jruby/compiler/BodyCompiler.java
@@ -370,12 +370,54 @@ public void defineNewMethod(String name, int methodArity, StaticScope scope,
* Define an alias for a new name to an existing oldName'd method.
*/
public void defineAlias(CompilerCallback args);
-
- public void assignConstantInCurrent(String name);
-
- public void assignConstantInModule(String name);
-
- public void assignConstantInObject(String name);
+
+ /**
+ * Assign a constant on the class or module currently in scope.
+ *
+ * @param name name of the constant
+ * @param value callback to load the value
+ */
+ public void assignConstantInCurrent(String name, CompilerCallback value);
+
+ /**
+ * Assign a constant on a specific class or module.
+ *
+ * @param name name of the constant
+ * @param moduleAndValue callback to load the class/module and value
+ */
+ public void assignConstantInModule(String name, CompilerCallback moduleAndValue);
+
+ /**
+ * Assign a constant on the Object class.
+ *
+ * @param name name of the constant
+ * @param value callback to load the value
+ */
+ public void assignConstantInObject(String name, CompilerCallback value);
+
+ /**
+ * Assign a constant on the class or module currently in scope. The value
+ * is expected to be on the top of the stack.
+ *
+ * @param name name of the constant
+ */
+ public void mAssignConstantInCurrent(String name);
+
+ /**
+ * Assign a constant on a specific class or module. The class/module
+ * and value are expected to be on the top of the stack.
+ *
+ * @param name name of the constant
+ */
+ public void mAssignConstantInModule(String name);
+
+ /**
+ * Assign a constant on the Object class. The value
+ * is expected to be on the top of the stack.
+ *
+ * @param name name of the constant
+ */
+ public void mAssignConstantInObject(String name);
/**
* Retrieve the constant with the specified name available at the current point in the
View
6 src/org/jruby/compiler/CacheCompiler.java
@@ -48,9 +48,9 @@
public void cacheDRegexp19(BaseBodyCompiler method, ArrayCallback arrayCallback, Object[] sourceArray, int options);
- public void cacheClosure(BaseBodyCompiler method, String closureMethod, int arity, StaticScope scope, String file, int line, boolean hasMultipleArgsHead, NodeType argsNodeId, ASTInspector inspector);
+ public int cacheClosure(BaseBodyCompiler method, String closureMethod, int arity, StaticScope scope, String file, int line, boolean hasMultipleArgsHead, NodeType argsNodeId, ASTInspector inspector);
- public void cacheClosure19(BaseBodyCompiler method, String closureMethod, int arity, StaticScope scope, String file, int line, boolean hasMultipleArgsHead, NodeType argsNodeId, String parameterList, ASTInspector inspector);
+ public int cacheClosure19(BaseBodyCompiler method, String closureMethod, int arity, StaticScope scope, String file, int line, boolean hasMultipleArgsHead, NodeType argsNodeId, String parameterList, ASTInspector inspector);
public void cacheSpecialClosure(BaseBodyCompiler method, String closureMethod);
@@ -60,6 +60,8 @@
public void cacheConstantFrom(BaseBodyCompiler method, String constantName);
+ public int reserveStaticScope();
+
public int cacheStaticScope(BaseBodyCompiler method, StaticScope scope);
public void loadStaticScope(BaseBodyCompiler method, int index);
View
3  src/org/jruby/compiler/JITCompiler.java
@@ -178,6 +178,9 @@ public void run() {
// finally, grab the script
Script jitCompiledScript = sourceClass.newInstance();
+ // set root scope
+ jitCompiledScript.setRootScope(method.getStaticScope());
+
// add to the jitted methods set
Set<Script> jittedMethods = runtime.getJittedMethods();
jittedMethods.add(jitCompiledScript);
View
25 src/org/jruby/compiler/ScriptCompiler.java
@@ -56,26 +56,15 @@
/**
* Begin compilation for a method that has the specified number of local variables.
* The returned value is a token that can be used to end the method later.
- *
- * @param javaName The outward user-readable name of the method. A unique name will be generated based on this.
- * @param arity The arity of the method's argument list
- * @param localVarCount The number of local variables that will be used by the method.
- * @return An Object that represents the method within this compiler. Used in calls to
- * endMethod once compilation for this method is completed.
- */
- public BodyCompiler startMethod(String rubyName, String javaName, CompilerCallback argsHandler, StaticScope scope, ASTInspector inspector);
-
- /**
- * Begin compilation for a the root of a script. This differs from method compilation
- * in that it doesn't do specific-arity logic, nor does it require argument processing.
*
- * @param javaName The outward user-readable name of the method. A unique name will be generated based on this.
- * @param arity The arity of the method's argument list
- * @param localVarCount The number of local variables that will be used by the method.
- * @return An Object that represents the method within this compiler. Used in calls to
- * endMethod once compilation for this method is completed.
+ * @param rubyName
+ * @param javaName
+ * @param argsHandler
+ * @param scope
+ * @param inspector
+ * @return
*/
- public BodyCompiler startRoot(String rubyName, String javaName, StaticScope scope, ASTInspector inspector);
+ public BodyCompiler startMethod(String rubyName, String javaName, CompilerCallback argsHandler, StaticScope scope, ASTInspector inspector, int scopeIndex);
/**
* Begin compilation for the root of a script named __file__.
View
2  src/org/jruby/compiler/VariableCompiler.java
@@ -41,7 +41,7 @@
public SkinnyMethodAdapter getMethodAdapter();
public void setMethodAdapter(SkinnyMethodAdapter sma);
public void beginMethod(CompilerCallback argsCallback, StaticScope scope);
- public void beginClass(CompilerCallback bodyPrep, StaticScope scope);
+ public void beginClass(StaticScope scope);
public void beginClosure(CompilerCallback argsCallback, StaticScope scope);
public void beginFlatClosure(CompilerCallback argsCallback, StaticScope scope);
public void assignLocalVariable(int index, boolean expr);
View
322 src/org/jruby/compiler/impl/BaseBodyCompiler.java
@@ -94,8 +94,9 @@
protected String methodName;
protected String rubyName;
protected StandardASMCompiler script;
+ protected int scopeIndex;
- public BaseBodyCompiler(StandardASMCompiler scriptCompiler, String methodName, String rubyName, ASTInspector inspector, StaticScope scope) {
+ public BaseBodyCompiler(StandardASMCompiler scriptCompiler, String methodName, String rubyName, ASTInspector inspector, StaticScope scope, int scopeIndex) {
this.script = scriptCompiler;
this.scope = scope;
this.inspector = inspector;
@@ -107,6 +108,8 @@ public BaseBodyCompiler(StandardASMCompiler scriptCompiler, String methodName, S
createVariableCompiler();
invocationCompiler = OptoFactory.newInvocationCompiler(this, method);
+
+ this.scopeIndex = scopeIndex;
}
public String getNativeMethodName() {
@@ -218,6 +221,10 @@ protected int getExceptionIndex() {
return StandardASMCompiler.ARGS_INDEX + argParamCount + StandardASMCompiler.EXCEPTION_OFFSET;
}
+ protected void loadStaticScope() {
+ script.getCacheCompiler().loadStaticScope(this, scopeIndex);
+ }
+
public void loadThis() {
method.aload(StandardASMCompiler.THIS);
}
@@ -334,23 +341,55 @@ public InvocationCompiler getInvocationCompiler() {
return invocationCompiler;
}
- public void assignConstantInCurrent(String name) {
+ public void assignConstantInCurrent(String name, CompilerCallback value) {
+ loadStaticScope();
+ method.ldc(name);
+ value.call(this);
+ method.invokevirtual(p(StaticScope.class), "setConstant", sig(IRubyObject.class, params(String.class, IRubyObject.class)));
+ }
+
+ public void assignConstantInModule(String name, CompilerCallback valueAndModule) {
loadThreadContext();
method.ldc(name);
- invokeUtilityMethod("setConstantInCurrent", sig(IRubyObject.class, params(IRubyObject.class, ThreadContext.class, String.class)));
+ valueAndModule.call(this);
+ invokeUtilityMethod("setConstantInModule", sig(IRubyObject.class, ThreadContext.class, String.class, IRubyObject.class, IRubyObject.class));
+ }
+
+ public void assignConstantInObject(String name, final CompilerCallback value) {
+ assignConstantInModule(name, new CompilerCallback() {
+ public void call(BodyCompiler context) {
+ value.call(context);
+ loadObject();
+ }
+ });
}
- public void assignConstantInModule(String name) {
+ // TODO: Inefficient, but rarely used (constants in masgn are not common)
+ public void mAssignConstantInCurrent(String name) {
+ loadStaticScope();
method.ldc(name);
+ method.dup2_x1();
+ method.pop2();
+ method.invokevirtual(p(StaticScope.class), "setConstant", sig(IRubyObject.class, params(String.class, IRubyObject.class)));
+ }
+
+ // TODO: Inefficient, but rarely used (constants in masgn are not common)
+ public void mAssignConstantInModule(String name) {
loadThreadContext();
- invokeUtilityMethod("setConstantInModule", sig(IRubyObject.class, IRubyObject.class, IRubyObject.class, String.class, ThreadContext.class));
+ method.ldc(name);
+ method.dup2_x2();
+ method.pop2();
+ invokeUtilityMethod("setConstantInModule", sig(IRubyObject.class, ThreadContext.class, String.class, IRubyObject.class, IRubyObject.class));
}
- public void assignConstantInObject(String name) {
- // load Object under value
+ // TODO: Inefficient, but rarely used (constants in masgn are not common)
+ public void mAssignConstantInObject(String name) {
loadObject();
-
- assignConstantInModule(name);
+ loadThreadContext();
+ method.ldc(name);
+ method.dup2_x2();
+ method.pop2();
+ invokeUtilityMethod("setConstantInModule", sig(IRubyObject.class, ThreadContext.class, String.class, IRubyObject.class, IRubyObject.class));
}
public void retrieveConstant(String name) {
@@ -368,58 +407,59 @@ public void retrieveConstantFromObject(String name) {
}
public void retrieveClassVariable(String name) {
- loadThreadContext();
loadRuntime();
+ loadStaticScope();
loadSelf();
method.ldc(name);
- invokeUtilityMethod("fastFetchClassVariable", sig(IRubyObject.class, params(ThreadContext.class, Ruby.class, IRubyObject.class, String.class)));
+ invokeUtilityMethod("fetchClassVariable", sig(IRubyObject.class, params(Ruby.class, StaticScope.class, IRubyObject.class, String.class)));
}
public void assignClassVariable(String name) {
- loadThreadContext();
- method.swap();
loadRuntime();
method.swap();
+ loadStaticScope();
+ method.swap();
loadSelf();
method.swap();
method.ldc(name);
method.swap();
- invokeUtilityMethod("fastSetClassVariable", sig(IRubyObject.class, params(ThreadContext.class, Ruby.class, IRubyObject.class, String.class, IRubyObject.class)));
+ invokeUtilityMethod("setClassVariable", sig(IRubyObject.class, params(Ruby.class, StaticScope.class, IRubyObject.class, String.class, IRubyObject.class)));
}
public void assignClassVariable(String name, CompilerCallback value) {
- loadThreadContext();
loadRuntime();
+ loadStaticScope();
loadSelf();
method.ldc(name);
value.call(this);
- invokeUtilityMethod("fastSetClassVariable", sig(IRubyObject.class, params(ThreadContext.class, Ruby.class, IRubyObject.class, String.class, IRubyObject.class)));
+ invokeUtilityMethod("setClassVariable", sig(IRubyObject.class, params(Ruby.class, StaticScope.class, IRubyObject.class, String.class, IRubyObject.class)));
}
+ // inefficient, but uncommon to see class vars in masgn
public void declareClassVariable(String name) {
- loadThreadContext();
- method.swap();
loadRuntime();
method.swap();
+ loadStaticScope();
+ method.swap();
loadSelf();
method.swap();
method.ldc(name);
method.swap();
- invokeUtilityMethod("fastDeclareClassVariable", sig(IRubyObject.class, params(ThreadContext.class, Ruby.class, IRubyObject.class, String.class, IRubyObject.class)));
+ invokeUtilityMethod("declareClassVariable", sig(IRubyObject.class, params(Ruby.class, StaticScope.class, IRubyObject.class, String.class, IRubyObject.class)));
}
public void declareClassVariable(String name, CompilerCallback value) {
- loadThreadContext();
loadRuntime();
+ loadStaticScope();
loadSelf();
method.ldc(name);
value.call(this);
- invokeUtilityMethod("fastDeclareClassVariable", sig(IRubyObject.class, params(ThreadContext.class, Ruby.class, IRubyObject.class, String.class, IRubyObject.class)));
+ invokeUtilityMethod("declareClassVariable", sig(IRubyObject.class, params(Ruby.class, StaticScope.class, IRubyObject.class, String.class, IRubyObject.class)));
}
public void createNewFloat(double value) {
@@ -1044,24 +1084,26 @@ public void createNewClosure(
}
String closureMethodName = "block_" + script.getAndIncrementInnerIndex() + "$RUBY$" + blockInMethod;
- ChildScopedBodyCompiler closureCompiler = new ChildScopedBodyCompiler(script, closureMethodName, rubyName, inspector, scope);
-
- closureCompiler.beginMethod(args, scope);
-
- body.call(closureCompiler);
-
- closureCompiler.endBody();
-
// Done with closure compilation
loadThreadContext();
loadSelf();
- script.getCacheCompiler().cacheClosure(this, closureMethodName, arity, scope, file, line, hasMultipleArgsHead, argsNodeId, inspector);
+ int scopeIndex = script.getCacheCompiler().cacheClosure(this, closureMethodName, arity, scope, file, line, hasMultipleArgsHead, argsNodeId, inspector);
script.addBlockCallbackDescriptor(closureMethodName, file, line);
invokeUtilityMethod("createBlock", sig(Block.class,
params(ThreadContext.class, IRubyObject.class, BlockBody.class)));
+
+ // emit closure body
+
+ ChildScopedBodyCompiler closureCompiler = new ChildScopedBodyCompiler(script, closureMethodName, rubyName, inspector, scope, scopeIndex);
+
+ closureCompiler.beginMethod(args, scope);
+
+ body.call(closureCompiler);
+
+ closureCompiler.endBody();
}
public void createNewClosure19(
@@ -1081,30 +1123,32 @@ public void createNewClosure19(
}
String closureMethodName = "block_" + script.getAndIncrementInnerIndex() + "$RUBY$" + blockInMethod;
- ChildScopedBodyCompiler19 closureCompiler = new ChildScopedBodyCompiler19(script, closureMethodName, rubyName, inspector, scope);
-
- closureCompiler.beginMethod(args, scope);
-
- body.call(closureCompiler);
-
- closureCompiler.endBody();
-
// Done with closure compilation
loadThreadContext();
loadSelf();
- script.getCacheCompiler().cacheClosure19(this, closureMethodName, arity, scope, file, line, hasMultipleArgsHead, argsNodeId, parameterList, inspector);
+ int scopeIndex = script.getCacheCompiler().cacheClosure19(this, closureMethodName, arity, scope, file, line, hasMultipleArgsHead, argsNodeId, parameterList, inspector);
script.addBlockCallback19Descriptor(closureMethodName, file, line);
invokeUtilityMethod("createBlock19", sig(Block.class,
params(ThreadContext.class, IRubyObject.class, BlockBody.class)));
+
+ // emit closure body
+
+ ChildScopedBodyCompiler19 closureCompiler = new ChildScopedBodyCompiler19(script, closureMethodName, rubyName, inspector, scope, scopeIndex);
+
+ closureCompiler.beginMethod(args, scope);
+
+ body.call(closureCompiler);
+
+ closureCompiler.endBody();
}
public void runBeginBlock(StaticScope scope, CompilerCallback body) {
String closureMethodName = "block_" + script.getAndIncrementInnerIndex() + "$RUBY$__begin__";
- ChildScopedBodyCompiler closureCompiler = new ChildScopedBodyCompiler(script, closureMethodName, rubyName, null, scope);
+ ChildScopedBodyCompiler closureCompiler = new ChildScopedBodyCompiler(script, closureMethodName, rubyName, null, scope, scopeIndex);
closureCompiler.beginMethod(null, scope);
@@ -1128,7 +1172,7 @@ public void runBeginBlock(StaticScope scope, CompilerCallback body) {
public void createNewForLoop(int arity, CompilerCallback body, CompilerCallback args, boolean hasMultipleArgsHead, NodeType argsNodeId, ASTInspector inspector) {
String closureMethodName = "block_" + script.getAndIncrementInnerIndex() + "$RUBY$__for__";
- ChildScopedBodyCompiler closureCompiler = new ChildScopedBodyCompiler(script, closureMethodName, rubyName, inspector, scope);
+ ChildScopedBodyCompiler closureCompiler = new ChildScopedBodyCompiler(script, closureMethodName, rubyName, inspector, scope, scopeIndex);
closureCompiler.beginMethod(args, null);
@@ -1153,7 +1197,7 @@ public void createNewForLoop(int arity, CompilerCallback body, CompilerCallback
public void createNewEndBlock(CompilerCallback body) {
String closureMethodName = "block_" + script.getAndIncrementInnerIndex() + "$RUBY$__end__";
- ChildScopedBodyCompiler closureCompiler = new ChildScopedBodyCompiler(script, closureMethodName, rubyName, null, scope);
+ ChildScopedBodyCompiler closureCompiler = new ChildScopedBodyCompiler(script, closureMethodName, rubyName, null, scope, scopeIndex);
closureCompiler.beginMethod(null, null);
@@ -1215,9 +1259,7 @@ public void loadTrue() {
}
public void loadCurrentModule() {
- loadThreadContext();
- invokeThreadContext("getCurrentScope", sig(DynamicScope.class));
- method.invokevirtual(p(DynamicScope.class), "getStaticScope", sig(StaticScope.class));
+ loadStaticScope();
method.invokevirtual(p(StaticScope.class), "getModule", sig(RubyModule.class));
}
@@ -1982,7 +2024,7 @@ public void isInstanceVariableDefined(String name) {
public void isClassVarDefined(String name, BranchCallback trueBranch, BranchCallback falseBranch) {
method.ldc(name);
- method.invokevirtual(p(RubyModule.class), "fastIsClassVarDefined", sig(boolean.class, params(String.class)));
+ method.invokevirtual(p(RubyModule.class), "isClassVarDefined", sig(boolean.class, params(String.class)));
Label trueLabel = new Label();
Label exitLabel = new Label();
method.ifne(trueLabel);
@@ -2321,61 +2363,6 @@ public void defineClass(
rubyName = "__singleton__";
}
- final RootScopedBodyCompiler classBody = new ClassBodyCompiler(script, classMethodName, rubyName, inspector, staticScope);
-
- // Here starts the logic for the class definition
- Label start = new Label();
- Label end = new Label();
- Label after = new Label();
- Label noException = new Label();
- classBody.method.trycatch(start, end, after, null);
-
- classBody.beginMethod(new ArgumentsCallback() {
- public int getArity() {
- return 0; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void call(BodyCompiler context) {
- classBody.loadThreadContext();
- classBody.method.aload(StandardASMCompiler.SELF_INDEX); // module to run the class under passed in as self
- classBody.method.checkcast(p(RubyModule.class));
-
- // static scope
- script.getCacheCompiler().cacheStaticScope(classBody, staticScope);
- if (inspector.hasClosure() || inspector.hasScopeAwareMethods()) {
- classBody.invokeThreadContext("preCompiledClass", sig(Void.TYPE, params(RubyModule.class, StaticScope.class)));
- } else {
- classBody.invokeThreadContext("preCompiledClassDummyScope", sig(Void.TYPE, params(RubyModule.class, StaticScope.class)));
- }
- }
- }, staticScope);
-
- // CLASS BODY
- if (RubyInstanceConfig.FULL_TRACE_ENABLED) classBody.traceClass();
-
- classBody.method.label(start);
-
- bodyCallback.call(classBody);
-
- classBody.method.label(end);
- // finally with no exception
- if (RubyInstanceConfig.FULL_TRACE_ENABLED) classBody.traceEnd();
- classBody.loadThreadContext();
- classBody.invokeThreadContext("postCompiledClass", sig(Void.TYPE, params()));
-
- classBody.method.go_to(noException);
-
- classBody.method.label(after);
- // finally with exception
- if (RubyInstanceConfig.FULL_TRACE_ENABLED) classBody.traceEnd();
- classBody.loadThreadContext();
- classBody.invokeThreadContext("postCompiledClass", sig(Void.TYPE, params()));
- classBody.method.athrow();
-
- classBody.method.label(noException);
-
- classBody.endBody();
-
// prepare to call class definition method
method.aload(StandardASMCompiler.THIS);
loadThreadContext();
@@ -2394,10 +2381,11 @@ public void call(BodyCompiler context) {
}
loadThreadContext();
+ loadStaticScope();
pathCallback.call(this);
- invokeUtilityMethod("prepareClassNamespace", sig(RubyModule.class, params(ThreadContext.class, IRubyObject.class)));
+ invokeUtilityMethod("prepareClassNamespace", sig(RubyModule.class, params(ThreadContext.class, StaticScope.class, IRubyObject.class)));
method.swap();
@@ -2413,67 +2401,62 @@ public void call(BodyCompiler context) {
invokeUtilityMethod("getSingletonClass", sig(RubyClass.class, params(Ruby.class, IRubyObject.class)));
}
+ // prepare and cache static scope using target class/module already on stack
+ method.dup();
+ loadThreadContext();
+ method.swap(); // [..., RubyModule, ThreadContext]
+
+ final int scopeIndex = script.getCacheCompiler().cacheStaticScope(this, staticScope); // [..., RubyModule, ThreadContext, StaticScope]
+ if (inspector.hasClosure() || inspector.hasScopeAwareMethods()) {
+ invokeThreadContext("preCompiledClass", sig(Void.TYPE, params(RubyModule.class, StaticScope.class)));
+ } else {
+ invokeThreadContext("preCompiledClassDummyScope", sig(Void.TYPE, params(RubyModule.class, StaticScope.class)));
+ }
+
method.getstatic(p(Block.class), "NULL_BLOCK", ci(Block.class));
method.invokestatic(script.getClassname(), classMethodName, StandardASMCompiler.getStaticMethodSignature(script.getClassname(), 0));
- }
-
- public void defineModule(final String name, final StaticScope staticScope, final CompilerCallback pathCallback, final CompilerCallback bodyCallback, final ASTInspector inspector) {
- String mangledName = JavaNameMangler.mangleMethodName(name);
- String moduleMethodName = "module__" + script.getAndIncrementMethodIndex() + "$RUBY$" + mangledName;
- final RootScopedBodyCompiler classBody = new ClassBodyCompiler(script, moduleMethodName, mangledName, inspector, staticScope);
+ // define the method that forms the body of the class/module
+ final RootScopedBodyCompiler classBody = new ClassBodyCompiler(script, classMethodName, rubyName, inspector, staticScope, scopeIndex);
- // Here starts the logic for the class definition
Label start = new Label();
Label end = new Label();
Label after = new Label();
Label noException = new Label();
classBody.method.trycatch(start, end, after, null);
- classBody.beginMethod(new ArgumentsCallback() {
- public int getArity() {
- return 0;
- }
-
- public void call(BodyCompiler context) {
- classBody.loadThreadContext();
- classBody.method.aload(StandardASMCompiler.SELF_INDEX); // module to run the module under passed in as self
- classBody.method.checkcast(p(RubyModule.class));
-
- // static scope
- script.getCacheCompiler().cacheStaticScope(classBody, staticScope);
- if (inspector.hasClosure() || inspector.hasScopeAwareMethods()) {
- classBody.invokeThreadContext("preCompiledClass", sig(Void.TYPE, params(RubyModule.class, StaticScope.class)));
- } else {
- classBody.invokeThreadContext("preCompiledClassDummyScope", sig(Void.TYPE, params(RubyModule.class, StaticScope.class)));
- }
- }
- }, staticScope);
-
- // CLASS BODY
+ classBody.beginMethod(null, staticScope);
if (RubyInstanceConfig.FULL_TRACE_ENABLED) classBody.traceClass();
classBody.method.label(start);
bodyCallback.call(classBody);
+
classBody.method.label(end);
+ // finally with no exception
+ if (RubyInstanceConfig.FULL_TRACE_ENABLED) classBody.traceEnd();
+ classBody.loadThreadContext();
+ classBody.invokeThreadContext("postCompiledClass", sig(Void.TYPE, params()));
classBody.method.go_to(noException);
classBody.method.label(after);
+ // finally with exception
if (RubyInstanceConfig.FULL_TRACE_ENABLED) classBody.traceEnd();
classBody.loadThreadContext();
classBody.invokeThreadContext("postCompiledClass", sig(Void.TYPE, params()));
classBody.method.athrow();
classBody.method.label(noException);
- if (RubyInstanceConfig.FULL_TRACE_ENABLED) classBody.traceEnd();
- classBody.loadThreadContext();
- classBody.invokeThreadContext("postCompiledClass", sig(Void.TYPE, params()));
classBody.endBody();
+ }
+
+ public void defineModule(final String name, final StaticScope staticScope, final CompilerCallback pathCallback, final CompilerCallback bodyCallback, final ASTInspector inspector) {
+ String mangledName = JavaNameMangler.mangleMethodName(name);
+ String moduleMethodName = "module__" + script.getAndIncrementMethodIndex() + "$RUBY$" + mangledName;
// prepare to call class definition method
method.aload(StandardASMCompiler.THIS);
@@ -2481,14 +2464,63 @@ public void call(BodyCompiler context) {
// prepare module object
loadThreadContext();
+ loadStaticScope();
+
pathCallback.call(this);
- invokeUtilityMethod("prepareClassNamespace", sig(RubyModule.class, params(ThreadContext.class, IRubyObject.class)));
+
+ invokeUtilityMethod("prepareClassNamespace", sig(RubyModule.class, params(ThreadContext.class, StaticScope.class, IRubyObject.class)));
+
method.ldc(name);
method.invokevirtual(p(RubyModule.class), "defineOrGetModuleUnder", sig(RubyModule.class, params(String.class)));
+ // prepare and cache static scope using target class/module already on stack
+ method.dup();
+ loadThreadContext();
+ method.swap(); // [..., RubyModule, ThreadContext]
+
+ final int scopeIndex = script.getCacheCompiler().cacheStaticScope(this, staticScope); // [..., RubyModule, ThreadContext, StaticScope]
+ if (inspector.hasClosure() || inspector.hasScopeAwareMethods()) {
+ invokeThreadContext("preCompiledClass", sig(Void.TYPE, params(RubyModule.class, StaticScope.class)));
+ } else {
+ invokeThreadContext("preCompiledClassDummyScope", sig(Void.TYPE, params(RubyModule.class, StaticScope.class)));
+ }
+
method.getstatic(p(Block.class), "NULL_BLOCK", ci(Block.class));
method.invokestatic(script.getClassname(), moduleMethodName, StandardASMCompiler.getStaticMethodSignature(script.getClassname(), 0));
+
+ // define the method that forms the body of the class/module
+ final RootScopedBodyCompiler classBody = new ClassBodyCompiler(script, moduleMethodName, mangledName, inspector, staticScope, scopeIndex);
+
+ Label start = new Label();
+ Label end = new Label();
+ Label after = new Label();
+ Label noException = new Label();
+ classBody.method.trycatch(start, end, after, null);
+
+ classBody.beginMethod(null, staticScope);
+
+ if (RubyInstanceConfig.FULL_TRACE_ENABLED) classBody.traceClass();
+
+ classBody.method.label(start);
+
+ bodyCallback.call(classBody);
+ classBody.method.label(end);
+
+ classBody.method.go_to(noException);
+
+ classBody.method.label(after);
+ if (RubyInstanceConfig.FULL_TRACE_ENABLED) classBody.traceEnd();
+ classBody.loadThreadContext();
+ classBody.invokeThreadContext("postCompiledClass", sig(Void.TYPE, params()));
+ classBody.method.athrow();
+
+ classBody.method.label(noException);
+ if (RubyInstanceConfig.FULL_TRACE_ENABLED) classBody.traceEnd();
+ classBody.loadThreadContext();
+ classBody.invokeThreadContext("postCompiledClass", sig(Void.TYPE, params()));
+
+ classBody.endBody();
}
public void unwrapPassedBlock() {
@@ -2616,13 +2648,6 @@ public void defineNewMethod(String name, int methodArity, StaticScope scope,
String mangledName = JavaNameMangler.mangleMethodName(name);
String newMethodName = "method__" + script.getAndIncrementMethodIndex() + "$RUBY$" + mangledName;
- BodyCompiler methodCompiler = script.startMethod(name, newMethodName, args, scope, inspector);
-
- // callbacks to fill in method body
- body.call(methodCompiler);
-
- methodCompiler.endBody();
-
// prepare to call "def" utility method to handle def logic
loadThreadContext();
@@ -2637,7 +2662,7 @@ public void defineNewMethod(String name, int methodArity, StaticScope scope,
method.ldc(newMethodName);
- script.getCacheCompiler().cacheStaticScope(this, scope);
+ int scopeIndex = script.getCacheCompiler().cacheStaticScope(this, scope);
method.pushInt(methodArity);
@@ -2656,6 +2681,15 @@ public void defineNewMethod(String name, int methodArity, StaticScope scope,
}
script.addInvokerDescriptor(newMethodName, methodArity, scope, inspector.getCallConfig(), filename, line);
+
+ // emit method body
+
+ BodyCompiler methodCompiler = script.startMethod(name, newMethodName, args, scope, inspector, scopeIndex);
+
+ // callbacks to fill in method body
+ body.call(methodCompiler);
+
+ methodCompiler.endBody();
}
public void rethrowIfSystemExit() {
@@ -2905,4 +2939,8 @@ public void definedNot() {
method.swap();
invokeUtilityMethod("getDefinedNot", sig(RubyString.class, Ruby.class, RubyString.class));
}
+
+ public int getScopeIndex() {
+ return scopeIndex;
+ }
}
View
2  src/org/jruby/compiler/impl/ChainedChildBodyCompiler.java
@@ -16,7 +16,7 @@ public void endBody() {
}
public ChainedChildBodyCompiler(StandardASMCompiler scriptCompiler, String methodName, String rubyName, ASTInspector inspector, StaticScope scope, ChildScopedBodyCompiler parent) {
- super(scriptCompiler, methodName, rubyName, inspector, scope);
+ super(scriptCompiler, methodName, rubyName, inspector, scope, parent.scopeIndex);
this.inNestedMethod = true;
}
}
View
2  src/org/jruby/compiler/impl/ChainedRootBodyCompiler.java
@@ -16,7 +16,7 @@ public void endBody() {
}
public ChainedRootBodyCompiler(StandardASMCompiler scriptCompiler, String methodName, String rubyName, ASTInspector inspector, StaticScope scope, RootScopedBodyCompiler parent) {
- super(scriptCompiler, methodName, rubyName, inspector, scope);
+ super(scriptCompiler, methodName, rubyName, inspector, scope, parent.scopeIndex);
this.inNestedMethod = true;
}
View
4 src/org/jruby/compiler/impl/ChildScopedBodyCompiler.java
@@ -13,8 +13,8 @@
public class ChildScopedBodyCompiler extends BaseBodyCompiler {
- public ChildScopedBodyCompiler(StandardASMCompiler scriptCompiler, String closureMethodName, String rubyName, ASTInspector inspector, StaticScope scope) {
- super(scriptCompiler, closureMethodName, rubyName, inspector, scope);
+ public ChildScopedBodyCompiler(StandardASMCompiler scriptCompiler, String closureMethodName, String rubyName, ASTInspector inspector, StaticScope scope, int scopeIndex) {
+ super(scriptCompiler, closureMethodName, rubyName, inspector, scope, scopeIndex);
}
@Override
View
4 src/org/jruby/compiler/impl/ChildScopedBodyCompiler19.java
@@ -5,8 +5,8 @@
public class ChildScopedBodyCompiler19 extends ChildScopedBodyCompiler {
- public ChildScopedBodyCompiler19(StandardASMCompiler scriptCompiler, String closureMethodName, String rubyName, ASTInspector inspector, StaticScope scope) {
- super(scriptCompiler, closureMethodName, rubyName, inspector, scope);
+ public ChildScopedBodyCompiler19(StandardASMCompiler scriptCompiler, String closureMethodName, String rubyName, ASTInspector inspector, StaticScope scope, int scopeIndex) {
+ super(scriptCompiler, closureMethodName, rubyName, inspector, scope, scopeIndex);
// we force argParamCount to 1 since we always know we'll have [] args
argParamCount = 1;
}
View
6 src/org/jruby/compiler/impl/ClassBodyCompiler.java
@@ -9,15 +9,15 @@
import static org.jruby.util.CodegenUtils.*;
public class ClassBodyCompiler extends RootScopedBodyCompiler {
- public ClassBodyCompiler(StandardASMCompiler scriptCompiler, String friendlyName, String rubyName, ASTInspector inspector, StaticScope scope) {
- super(scriptCompiler, friendlyName, rubyName, inspector, scope);
+ public ClassBodyCompiler(StandardASMCompiler scriptCompiler, String friendlyName, String rubyName, ASTInspector inspector, StaticScope scope, int scopeIndex) {
+ super(scriptCompiler, friendlyName, rubyName, inspector, scope, scopeIndex);
}
@Override
public void beginMethod(CompilerCallback bodyPrep, StaticScope scope) {
method.start();
- variableCompiler.beginClass(bodyPrep, scope);
+ variableCompiler.beginClass(scope);
// visit a label to start scoping for local vars in this method
method.label(scopeStart);
View
5 src/org/jruby/compiler/impl/HeapBasedVariableCompiler.java
@@ -83,7 +83,7 @@ public void declareLocals(StaticScope scope, Label start, Label end) {
method.visitLocalVariable("locals", ci(DynamicScope.class), null, start, end, methodCompiler.getDynamicScopeIndex());
}
- public void beginClass(CompilerCallback bodyPrep, StaticScope scope) {
+ public void beginClass(StaticScope scope) {
assert scope != null : "compiling a class body with no scope";
// store the local vars in a local variable for preparing the class (using previous scope)
@@ -94,9 +94,6 @@ public void beginClass(CompilerCallback bodyPrep, StaticScope scope) {
method.invokevirtual(p(DynamicScope.class), "getValues", sig(IRubyObject[].class));
method.astore(methodCompiler.getVarsArrayIndex());
- // class bodies prepare their own dynamic scope, so let it do that
- bodyPrep.call(methodCompiler);
-
// store the new local vars in a local variable
methodCompiler.loadThreadContext();
methodCompiler.invokeThreadContext("getCurrentScope", sig(DynamicScope.class));
View
48 src/org/jruby/compiler/impl/InheritedCacheCompiler.java
@@ -98,6 +98,13 @@ public InheritedCacheCompiler(StandardASMCompiler scriptCompiler) {
this.scriptCompiler = scriptCompiler;
}
+ public int reserveStaticScope() {
+ int index = scopeCount;
+ scopeCount++;
+
+ return index;
+ }
+
public int cacheStaticScope(BaseBodyCompiler method, StaticScope scope) {
String scopeString = RuntimeHelpers.encodeScope(scope);
@@ -107,25 +114,28 @@ public int cacheStaticScope(BaseBodyCompiler method, StaticScope scope) {
// retrieve scope from scopes array
method.loadThis();
method.loadThreadContext();
+ method.loadStaticScope();
method.method.ldc(scopeString);
if (index < AbstractScript.NUMBERED_SCOPE_COUNT) {
// use numbered access method
- method.method.invokevirtual(scriptCompiler.getClassname(), "getScope" + index, sig(StaticScope.class, ThreadContext.class, String.class));
+ method.method.invokevirtual(scriptCompiler.getClassname(), "getScope" + index, sig(StaticScope.class, ThreadContext.class, StaticScope.class, String.class));
} else {
method.method.pushInt(index);
- method.method.invokevirtual(scriptCompiler.getClassname(), "getScope", sig(StaticScope.class, ThreadContext.class, String.class, int.class));
+ method.method.invokevirtual(scriptCompiler.getClassname(), "getScope", sig(StaticScope.class, ThreadContext.class, StaticScope.class, String.class, int.class));
}
return index;
}
public void loadStaticScope(BaseBodyCompiler method, int index) {
+ method.loadThis();
+
if (scopeCount < AbstractScript.NUMBERED_SCOPE_COUNT) {
// use numbered access method
- method.method.invokevirtual(scriptCompiler.getClassname(), "getScope" + index, sig(StaticScope.class, ThreadContext.class, String