자바 개발자에게는 Exception은 필요하기도 하면서도 귀찮은 존재이죠. 하지만, 디버깅을 위해서라면 최고의 해답이 될수 있다고 생각이 됩니다.

하지만, 특정 경우 StackTrace의 소스 라인번호가 나오지 않고, 단순히 "compiled code"라고 나오면 참으로 답답할 따름이겠죠?

이를 해결 하기 위한 방법은 -Djava.compiler=NONE 을 추가해주거나 환경변수로 JAVA_COMPILER=NONE 해주는 방법입니다.

 

예1) java -Djava.compiler=NONE 클래스명

 

예2) export JAVA_COMPILER=NONE java 클래스명

 

해당 옵션은 정확히는 JIT 옵션을 제거하는 것이긴 하지만, JIT 옵션이 활성화 되어 있는 경우 class 파일을 native 코드로 컴파일 하면서 라인번호가 사라지는 것입니다.

 

하지만, 최근의 IBM java 에서 JIT를 끄고 돌리는 경우 성능상 많은 손실을 볼 수 있습니다.

(경험상으로는 jdk 1.3인 경우는 약 10% 정도의 성능 손실을, 1.4인 경우는 대략 20~30%정도의 성능 손실이 되는 듯합니다.)

 

결론:

1) StackTrace의 라인번호가 나오지 않는 경우에는 JIT 옵션을 제거하세요.

2) JIT 옵션을 제거하는 경우 성능상 손실을 볼수가 있으므로, 주의하세요

 

참조 : http://thunderguy.com/semicolon/2004/02/11/java-stack-trace-with-line-numbers/

 

Sometimes, application servers don’t display the line numbers during printing the trace but instead just print the method name with the “(Unknown Source)” on it.

eg. something like this.

Exception in thread “main” java.lang.ArithmeticException at TraceWithoutLineNumbers.main(Unknown Source)

I wrote this small class to just help me learn why the line numbers get missed and Unknown Source comes up when the trace gets printed.

 

package test;

 

public class TraceWithoutLineNumbers {

 

       public static void main(String[] args) {

              System.out.println("hello world");

 

              if (true) {

                     throw new ArithmeticException();

              }

              System.out.println("very true");

       }

}

 

For the above code, I gave a

Ø  javac TraceWithoutLineNumbers.java

and got

java TraceWithoutLineNumbers hello world Exception in thread “main” java.lang.ArithmeticException at TraceWithoutLineNumbers.main(TraceWithoutLineNumbers.java:9)

 

Cool. Got the line number.

By default, the minimal debugging option is on. (Only line number and source file information is generated). Here is the list of all the other java compiler options.

So, I do a

Ø  javac -g:none TraceWithoutLineNumbers.java

 

java TraceWithoutLineNumbers hello world Exception in thread “main” java.lang.ArithmeticException at TraceWithoutLineNumbers.main(Unknown Source)

 

There is nothing you could do on this if the class is built and run by the server ( read if you dont have control over the class’ compilation). However, if it is a standalone class, you can very well do a javac -g .

Or use this option.

-g:{keyword list}

Generate only some kinds of debugging information, specified by a comma

separated list of keywords. Valid keywords are:

source

 Source file debugging information

lines

 Line number debugging information

vars

 Local variable debugging information

Probably, the app server or the web server you are running your class on would have disabled the debugging option for performance purposes.

 

참조 : http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javac.html#options

'Java > The Java Language' 카테고리의 다른 글

What is Enum in Java  (1) 2013.02.06
Static and Nostatic Initializer blocks  (0) 2013.02.06
Assertion  (1) 2013.02.06
JVM Architecture  (0) 2013.02.06
JAR file  (0) 2013.02.06
Posted by Steven J.S Min
,