harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x..@apache.org
Subject svn commit: r574899 - in /harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes: javasrc/java/lang/Throwable.java javasrc/org/apache/harmony/vm/VMStack.java native/org_apache_harmony_vm_VMStack.cpp native/org_apache_harmony_vm_VMStack.h
Date Wed, 12 Sep 2007 11:59:31 GMT
Author: xli
Date: Wed Sep 12 04:59:29 2007
New Revision: 574899

URL: http://svn.apache.org/viewvc?rev=574899&view=rev
Log:
HARMONY-3997 : [drlvm][exception] Class unloading support in lazy stack creation.

Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Throwable.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/vm/VMStack.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.h

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Throwable.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Throwable.java?rev=574899&r1=574898&r2=574899&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Throwable.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Throwable.java
Wed Sep 12 04:59:29 2007
@@ -41,8 +41,10 @@
 	private final String detailMessage;
 
 	private StackTraceElement[] stackTrace;
-	
-	private transient Object state;
+
+    private transient Class [] stackClasses;
+
+    private transient Object state;
 
     /**
      * @com.intel.drl.spec_ref 
@@ -80,6 +82,7 @@
      */
 	public Throwable fillInStackTrace() {
 		state = VMStack.getStackState();
+        stackClasses = VMStack.getStackClasses(state);
 		return this;
 	}
 
@@ -107,14 +110,9 @@
     /**
      * @com.intel.drl.spec_ref 
      */
-	public StackTraceElement[] getStackTrace() {
-	    if (stackTrace == null) {
-	        stackTrace = VMStack.getStackTrace(state);
-	    }
-		StackTraceElement[] st = new StackTraceElement[stackTrace.length];
-		System.arraycopy(stackTrace, 0, st, 0, stackTrace.length);
-		return st;
-	}
+    public StackTraceElement[] getStackTrace() {
+        return getStackTrace(true);
+    }
 
     /**
      * @com.intel.drl.spec_ref 
@@ -149,15 +147,37 @@
     /**
      * @com.intel.drl.spec_ref 
      */
