Skip to main content

Where to change the value of code?

4 replies [Last post]
jayce_nqq
Offline
Joined: 2009-06-18
Points: 0

Dear all,
In project cldc, com.sun.squawk.ServiceOperation.java, there is a loop. Squawk VM change the value of code(Line 78:private static int code) to do switch loop. Who knows where the project changes the value of code?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
eric_arseneau
Offline
Joined: 2004-07-15
Points: 0

Derek will need to answer this one, I say an indirect one in

com.sun.squawk.vm.Global

I assume these are variables used by the VM, just not sure how yet.

Derek, can you enlighten us?

jayce_nqq
Offline
Joined: 2009-06-18
Points: 0

Is [b][i]code[/i][/b](in com.sun.squawk.ServiceOperation.java) = [b][i]Global.com_sun_squawk_ServiceOperation$code[/i][/b](in com.sun.squawk.vm.Global.java) ? I changed the function [b][i]execute()[/i][/b] in ServiceOperation like following:
static void execute() {
try {
/////////////////////////////////////////////////////////
VM.println("==========ServiceOperation==========");
VM.println(code);
VM.println(Global.com_sun_squawk_ServiceOperation$code);
VM.println("==========ServiceOperation==========");
/////////////////////////////////////////////////////////
for (;;) {
VM.threadSwitch();

switch(code) {
case EXTEND: {

if (VMThread.extendStack(i1)) {
VM.println("EXTEND, code = 1");
break;
}
pendingException = VM.getOutOfMemoryError(); // and drop through to THROW
}
case THROW: {
VM.print("THROW,code = 4");
VM.println(code);

VM.throwException(pendingException);
break;
}
case GARBAGE_COLLECT: {
/////////////////////////////////////////////////////////
VM.print("GARBAGE_COLLECT,code = ");
VM.println(code);
VM.print("Global.com_sun_squawk_ServiceOperation$code = ");
VM.println(Global.com_sun_squawk_ServiceOperation$code);
Hashtable intGlobal = Global.getGlobalInts();
VM.print("(int)Global.com_sun_squawk_ServiceOperation$code = ");
VM.printObject(intGlobal.get("com.sun.squawk.ServiceOperation.code"));
/////////////////////////////////////////////////////////

GC.collectGarbage(i1 != 0);
break;
}
case COPY_OBJECT_GRAPH: {
VM.println("COPY_OBJECT_GRAPH,code = 3");
GC.copyObjectGraph(o1, (ObjectMemorySerializer.ControlBlock)o2.toObject());
break;
}
case CHANNELIO: {
cioExecute();
break;
}
default: {
VM.fatalVMError();
break;
}
}
o1 = null;
o2 = null;
}
} finally {

VM.println(code);
}
}

But the result of test is like this:
[b]==========ServiceOperation==========
0
-8608480570021773305
==========ServiceOperation==========
GARBAGE_COLLECT,code = 2
Global.com_sun_squawk_ServiceOperation$code=-8608480570021773295
(int)Global.com_sun_squawk_ServiceOperation$code=7[/b]

where to change the value of [b][i]code[/i][/b]?

derek_white
Offline
Joined: 2006-09-08
Points: 0

OK, I think I'm starting to understand your question.

ServiceOperation.execute() is meant to be executed by the interpreter loop, on the service stack. So "code" is set by the interpreter loop.

The constants in VM.Global are similarly designed for the interpreter, and contain encoded information about the variable, not the variable value itself.

You can try to do the call from the interpreter loop, but if you can tell us what you're trying to do maybe there is a simpler solution...
- Derek

jayce_nqq
Offline
Joined: 2009-06-18
Points: 0

Thank you!

According to read the source code of Squawk, I know that the thread scheduling of Squawk VM is based on thread priority. What I want to do is adding an Round-Robin scheduling to Squawk VM. So I need to assign a quantum to each thread. If the thread is still running at the end of the quantum, Squawk needs to schedule another thread.

My problem is how to trigger the schedule at the end of quantum? My solution is to change the [b][i]code[/i][/b] of [b]ServiceOperation[/b]. Now [b][i]code[/i][/b] has five value in [b]ServiceOperation[/b], I want to add a vaule to the [b][i]code[/i][/b]. So in the interpreter loop, squawk can do the Round-Robin?

Can you understand my question by my description?

Thank you for your help!!!!