[hg] main-silver: #227892: Load the type and super class outside...

  • From:
  • To:
  • Subject: [hg] main-silver: #227892: Load the type and super class outside...
  • Date: Sun, 31 Mar 2013 04:41:21 -0700

changeset 5efed451e491 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/5efed451e491
description:
        #227892: Load the type and super class outside of synchronized block 
in order to prevent from AWT waiting on the lock for a long time.

diffstat:

 
debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractObjectVariable.java
 |  114 +++++++--
 1 files changed, 87 insertions(+), 27 deletions(-)

diffs (179 lines):

diff --git 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractObjectVariable.java
 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractObjectVariable.java
--- 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractObjectVariable.java
+++ 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/AbstractObjectVariable.java
@@ -118,8 +118,10 @@
     private com.sun.jdi.Type valueType;
     private String           valueTypeName;
     private final boolean[]  valueTypeLoaded = new boolean[] { false };
+    private boolean          valueTypeLoading = false;
     private Super            superClass;
     private final boolean[]  superClassLoaded = new boolean[] { false };
+    private boolean          superClassLoading = false;
     
     private DebuggetStateListener stateChangeListener = new 
DebuggetStateListener();
 
@@ -317,7 +319,23 @@
 
     public Super getSuper () {
         synchronized (superClassLoaded) {
-            if (!superClassLoaded[0]) {
+            if (superClassLoaded[0]) {
+                return superClass;
+            }
+            if (superClassLoading) {
+                try {
+                    superClassLoaded.wait();
+                } catch (InterruptedException ex) {
+                    return null;
+                }
+                if (superClassLoaded[0]) {
+                    return superClass;
+                }
+            } else {
+                superClassLoading = true;
+            }
+        }
+        Super sup = null;
                 try {
                     Type t = getCachedType();
                     if (t instanceof ClassType) {
@@ -331,26 +349,23 @@
                                     superType,
                                     getID()
                                     );
-                            superClass = s;
-                        } else {
-                            superClass = null;
+                    sup = s;
                         }
-                    } else {
-                        superClass = null;
                     }
                 } catch (ObjectCollectedExceptionWrapper ocex) {
-                    superClass = null;
                 } catch (InternalExceptionWrapper ex) {
-                    superClass = null;
                 } catch (VMDisconnectedExceptionWrapper e) {
-                    superClass = null;
                 } finally {
+            synchronized (superClassLoaded) {
+                if (superClassLoading) {
+                    superClass = sup;
+                    superClassLoading = false;
                     superClassLoaded[0] = true;
+                    superClassLoaded.notifyAll();
                 }
-
             }
-            return superClass;
         }
+        return sup;
     }
 
     public boolean hasAllTypes() {
@@ -633,22 +648,64 @@
         return getDebugger().evaluate(expression, this);
     }
 
-    private com.sun.jdi.Type getCachedType() throws 
InternalExceptionWrapper, VMDisconnectedExceptionWrapper, 
ObjectCollectedExceptionWrapper {
+    private com.sun.jdi.Type getCachedType() throws InternalExceptionWrapper,
+                                                    
VMDisconnectedExceptionWrapper,
+                                                    
ObjectCollectedExceptionWrapper {
+        return getCachedType(null);
+    }
+    
+    private com.sun.jdi.Type getCachedType(String[] namePtr) throws 
InternalExceptionWrapper,
+                                                                    
VMDisconnectedExceptionWrapper,
+                                                                    
ObjectCollectedExceptionWrapper {
         synchronized (valueTypeLoaded) {
-            if (!valueTypeLoaded[0]) {
-                Value v = getInnerValue();
-                if (v != null) {
-                    //assert !java.awt.EventQueue.isDispatchThread();
-                    valueType = ValueWrapper.type(v);
-                    valueTypeName = TypeWrapper.name(valueType);
-                } else {
-                    valueType = null;
-                    valueTypeName = "";
-                }
-                valueTypeLoaded[0] = true;
+            if (valueTypeLoaded[0]) {
+                if (namePtr != null) {
+                    namePtr[0] = valueTypeName;
             }
             return valueType;
         }
+            if (valueTypeLoading) {
+                try {
+                    valueTypeLoaded.wait();
+                } catch (InterruptedException ex) {
+                    return null;
+                }
+                if (valueTypeLoaded[0]) { // Check if it was really loaded
+                    if (namePtr != null) {
+                        namePtr[0] = valueTypeName;
+                    }
+                    return valueType;
+                } else {
+                    return null;
+                }
+            } else {
+                valueTypeLoading = true;
+            }
+        }
+        Value v = getInnerValue();
+        Type type = null;
+        String typeName = "";
+        try {
+            if (v != null) {
+                //assert !java.awt.EventQueue.isDispatchThread();
+                type = ValueWrapper.type(v);
+                typeName = TypeWrapper.name(type);
+            }
+        } finally {
+            synchronized (valueTypeLoaded) {
+                if (valueTypeLoading) { // While we're sill interested in it
+                    valueType = type;
+                    valueTypeName = typeName;
+                    valueTypeLoading = false;
+                    valueTypeLoaded[0] = true;
+                    valueTypeLoaded.notifyAll();
+                }
+            }
+        }
+        if (namePtr != null) {
+            namePtr[0] = typeName;
+        }
+        return type;
     }
     
     /**
@@ -660,10 +717,9 @@
     public String getType () {
         if (genericType != null) return genericType;
         try {
-            synchronized (valueTypeLoaded) {
-                getCachedType();
-                return valueTypeName;
-            }
+            String[] typeNamePtr = new String[1];
+            getCachedType(typeNamePtr);
+            return typeNamePtr[0];
         } catch (InternalExceptionWrapper ex) {
             return ex.getLocalizedMessage();
         } catch (VMDisconnectedExceptionWrapper vmdex) {
@@ -726,10 +782,14 @@
             inheritedFields = null;
         }
         synchronized (superClassLoaded) {
+            superClassLoading = false;
             superClassLoaded[0] = false;
+            superClassLoaded.notifyAll();
         }
         synchronized (valueTypeLoaded) {
+            valueTypeLoading = false;
             valueTypeLoaded[0] = false;
+            valueTypeLoaded.notifyAll();
         }
     }
     

[hg] main-silver: #227892: Load the type and super class outside...

mentlicher 03/31/2013

Project Features

About this Project

Debugger was started in November 2009, is owned by tpavek, and has 29 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close