2010-05-14 4 views
2

Eclipse의 디버거에서 breakpoint 표준에 의해 약간 비효율적 인 조건부 중단 점을 설정했습니다. HashMap의 값 목록 (8 개 요소)에 Double.NaN이 있는지 확인합니다. 이로 인해 성능이 크게 저하되었습니다. 약 5 분 후에 포기했습니다.질문 Eclipse 정보 Java Debugger 조건부 중단 점 비효율

그런 다음 조건문을 동일한 줄에 if 문에 붙여 넣고 if에 noop을 넣고 거기에 일반 중단 점을 설정합니다. 그 중단 점은 예상 된 20-30 초 내에 도달했습니다.

조건부 중단 점이 성능에 치중하게 만드는 특별한 것이 있습니까? 아니면 Eclipse의 구현이 다소 어리석은가요? 그들이 아주 쉽게 똑같은 일을 할 수있는 것처럼 보입니다.

답변

2

흥미 롭습니다!

조건부 중단 점의 유무를 확인하기 위해 일부 소스 코드를 사용했습니다. 아래 첨부. 조건부 중단 점 디버거에서

실행 :
이 기간 : 1,210,623 마이크로

이 조건부 중단없이 디버거에서

실행 :
기간 : 24 마이크로

는 VM이 ​​때문에 중단되지 IMHO 두 번째 스레드가 계속해서 나란히 실행됩니다. Eclipse는 현재 클래스에 중단 점 코드를 주입해야합니다. 어쩌면 모든 호출마다 그렇게 할 수 있으며 모든 호출에서 클래스를 다시 컴파일해야 할 수도 있습니다. Eclipse 소스를 확인하면 정확히 무슨 일이 일어나는지 알 수 있습니다.

C# 및 Visual Studio에서 조건부 중단 점을 실행 한 경험이 훨씬 더 나쁩니다. 위장감은 상황이 몇 가지 더 심각하다는 것입니다.

public class BreakPointPlay { 

static int breakpointHits; 

static volatile int modifiedBySecondThread; 

static volatile boolean stopped; 

public static void main(String[] args) throws InterruptedException { 

    Thread secondThread = startSecondThread(); 

    final long LOOPS = 1000; 
    long counter = 0; 
    long start = System.nanoTime(); 
    for (long i = 0; i < LOOPS; i++) { 

     // place breakpoint here and set the condition to the 
     // #breakPointCondition() method. 
     counter += i; 

    } 
    long stop = System.nanoTime(); 
    long nanos = stop - start; 
    long micros = nanos/1000; 

    System.out.println("\nDuration: " + micros + " microseconds\n"); 

    printInfo(); 
    stopped = true; 

    secondThread.join(); 
} 

private static Thread startSecondThread() { 
    Thread thread = new Thread(new Runnable() { 
     @Override 
     public void run() { 
      while(! stopped){ 
       modifiedBySecondThread++; 
      } 
     } 
    }); 
    thread.start(); 
    return thread; 
} 

private static void printInfo() { 
    printModifiedBySecondThread(); 
    printThread(); 
    printClassLoader(); 
    printStackTrace(); 
    printModifiedBySecondThread(); 
} 

private static void printStackTrace() { 
    Exception exception = new Exception(); 
    exception.fillInStackTrace(); 
    exception.printStackTrace(System.out); 
} 

private static void printModifiedBySecondThread() { 
    print("modifiedBySecondThread " + modifiedBySecondThread); 
} 

public static boolean breakPointCondition(){ 
    breakpointHits++; 
    if(breakpointHits == 100){ 
     printInfo(); 
    } 
    return false; 
} 

private static void printClassLoader() { 
    print("ClassLoader " + new BreakPointPlay().getClass().getClassLoader()); 
} 

private static void printThread() { 
    print("Thread " + Thread.currentThread()); 
} 

private static void print(String msg){ 
    System.out.println(msg); 
} 


} 
0

중단 점은 몇 번 통과 했습니까? 디버거가 트리거되기 전에 중단 점 조건을 여러 번 테스트해야 할 수도 있습니다. 어떻게 구현되는지는 모르겠지만 디버거가 조건을 실행하는 것이 일반적으로 컴파일 된 Java보다 훨씬 효율적이지 않은 경우 놀라지 않을 것입니다. JIT에서 관심을 덜받는 것일 수도 있습니다. 아마 심지어 Java로 완전히 컴파일되지 않고 해석됩니다.

0

Eclipse는 중단 점 조건을 검사하기 위해 전체 JVM을 중지해야합니다. 이것이 비용이 드는 이유입니다.