commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Bode <jchr...@web.de>
Subject Help with Javaflows ClassLoader
Date Sat, 10 Apr 2010 09:25:32 GMT
Hi,

I am in desperate need for a coroutine scripting solution for my game 
and I was so happy to find
javaflow.

Despite the simplicity of the tutorial, there seems to be a lot of 
complexity behind and I get errors
I have no chance to deal with. It would be great if someone could help 
me out. Without coroutine
support I am really stuck in a way, so I really appreciate any help.

I am using Netbeans 6.8 with jdk 1.6.0_16.
The file that is to be enhanced is with all other project-classes in the 
normal classpath. Its package is
"Tests.Scripts".

Here is what I tried:

//A simple test script
public class TestScript implements Runnable {

public void run() {
System.out.println("Script started");

for(int i = 0; i < 10; i++)
{
System.out.println("Step " + i);

Continuation.suspend();
}
}

}

//The main class
public class ContinuationTest {
public static void main(String[] argv) {
continuationTest();
}

private static void continuationTest() {
try {
ContinuationClassLoader cl = new ContinuationClassLoader(new URL[] {new 
File("/").toURI().toURL()}, ContinuationTest.class.getClassLoader());

cl.addLoaderPackageRoot("Tests.Scripts");
Class script = cl.loadClass("Tests.Scripts.TestScript");

System.out.println("Running script: ");

Continuation entity1 = 
Continuation.startWith((TestScript)script.newInstance());

System.out.println("Script suspended");

while (entity1 != null) {
entity1 = Continuation.continueWith(entity1);
System.out.println("Script suspended");
}

} catch (Exception ex) {
Logger.getLogger(ContinuationTest.class.getName()).log(Level.SEVERE, 
null, ex);
}


}
}


So nothing special here... The script is seemingly succesfully found and 
all the bytecode processing magic starts, but fails
anywere in, and I have no chance to understand what goes wrong. 
Apparently the "loadClass" method fails and this is what i get:

I cut parts out, where [...] is. As I am not sure if the ASM dump is 
valuable to you, I left it complete, so sorry for the long post.

