5.10.1 When the -XX:+HitachiLocalsInThrowable Option Is Specified
For each stack frame information of the stack trace information output by the java.lang.Throwable.printStackTrace method, the local variable information within the method corresponding to that stack frame is inserted and output.
- Organization of this subsection
(1) Example of output in standard format and simple output format
This is the example of output when you specify the -XX:+HitachiLocalsInThrowable option only as a function to output local variables.
The example of Java program and output of the corresponding local variable information within the stack trace are as follows:
Java program example 1
class Example1 { public static void main(String[] args) { Example1 e1 = new Example1(); Object obj = new Object(); e1.method(1, 'Q', obj); // Execute-e1.method (5th line). } void method(int l1, char l2, Object l3) { float l4 = 4.0f; boolean l5 = true; double l6 = Double.MAX_VALUE; Object[] l7 = new Object[10]; try { <Exception occurred!> // methodProcess-when-there-is-an-exception-in-process-of-method(15th line). } catch (Exception e) { e.printStackTrace(); // output-stack-trace-information (17th line). } } }
The example of output is described below.
This example is the stack trace information output by e.printStackTrace method on the 17th line when an exception occurs in e1.method method executed on the 5th line of example 1 of the Java program.
|
The output contents are as follows:
-
The information of the method that executes the stack trace output process is output. This example shows the output of the stack trace information when an exception occurs on the 15th line of the Java program 1.
-
As the local variable information, the information of objects invoked by the instance method is output. In this example, the class name and address of the object of example 1 class created on the 3rd line of example 1 of the Java program is output.
-
As local variable information, the information of the values of local variables specified as arguments of the method are output. The [arg*] after variable name is the information indicating the number of the method argument. The values specified when executing the e1.method method on the 5th line of example 1 of Java program are output.
Note that for local variables 11 and 12, the actual value is output since they are basic type (int type and char type) variables. The local variable l3 is a java.lang.Object class type variable, as a result, the address is output.
-
As local variable information, from the local variables in the method, information of the values of local variables that are not specified as method argument is output.
Note that since the local variables l4 to l6 are of basic type (float type, boolean type, and double type), their actual value is output. Since the local variable l7 is the java.lang.Object class type variable, the address is output.
The example of output in the simple output format when you specify -XX:+HitachiLocalsSimpleFormat option, is described below. Further, the explanation of the output contents is the same as that for standard format.
|
Moreover, if the -g option or -g:vars option is not specified when executing javac command, and since there is no local variable information, the output contents are restricted in the following manner. This is same as when executing the native method.
-
The local variables that can be output are only the arguments that are passed to the method and objects (this) invoked by the instance method.
-
For the arguments passed to the method, the variable name is not output. Only the argument number is output.
-
In the case of the native method, the value when the native method is invoked is output as the value of the local variable. It is not the output result that reflects the result of the executing native method.
The example of output in the case of Java program example 1, when the local variable information does not exist, is described below. The example of output in the simple output format is as follows:
|
There are following differences as compared to Figure 5-3.
-
The variable names of the arguments (l1 to l3) passed to the method is not output.
-
As the value is output when the method is invoked, the information (l4 to l7) for the local variables set in the method is not output.
(2) Example of output when class or array type variables are output as a character string
When the local variables to be output are of class or array type, there are times when the information required for troubleshooting cannot be acquired in the value expression of only the address. At this time, if you specify the -XX:HitachiCallToString option, you can acquire the value of class or array type variable as a character string. In options, you can specify minimal or full as the applicable scope.
When you specify -XX:HitachiCallToString=minimal option, among the classes in the java.lang package, String, StringBuffer, Boolean, Byte, Character, Short, Integer, Long, Float, or Double are the targets of a parameter. When specifying the -XX:HitachiCallToString=full option, all the classes are targets.
An example of the Java program and example of output when the -XX:HitachiCallToString option is specified is described below. Further, the simple output format is used below.
Java program example 2
class Example2 { public static void main(String[] args) { Example2 e2 = new Example2(); e2.method();// Executes-e2.method-method (4th line). } void method() { String l1 = "local 1"; StringBuffer l2 = new StringBuffer(l1); l2.append(" + local 2"); Boolean l3 = new Boolean(false); Character l4 = new Character('X'); Long l5 = new Long(Long.MIN_VALUE); Object l6 = new Thread(); Object[] l7 = new Thread[10]; try { <Exception occurred!> // Process-when-exception-occurred-in-process-of-method (18th line). } catch (Exception e) { e.printStackTrace(); // Output stack trace information (20th line). } } public String toString() { return "I am an Example2 instance."; } }
An example of output when specifying the -XX:HitachiCallToString=minimal option is described below:
This example is the stack trace information output by the 20th line e.printStackTrace method when an exception occurs in the e2.method method executed on the 4th line of example 1 of the Java program.
|
The output contents are as follows:
-
Among the local variables of class type, this information is that of the local variables of class type for which a character string is to be output. In continuation to the address, the value converted into a character string is output.
-
Among the local variables of class type, this information is that of local variables of class type for which a character string is not to be output. Only the address is output.
Shown below is the example of output when you specify the -XX:HitachiCallToString=full option.
|
There are following differences as compared to Figure 5-5.
-
When you specify minimal, the character string is output even for the local variables (l6 and l7) of the arrays of java.lang.Object and java.lang.Object class for which a character string is not to be output.
However, the character string is not output and only the address is output, such as in the following cases:
-
If the value of the local variable is null
-
If an error occurs again when a character string is being output, you cannot acquire the value successfully.
- Important note
-
The object output in the local variable information may be operated in parallel by other threads. For this reason, the character string output by specifying this option may be different than the information corresponding to that object when an exception actually occurs.
(3) Example of output when the actual type name of class or array type variables is to be output
When local variables that are output are of class or array type, there are cases when that variable type name and the type name of actually substituted value differ. For example, depending on the inheritance relationship of classes or the implementation relationship of interfaces, values of different type names are substituted in variables.
In this case, by specifying the -XX:+HitachiTrueTypeInLocals option, you can add the type name of a value actually substituted to the class or array type variables and acquire the character string.
The acquired character string is output by adding one single byte space at the end of the value expression and enclosing with parentheses (()). At this time, there is no limit on the output character string length.
An example of output when you specify -XX:+HitachiTrueTypeInLocals option is described below. Simple output format is shown below. The program to be executed is example 2 of the Java program. Moreover, this example is an example where you specify the -XX:HitachiCallToString=minimal option.
|
The output contents are as follows:
-
The variable type name is an array of java.lang.Object class or java.lang.Object class but the type name of the actually substituted value is output as the array of java.lang.Thread class and java.lang.Thread class.
Note that you can specify the -XX:+HitachiTrueTypeInLocals option along with the -XX:HitachiCallToString=full option.