I think that JohnR might have mentioned this to me once, but I just 
figured out/remembered that it is very easy to turn on Java method
tracing from within Tcl Blend.

Method tracing is sort of a poor man's printf, where methods are
announced as they are entered.

I just added the following to my tcl blend troubleshooting notes
at
http://ptolemy.eecs.berkeley.edu/~cxh/java/tclblend/troubleshooting.html

--start--

Tracing MethodCalls

The java.lang.Runtime optionally includes support for tracing Java
Method Calls 

To turn on tracing, execute the following code: 

    set runtime [java::call Runtime getRuntime]
    $runtime traceMethodCalls True

For example: 

% package require java
1.1
% set runtime [java::call Runtime getRuntime]
java0x1
%  $runtime traceMethodCalls True
# main [ 1] | < java/lang/Runtime.traceMethodCalls(Z)V returning
# main [ 1] | < tcl/lang/Interp.setResult(Ltcl/lang/TclObject;)V returning
% set a [java::new java.util.GregorianCalendar]
# main [ 1] | < tcl/lang/CObject.incrRefCount(J)V returning
# main [ 1] | < tcl/lang/CObject.incrRefCount(J)V returning
# main [ 1] | < tcl/lang/CObject.getString(J)Ljava/lang/String; returning
# main [ 1] | <
tcl/lang/Interp.createCommand(Ljava/lang/String;Ltcl/lang/Command;)V returning
# main [ 1] | < tcl/lang/TclList.listLength(JJ)I returning
# main [ 1] | < tcl/lang/CObject.incrRefCount(J)V returning
# main [ 1] | < tcl/lang/CObject.decrRefCount(J)V returning
# main [ 1] | < tcl/lang/TclList.listLength(JJ)I returning
# main [ 2] | | < tcl/lang/CObject.incrRefCount(J)V returning
# main [ 1] | < tcl/lang/TclList.index(JI)Ltcl/lang/TclObject; returning
# main [ 1] | < tcl/lang/CObject.getString(J)Ljava/lang/String; returning
# main [ 1] | < tcl/lang/TclList.listLength(JJ)I returning
# main [ 2] | | < tcl/lang/CObject.incrRefCount(J)V returning
# main [ 1] | < tcl/lang/TclList.index(JI)Ltcl/lang/TclObject; returning
# main [ 1] | < tcl/lang/CObject.getString(J)Ljava/lang/String; returning
# main [ 1] | < 
tcl/lang/Interp.getVar(Ljava/lang/String;Ljava/lang/String;I)Ltcl/lang/TclObject; 
throwing tcl/lang/TclException
# main [ 1] | < tcl/lang/CObject.getString(J)Ljava/lang/String; returning
# main [ 1] | < tcl/lang/CObject.makeRef(JLtcl/lang/TclObject;)V returning
# main [ 1] | < tcl/lang/CObject.decrRefCount(J)V returning
# main [ 3] | | | < 
java/lang/System.arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V returning
# main [ 3] | | | < java/lang/Float.floatToIntBits(F)I returning
# main [ 3] | | | < java/lang/Double.doubleToLongBits(D)J returning
# main [ 1] | < tcl/lang/Interp.createCommand(Ljava/lang/String;Ltcl/lang/Command;)V 
returning
# main [ 1] | < tcl/lang/Interp.setResult(Ltcl/lang/TclObject;)V returning
java0x2
% 

To turn off tracing of method calls 

    $runtime traceMethodCalls False




Tracing Instructions

The java.lang.Runtime optionally includes support for tracing
instructions 

To turn on tracing, execute the following code: 

    set runtime [java::call Runtime getRuntime]
    $runtime traceInstructions True

For example: 

% package require java
1.1
% set runtime [java::call Runtime getRuntime]
java0x1
% $runtime traceInstructions True
% set a [java::new java.util.GregorianCalendar]
ED6660B0        0execute_java_constructor new tcl/lang/JavaNewCmd =>
tcl.lang.JavaNewCmd@ED66B748/ED757DC0
ED6660B0        0execute_java_constructor new java/lang/String =>
java.lang.String@ED66B738/ED757DE0
ED6660B0        0execute_java_constructor new java/lang/String =>
java.lang.String@ED66B720/ED757E40
ED6660B0        0execute_java_constructor new java/lang/String =>
java.lang.String@ED66B710/ED757E80
ED6660B0        0execute_java_constructor new java/lang/String =>
java.lang.String@ED66B838/ED757EC0
ED6660B0        0execute_java_constructor new java/lang/String =>
java.lang.String@ED66B6F0/ED757F18
ED6660B0        0execute_java_constructor new java/lang/String =>
java.lang.String@ED66B970/ED758008
ED6660B0        0execute_java_constructor new java/lang/String =>
java.lang.String@ED66B948/ED7580B8
ED6660B0        0execute_java_constructor new java/lang/String =>
java.lang.String@ED66B920/ED758140
[etc]

To turn of tracing of instructions, execute the following code: 

    $runtime traceInstructions False

The output of tracing instructions is very detailed, you may want to
trace method calls instead. 

--end--

Also, the following proc will query the system for the total amount of
memory and the amount of free memory

# Get Runtime information
proc jdkRuntime {} {
    set runtime [java::call Runtime getRuntime]
    puts "totalMemory: [$runtime totalMemory]"
    puts "freeMemory:  [$runtime freeMemory]"
}

-Christopher

----------------------------------------------------------------
The TclJava mailing list is sponsored by WebNet Technologies.
To subscribe:    send mail to [EMAIL PROTECTED]  
                 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
                 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 
A list archive is at: http://www.findmail.com/listsaver/tcldallas/

Reply via email to