11227341 AMonitored locals 0
7704521 AMonitored locals 0
17905416 AMonitored locals 0
21666162 AMonitored locals 0
21836611 AMonitored locals 0
783148 AMonitored locals 0
11227341 Monitored locals 0
7704521 Monitored locals 0
17905416 Monitored locals 0
21666162 Monitored locals 0
21836611 Monitored locals 0
783148 Monitored locals 0
java.lang.IndexOutOfBoundsException: Trying to access an inexistant 
local variable 0
at org.objectweb.asm.tree.analysis.Frame.setLocal(Unknown Source)
at org.objectweb.asm.tree.analysis.Analyzer.analyze(Unknown Source)
[...]
at Tests.ContinuationTest.continuationTest(ContinuationTest.java:31)
at Tests.ContinuationTest.main(ContinuationTest.java:23)
10.04.2010 11:21:26 Tests.ContinuationTest continuationTest
SCHWERWIEGEND: null
java.lang.RuntimeException: Trying to access an inexistant local 
variable 0 run()V
00000 ? : INVOKESTATIC 
org/apache/commons/javaflow/bytecode/StackRecorder.get 
()Lorg/apache/commons/javaflow/bytecode/StackRecorder;
00001 ? : DUP
00002 ? : ASTORE 2
00003 ? : L0
00004 ? : IFNULL L1
00005 ? : ALOAD 2
00006 ? : GETFIELD 
org/apache/commons/javaflow/bytecode/StackRecorder.isRestoring : Z
00007 ? : IFEQ L1
00008 ? : ALOAD 2
00009 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popInt ()I
00010 ? : TABLESWITCH
0: L2
1: L3
2: L4
3: L5
4: L6
5: L7
default: L1
00011 ? : L2
00012 ? : ALOAD 2
00013 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popObject 
()Ljava/lang/Object;
00014 ? : CHECKCAST Tests/Scripts/TestScript
00015 ? : ASTORE 0
00016 ? : ALOAD 2
00017 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popReference 
()Ljava/lang/Object;
00018 ? : CHECKCAST java/io/PrintStream
00019 ? : ACONST_NULL
00020 ? : GOTO L8
00021 ? : L3
00022 ? : ALOAD 2
00023 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popInt ()I
00024 ? : ISTORE 1
00025 ? : ALOAD 2
00026 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popObject 
()Ljava/lang/Object;
00027 ? : CHECKCAST Tests/Scripts/TestScript
00028 ? : ASTORE 0
00029 ? : ALOAD 2
00030 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popObject 
()Ljava/lang/Object;
00031 ? : CHECKCAST java/io/PrintStream
00032 ? : ALOAD 2
00033 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popReference 
()Ljava/lang/Object;
00034 ? : CHECKCAST java/lang/StringBuilder
00035 ? : ACONST_NULL
00036 ? : GOTO L9
00037 ? : L4
00038 ? : ALOAD 2
00039 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popInt ()I
00040 ? : ISTORE 1
00041 ? : ALOAD 2
00042 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popObject 
()Ljava/lang/Object;
00043 ? : CHECKCAST Tests/Scripts/TestScript
00044 ? : ASTORE 0
00045 ? : ALOAD 2
00046 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popObject 
()Ljava/lang/Object;
00047 ? : CHECKCAST java/io/PrintStream
00048 ? : ALOAD 2
00049 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popReference 
()Ljava/lang/Object;
00050 ? : CHECKCAST java/lang/StringBuilder
00051 ? : ICONST_0
00052 ? : GOTO L10
00053 ? : L5
00054 ? : ALOAD 2
00055 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popInt ()I
00056 ? : ISTORE 1
00057 ? : ALOAD 2
00058 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popObject 
()Ljava/lang/Object;
00059 ? : CHECKCAST Tests/Scripts/TestScript
00060 ? : ASTORE 0
00061 ? : ALOAD 2
00062 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popObject 
()Ljava/lang/Object;
00063 ? : CHECKCAST java/io/PrintStream
00064 ? : ALOAD 2
00065 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popReference 
()Ljava/lang/Object;
00066 ? : CHECKCAST java/lang/StringBuilder
00067 ? : GOTO L11
00068 ? : L6
00069 ? : ALOAD 2
00070 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popInt ()I
00071 ? : ISTORE 1
00072 ? : ALOAD 2
00073 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popObject 
()Ljava/lang/Object;
00074 ? : CHECKCAST Tests/Scripts/TestScript
00075 ? : ASTORE 0
00076 ? : ALOAD 2
00077 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popReference 
()Ljava/lang/Object;
00078 ? : CHECKCAST java/io/PrintStream
00079 ? : ACONST_NULL
00080 ? : GOTO L12
00081 ? : L7
00082 ? : ALOAD 2
00083 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popInt ()I
00084 ? : ISTORE 1
00085 ? : ALOAD 2
00086 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.popObject 
()Ljava/lang/Object;
00087 ? : CHECKCAST Tests/Scripts/TestScript
00088 ? : ASTORE 0
00089 ? : GOTO L13
00090 ? : L1
00091 ? : L14
00092 ? : LINENUMBER 17 L14
00093 ? : GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
00094 ? : LDC "Script started"
00095 ? : L8
00096 ? : INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
00097 ? : ALOAD 2
00098 ? : IFNULL L15
00099 ? : ALOAD 2
00100 ? : GETFIELD 
org/apache/commons/javaflow/bytecode/StackRecorder.isCapturing : Z
00101 ? : IFEQ L15
00102 ? : ALOAD 2
00103 ? : ALOAD 0
00104 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushReference 
(Ljava/lang/Object;)V
00105 ? : ALOAD 2
00106 ? : ALOAD 0
00107 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushObject 
(Ljava/lang/Object;)V
00108 ? : ALOAD 2
00109 ? : BIPUSH 0
00110 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00111 ? : RETURN
00112 ? : L15
00113 ? : L16
00114 ? : LINENUMBER 19 L16
00115 ? : ICONST_0
00116 ? : ISTORE 1
00117 ? : L17
00118 ? : ILOAD 1
00119 ? : BIPUSH 10
00120 ? : IF_ICMPGE L18
00121 ? : L19
00122 ? : LINENUMBER 21 L19
00123 ? : GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
00124 ? : NEW java/lang/StringBuilder
00125 ? : DUP
00126 ? : INVOKESPECIAL java/lang/StringBuilder.<init> ()V
00127 ? : LDC "Step "
00128 ? : L9
00129 ? : INVOKEVIRTUAL java/lang/StringBuilder.append 
(Ljava/lang/String;)Ljava/lang/StringBuilder;
00130 ? : ALOAD 2
00131 ? : IFNULL L20
00132 ? : ALOAD 2
00133 ? : GETFIELD 
org/apache/commons/javaflow/bytecode/StackRecorder.isCapturing : Z
00134 ? : IFEQ L20
00135 ? : POP
00136 ? : ALOAD 2
00137 ? : SWAP
00138 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushObject 
(Ljava/lang/Object;)V
00139 ? : ALOAD 2
00140 ? : ALOAD 0
00141 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushReference 
(Ljava/lang/Object;)V
00142 ? : ALOAD 2
00143 ? : ALOAD 0
00144 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushObject 
(Ljava/lang/Object;)V
00145 ? : ALOAD 2
00146 ? : ILOAD 1
00147 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00148 ? : ALOAD 2
00149 ? : BIPUSH 1
00150 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00151 ? : RETURN
00152 ? : L20
00153 ? : ILOAD 1
00154 ? : L10
00155 ? : INVOKEVIRTUAL java/lang/StringBuilder.append 
(I)Ljava/lang/StringBuilder;
00156 ? : ALOAD 2
00157 ? : IFNULL L21
00158 ? : ALOAD 2
00159 ? : GETFIELD 
org/apache/commons/javaflow/bytecode/StackRecorder.isCapturing : Z
00160 ? : IFEQ L21
00161 ? : POP
00162 ? : ALOAD 2
00163 ? : SWAP
00164 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushObject 
(Ljava/lang/Object;)V
00165 ? : ALOAD 2
00166 ? : ALOAD 0
00167 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushReference 
(Ljava/lang/Object;)V
00168 ? : ALOAD 2
00169 ? : ALOAD 0
00170 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushObject 
(Ljava/lang/Object;)V
00171 ? : ALOAD 2
00172 ? : ILOAD 1
00173 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00174 ? : ALOAD 2
00175 ? : BIPUSH 2
00176 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00177 ? : RETURN
00178 ? : L21
00179 ? : L11
00180 ? : INVOKEVIRTUAL java/lang/StringBuilder.toString 
()Ljava/lang/String;
00181 ? : ALOAD 2
00182 ? : IFNULL L22
00183 ? : ALOAD 2
00184 ? : GETFIELD 
org/apache/commons/javaflow/bytecode/StackRecorder.isCapturing : Z
00185 ? : IFEQ L22
00186 ? : POP
00187 ? : ALOAD 2
00188 ? : SWAP
00189 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushObject 
(Ljava/lang/Object;)V
00190 ? : ALOAD 2
00191 ? : ALOAD 0
00192 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushReference 
(Ljava/lang/Object;)V
00193 ? : ALOAD 2
00194 ? : ALOAD 0
00195 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushObject 
(Ljava/lang/Object;)V
00196 ? : ALOAD 2
00197 ? : ILOAD 1
00198 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00199 ? : ALOAD 2
00200 ? : BIPUSH 3
00201 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00202 ? : RETURN
00203 ? : L22
00204 ? : L12
00205 ? : INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
00206 ? : ALOAD 2
00207 ? : IFNULL L23
00208 ? : ALOAD 2
00209 ? : GETFIELD 
org/apache/commons/javaflow/bytecode/StackRecorder.isCapturing : Z
00210 ? : IFEQ L23
00211 ? : ALOAD 2
00212 ? : ALOAD 0
00213 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushReference 
(Ljava/lang/Object;)V
00214 ? : ALOAD 2
00215 ? : ALOAD 0
00216 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushObject 
(Ljava/lang/Object;)V
00217 ? : ALOAD 2
00218 ? : ILOAD 1
00219 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00220 ? : ALOAD 2
00221 ? : BIPUSH 4
00222 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00223 ? : RETURN
00224 ? : L23
00225 ? : L24
00226 ? : LINENUMBER 23 L24
00227 ? : L13
00228 ? : INVOKESTATIC org/apache/commons/javaflow/Continuation.suspend ()V
00229 ? : ALOAD 2
00230 ? : IFNULL L25
00231 ? : ALOAD 2
00232 ? : GETFIELD 
org/apache/commons/javaflow/bytecode/StackRecorder.isCapturing : Z
00233 ? : IFEQ L25
00234 ? : ALOAD 2
00235 ? : ALOAD 0
00236 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushReference 
(Ljava/lang/Object;)V
00237 ? : ALOAD 2
00238 ? : ALOAD 0
00239 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushObject 
(Ljava/lang/Object;)V
00240 ? : ALOAD 2
00241 ? : ILOAD 1
00242 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00243 ? : ALOAD 2
00244 ? : BIPUSH 5
00245 ? : INVOKEVIRTUAL 
org/apache/commons/javaflow/bytecode/StackRecorder.pushInt (I)V
00246 ? : RETURN
00247 ? : L25
00248 ? : L26
00249 ? : LINENUMBER 19 L26
00250 ? : IINC 1 1
00251 ? : GOTO L17
00252 ? : L18
00253 ? : LINENUMBER 25 L18
00254 ? : RETURN
00255 ? : L27
00256 ? : L28


at org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unknown Source)
[...]
at Tests.ContinuationTest.main(ContinuationTest.java:23)


So if anybody could help me I would really appreciate it. Besides I want 
to edit/load scripts while the main program is running. That?s why
I chose the class-loader approch.

Thanks a lot,
Christian Bode


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message