Skip to content

Commit

Permalink
Delays LocalJumpError and SystemExit clas creations. But failed to de…
Browse files Browse the repository at this point in the history
…lay NameError class creation. If it's delayed runtime.getClass(NameError) returns null. This could be fixed changing the place to call tryGetConstantIfPossible. But, it ended up in classloader related(?) trouble to find org.jruby.runtime.backtrace.FrameType.
  • Loading branch information
yokolet committed Jul 20, 2012
1 parent a07f7ea commit cff6994
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/org/jruby/NativeException.java
Expand Up @@ -66,7 +66,7 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
}
};

public static RubyClass createClass(Ruby runtime, RubyClass baseClass) {
static RubyClass createClass(Ruby runtime, RubyClass baseClass) {
RubyClass exceptionClass = runtime.defineClass(CLASS_NAME, baseClass, NATIVE_EXCEPTION_ALLOCATOR);

exceptionClass.defineAnnotatedMethods(NativeException.class);
Expand Down
38 changes: 23 additions & 15 deletions src/org/jruby/Ruby.java
Expand Up @@ -1389,7 +1389,13 @@ private void initClassCreatorMap() {
classCreatorMap.put("ScriptError", this.getClass().getMethod("getScriptError"));
classCreatorMap.put("RangeError", this.getClass().getMethod("getRangeError"));
classCreatorMap.put("SignalException", this.getClass().getMethod("getSignalException"));
classCreatorMap.put("NameError", this.getClass().getMethod("getNameError"));
classCreatorMap.put("NameError::Message", this.getClass().getMethod("getNameErrorMessage"));
classCreatorMap.put("SystemExit", this.getClass().getMethod("getSystemExit"));

classCreatorMap.put("NoMethodError", this.getClass().getMethod("getNoMethodError"));
classCreatorMap.put("LocalJumpError", this.getClass().getMethod("getLocalJumpError"));
classCreatorMap.put("NativeException", this.getClass().getMethod("getNativeException"));
classCreatorMap.put("SystemCallError", this.getClass().getMethod("getSystemCallError"));
classCreatorMap.put("Fatal", this.getClass().getMethod("getFatal"));
classCreatorMap.put("Interrupt", this.getClass().getMethod("getInterrupt"));
Expand Down Expand Up @@ -1424,21 +1430,8 @@ public Method findClassCreatorMethod(String name) {

private void initExceptions() {
initClassCreatorMap();

if (profile.allowClass("NameError")) {
nameError = RubyNameError.createNameErrorClass(this, getStandardError());
nameErrorMessage = RubyNameError.createNameErrorMessageClass(this, nameError);
}
if (profile.allowClass("SystemExit")) {
systemExit = RubySystemExit.createSystemExitClass(this, getException());
}
if (profile.allowClass("LocalJumpError")) {
localJumpError = RubyLocalJumpError.createLocalJumpErrorClass(this, getStandardError());
}
if (profile.allowClass("NativeException")) {
nativeException = NativeException.createClass(this, getRuntimeError());
}

nameError = getNameError();

if (is1_9()) {
if (profile.allowClass("EncodingError")) {
encodingError = defineClass("EncodingError", getStandardError(), getStandardError().getAllocator());
Expand Down Expand Up @@ -2144,10 +2137,16 @@ public RubyClass getException() {
}

public RubyClass getNameError() {
if (nameError == null && profile.allowClass("NameError")) {
nameError = RubyNameError.createNameErrorClass(this, getStandardError());
}
return nameError;
}

public RubyClass getNameErrorMessage() {
if (nameErrorMessage == null && profile.allowClass("NameError")) {
nameErrorMessage = RubyNameError.createNameErrorMessageClass(this, getNameError());
}
return nameErrorMessage;
}

Expand All @@ -2169,14 +2168,23 @@ public RubyClass getRangeError() {
}

public RubyClass getSystemExit() {
if (systemExit == null && profile.allowClass("SystemExit")) {
systemExit = RubySystemExit.createSystemExitClass(this, getException());
}
return systemExit;
}

public RubyClass getLocalJumpError() {
if (localJumpError == null && profile.allowClass("LocalJumpError")) {
localJumpError = RubyLocalJumpError.createLocalJumpErrorClass(this, getStandardError());
}
return localJumpError;
}

public RubyClass getNativeException() {
if (nativeException == null && profile.allowClass("NativeException")) {
nativeException = NativeException.createClass(this, getRuntimeError());
}
return nativeException;
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/jruby/RubyLocalJumpError.java
Expand Up @@ -50,7 +50,7 @@ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
}
};

public static RubyClass createLocalJumpErrorClass(Ruby runtime, RubyClass standardErrorClass) {
static RubyClass createLocalJumpErrorClass(Ruby runtime, RubyClass standardErrorClass) {
RubyClass nameErrorClass = runtime.defineClass("LocalJumpError", standardErrorClass, LOCALJUMPERROR_ALLOCATOR);

nameErrorClass.defineAnnotatedMethods(RubyLocalJumpError.class);
Expand Down
2 changes: 1 addition & 1 deletion src/org/jruby/RubyModule.java
Expand Up @@ -3465,7 +3465,7 @@ public IRubyObject fetchConstant(String name) {
public IRubyObject fetchConstant(String name, boolean includePrivate) {
assert IdUtil.isConstant(name);
ConstantEntry entry = constantEntryFetch(name);

if (entry == null) return null;

if (entry.hidden && !includePrivate) {
Expand Down
4 changes: 2 additions & 2 deletions src/org/jruby/RubyNameError.java
Expand Up @@ -141,13 +141,13 @@ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
}
};

public static RubyClass createNameErrorClass(Ruby runtime, RubyClass standardErrorClass) {
static RubyClass createNameErrorClass(Ruby runtime, RubyClass standardErrorClass) {
RubyClass nameErrorClass = runtime.defineClass("NameError", standardErrorClass, NAMEERROR_ALLOCATOR);
nameErrorClass.defineAnnotatedMethods(RubyNameError.class);
return nameErrorClass;
}

public static RubyClass createNameErrorMessageClass(Ruby runtime, RubyClass nameErrorClass) {
static RubyClass createNameErrorMessageClass(Ruby runtime, RubyClass nameErrorClass) {
RubyClass messageClass = nameErrorClass.defineClassUnder("Message", runtime.getClass("Data"), RubyNameErrorMessage.NAMEERRORMESSAGE_ALLOCATOR);
messageClass.defineAnnotatedMethods(RubyNameErrorMessage.class);
return messageClass;
Expand Down
2 changes: 1 addition & 1 deletion src/org/jruby/RubySystemExit.java
Expand Up @@ -43,7 +43,7 @@ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
}
};

public static RubyClass createSystemExitClass(Ruby runtime, RubyClass exceptionClass) {
static RubyClass createSystemExitClass(Ruby runtime, RubyClass exceptionClass) {
RubyClass systemExitClass = runtime.defineClass("SystemExit", exceptionClass, SYSTEMEXIT_ALLOCATOR);

systemExitClass.defineAnnotatedMethods(RubySystemExit.class);
Expand Down

0 comments on commit cff6994

Please sign in to comment.