Skip to content

Commit d038633

Browse files
committed
Simplify class loading, Blackrush++
1 parent 8e77578 commit d038633

File tree

1 file changed

+6
-48
lines changed

1 file changed

+6
-48
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/BootJavaInterop.java

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -95,57 +95,15 @@ public SixModelObject getInteropForClass(Class<?> c) {
9595

9696
/** Main entry point for OO-ish callouts. */
9797
public SixModelObject typeForName(String name) {
98+
Class<?> klass = null;
99+
ClassLoader syscl = ClassLoader.getSystemClassLoader();
98100
try {
99-
return getSTableForClass(Class.forName(name)).WHAT;
100-
} catch (ClassNotFoundException e) {
101-
try {
102-
String cfname = name.replace(".", "/");
103-
String cpStr = System.getProperty("java.class.path");
104-
String[] cps = cpStr.split("[;:]");
105-
String cfpath = null;
106-
File cf = null;
107-
for(int i = 0; i < cps.length; i++) {
108-
cf = new File(cps[i] + "/" + cfname + ".class");
109-
if(cf.exists()) {
110-
cfpath = cf.toString().replace(cfname + ".class", "");
111-
break;
112-
}
113-
cf = null;
114-
}
115-
if(cfpath != null) {
116-
try {
117-
URL url = new URL("file://" + cfpath + "/");
118-
URLClassLoader cl = new URLClassLoader(new URL[] { url });
119-
jarClassLoaders.put(cfname, cl);
120-
return getSTableForClass(cl.loadClass(name)).WHAT;
121-
} catch (MalformedURLException mue) {
122-
throw mue;
123-
}
124-
} else {
125-
throw e;
126-
}
127-
} catch (ClassNotFoundException|MalformedURLException ine) {
128-
throw ExceptionHandling.dieInternal(gc.getCurrentThreadContext(), ine);
129-
}
101+
klass = syscl.loadClass(name);
130102
}
131-
}
132-
public SixModelObject typeForNameFromJAR(String name, String JAR) {
133-
try {
134-
URLClassLoader cl = jarClassLoaders.get(JAR);
135-
if (cl == null) {
136-
URL url = new URL("jar:" + new File(JAR).toURI().toURL() + "!/");
137-
cl = new URLClassLoader(new URL[] { url });
138-
jarClassLoaders.put(JAR, cl);
139-
}
140-
return getSTableForClass(Class.forName(name, true, cl)).WHAT;
141-
} catch (ClassNotFoundException e) {
142-
throw ExceptionHandling.dieInternal(gc.getCurrentThreadContext(), e);
143-
} catch (MalformedURLException e) {
144-
throw ExceptionHandling.dieInternal(gc.getCurrentThreadContext(), e);
145-
} catch (Throwable e) {
146-
e.printStackTrace();
147-
throw e;
103+
catch( ClassNotFoundException cnfe ) {
104+
throw ExceptionHandling.dieInternal(gc.getCurrentThreadContext(), cnfe);
148105
}
106+
return getSTableForClass(klass).WHAT;
149107
}
150108

151109
/** Convenience methods for NQP coding. */

0 commit comments

Comments
 (0)