-	public void printStackTrace(PrintWriter pw) {
+    public void printStackTrace(PrintWriter pw) {
 		pw.println(makeThrowableString());
-	}
+    }
+
+    private void initStackTrace() {
+        if (stackTrace == null) {
+            stackTrace = VMStack.getStackTrace(state);
+            state = null;
+            stackClasses = null;
+        }
+    }
+
+    private StackTraceElement[] getStackTrace(boolean copyArray)
+    {
+        StackTraceElement[] st;
+        initStackTrace();
+
+        if (copyArray) {
+            st = new StackTraceElement[stackTrace.length];
+            System.arraycopy(stackTrace, 0, st, 0, stackTrace.length);
+        } else {
+            st = stackTrace;
+        }
+        return st;
+    }
 
 	private String makeThrowableString() {
         StringBuffer sb = new StringBuffer();
         sb.append(toString());
 	    if (stackTrace == null) {
-	        stackTrace = VMStack.getStackTrace(state);
+            initStackTrace();
 	    }
 	    // FIXME stackTrace should never be null here
         if (stackTrace != null) {
@@ -173,7 +193,7 @@
             StackTraceElement[] parentStackTrace = wCause.stackTrace;
             wCause = wCause.getCause();
     	    if (wCause.stackTrace == null) {
-    	        wCause.stackTrace = VMStack.getStackTrace(wCause.state);
+                wCause.initStackTrace();
     	    }
             sb.append("\nCaused by: ").append(wCause.toString());
     	    // FIXME wCause.stackTrace should never be null here
@@ -242,7 +262,7 @@
 
         private void writeObject(ObjectOutputStream s) throws IOException {
             if (stackTrace == null) {
-                stackTrace = VMStack.getStackTrace(state);
+                initStackTrace();
             }
             s.defaultWriteObject();
         }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/vm/VMStack.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/vm/VMStack.java?rev=574899&r1=574898&r2=574899&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/vm/VMStack.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/vm/VMStack.java
Wed Sep 12 04:59:29 2007
@@ -78,7 +78,7 @@
      * @api2vm
      */
     public static native Class[] getClasses(int maxSize, boolean considerPrivileged);
-    
+
     /**
      * Saves stack information of currently executing thread. Returned object
      * can be used as a handler to obtain an array of
@@ -88,7 +88,27 @@
      * @return handler of the current stack. 
      */
     public static native Object getStackState();
-    
+
+    /**
+     * Collects and returns the classes of invoked methods as an array of the
+     * {@link Class} objects. This method may be used by
+     * <code>java.lang.Throwable</code> class implementation.
+     * <p>
+     * Resulting stack should contain native stack frames as well as reflection
+     * stack frames.
+     * <p>
+     * <b>Note</b>, that it returns classes for all stack, without any checks.
+     * It's fast, simple version of {@link VMStack#getClasses() VMStack.getClasses()}
+     * method, and used from Throwable class implementation.
+     *
+     * @param state handler returned by the
+     *        {@link VMStack#getStackState() VMStack.getStackState()} method.
+     * @return array of <code>Class</code> elements. If stack is
+     *         empty then null should be returned.
+     * @api2vm
+     */
+    public static native Class[] getStackClasses(Object state);
+
     /**
      * Collects and returns the stack of invoked methods as an array of the
      * {@link StackTraceElement} objects. This method may be used by
@@ -108,6 +128,6 @@
      * @api2vm
      */
     public static native StackTraceElement[] getStackTrace(Object state);
-    
+
     public static native StackTraceElement[] getThreadStackTrace(Thread t);
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp?rev=574899&r1=574898&r2=574899&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.cpp
Wed Sep 12 04:59:29 2007
@@ -241,7 +241,6 @@
     return arr;
 }
 
-
 /*
  * Class:     org_apache_harmony_vm_VMStack
  * Method:    getStackState
@@ -274,6 +273,52 @@
 
     return array;
 } // Java_org_apache_harmony_vm_VMStack_getStackState
+
+/*
+ * Class:     org_apache_harmony_vm_VMStack
+ * Method:    getStackClasses
+ * Signature: (Ljava/lang/Object;)[Ljava/lang/Class;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_vm_VMStack_getStackClasses
+  (JNIEnv *jenv, jclass, jobject state)
+{
+    ASSERT_RAISE_AREA;
+    if (NULL == state)
+        return NULL;
+
+    Global_Env* genv = jni_get_vm_env(jenv);
+
+     // state object contains raw data as long array
+    jlongArray array = (jlongArray)state;
+    assert(array);
+
+    // copy data to array
+    jlong* array_data = jenv->GetLongArrayElements(array, NULL);
+
+    // get depth of the stack
+    StackTraceFrame* frames = (StackTraceFrame*) array_data;
+    unsigned size = jenv->GetArrayLength(array) * 8 / sizeof(StackTraceFrame);
+
+    // get class array class
+    jclass cac = struct_Class_to_java_lang_Class_Handle(genv->JavaLangClass_Class);
+    assert(cac);
+
+    // create java array
+    jobjectArray arr = jenv->NewObjectArray(size, cac, NULL);
+    if (arr == NULL) {
+        return NULL;
+    }
+
+    // find and store classes of the methods on the stack
+    for (unsigned i=0; i < size; i++) {
+        Method* m = frames[i].method;
+        Class* c = m->get_class();
+        jclass jc = struct_Class_to_java_lang_Class_Handle(c);
+        jenv->SetObjectArrayElement(arr, i, jc);
+    }
+
+    return arr;
+}
 
 /*
  * Class:     org_apache_harmony_vm_VMStack

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.h?rev=574899&r1=574898&r2=574899&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.h
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_vm_VMStack.h
Wed Sep 12 04:59:29 2007
@@ -62,6 +62,13 @@
 Java_org_apache_harmony_vm_VMStack_getStackState(JNIEnv *, jclass);
 
 /*
+ * Method: org.apache.harmony.vm.VMStack.getStackClasse(Ljava/lang/Object;)[Ljava/lang/Class
+ */
+JNIEXPORT jobjectArray JNICALL
+Java_org_apache_harmony_vm_VMStack_getStackClasses(JNIEnv *, jclass,
+    jobject);
+
+/*
  * Method: org.apache.harmony.vm.VMStack.getStackTrace(Ljava/lang/Object;)[Ljava/lang/StackTraceElement;
  */
 JNIEXPORT jobjectArray JNICALL



Mime
View raw message