OSDN Git Service

2007-02-15 Kyle Galloway <kgallowa@redhat.com>
authorkgallowa <kgallowa@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 15 Feb 2007 14:49:50 +0000 (14:49 +0000)
committerkgallowa <kgallowa@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 15 Feb 2007 14:49:50 +0000 (14:49 +0000)
   * gnu/classpath/jdwp/natVMVirtualMachine (getFrames): Implement.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@121997 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/gnu/classpath/jdwp/natVMVirtualMachine.cc
libjava/testsuite/libjava.jvmti/interp/getlocalvartable.h [new file with mode: 0644]
libjava/testsuite/libjava.jvmti/interp/getlocalvartable.jar [new file with mode: 0644]
libjava/testsuite/libjava.jvmti/interp/getlocalvartable.java [new file with mode: 0644]
libjava/testsuite/libjava.jvmti/interp/getlocalvartable.out [new file with mode: 0644]
libjava/testsuite/libjava.jvmti/interp/natgetlocalvartable.cc [new file with mode: 0644]

index efd3543..5862f8f 100644 (file)
@@ -1,3 +1,7 @@
+2007-02-15  Kyle Galloway  <kgallowa@redhat.com>
+   * gnu/classpath/jdwp/natVMVirtualMachine (getFrames): Implement.
+
 2007-02-13  Keith Seitz  <keiths@redhat.com>
 
        * gnu/classpath/jdwp/natVMVirtualMachine.cc
index d219f58..71aa674 100644 (file)
@@ -486,11 +486,49 @@ getClassMethod (jclass klass, jlong id)
 }
 
 java::util::ArrayList *
-gnu::classpath::jdwp::VMVirtualMachine::getFrames (MAYBE_UNUSED Thread *thread,
-                                                  MAYBE_UNUSED jint start,
-                                                  MAYBE_UNUSED jint length)
+gnu::classpath::jdwp::VMVirtualMachine::getFrames (Thread *thread, jint start,
+                                                   jint length)
 {
-  return NULL;
+  jint frame_count = getFrameCount (thread);
+  ::java::util::ArrayList *frame_list;
+  
+  // Calculate the max number of frames to be returned.
+  jint num_frames = frame_count - start;
+  
+  // Check if num_frames is valid.
+  if (num_frames < 0)
+    num_frames = 0;
+  
+  // Check if there are more than length frames left after start.
+  // If length ios -1 return all remaining frames.
+  if (length != -1 && num_frames > length)
+    num_frames = length;
+     
+  frame_list = new ::java::util::ArrayList (num_frames);
+  
+  _Jv_Frame *vm_frame = reinterpret_cast<_Jv_Frame *> (thread->frame);
+  
+  // Take start frames off the top of the stack
+  while (vm_frame != NULL && start > 0)
+    {
+      start--;
+      vm_frame = vm_frame->next;
+    }
+  
+  // Use as a counter for the number of frames returned.
+  num_frames = 0;
+  
+  while (vm_frame != NULL && (num_frames < length || length == -1))
+    {  
+      jlong frameId = reinterpret_cast<jlong> (vm_frame);
+      
+      VMFrame *frame = getFrame (thread, frameId);
+      frame_list->add (frame);
+      vm_frame = vm_frame->next;
+      num_frames++;
+    }
+  
+  return frame_list;
 }
 
 gnu::classpath::jdwp::VMFrame *
diff --git a/libjava/testsuite/libjava.jvmti/interp/getlocalvartable.h b/libjava/testsuite/libjava.jvmti/interp/getlocalvartable.h
new file mode 100644 (file)
index 0000000..8d4cb3b
--- /dev/null
@@ -0,0 +1,19 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+
+#ifndef __getlocalvartable__
+#define __getlocalvartable__
+
+#include <jni.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+JNIEXPORT jint JNICALL Java_getlocalvartable_do_1getlocalvartable_1tests (JNIEnv *env, jclass);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __getlocalvartable__ */
diff --git a/libjava/testsuite/libjava.jvmti/interp/getlocalvartable.jar b/libjava/testsuite/libjava.jvmti/interp/getlocalvartable.jar
new file mode 100644 (file)
index 0000000..9fffb92
Binary files /dev/null and b/libjava/testsuite/libjava.jvmti/interp/getlocalvartable.jar differ
diff --git a/libjava/testsuite/libjava.jvmti/interp/getlocalvartable.java b/libjava/testsuite/libjava.jvmti/interp/getlocalvartable.java
new file mode 100644 (file)
index 0000000..e0f3b31
--- /dev/null
@@ -0,0 +1,63 @@
+public class getlocalvartable
+{
+  public boolean done = false;
+
+  // num_frames is the number of frames > the original run () call so if
+  // num_frames = 1, the thread will have 2 frames, the original Thread.run
+  // call, plus one additional
+  public int num_frames, thread_num;
+
+  public static int num_threads = 1;
+
+  static
+    {
+      System.loadLibrary("natgetlocalvartable");
+    }
+
+  public double aMethod (float pone, float ptwo)
+  {
+    float fone, ftwo;
+    double done, dtwo;
+    
+    fone = pone;
+    ftwo = 2 * ptwo;
+    
+    done = 5 * fone;
+    dtwo = 6 * ftwo;
+    
+    return done + dtwo;
+  }
+  
+  public long bMethod (int ipone, int iptwo)
+  {
+    int ione, itwo;
+    long lone, ltwo;
+    
+    ione = ipone;
+    itwo = 5 * iptwo;
+    
+    lone = ione;
+    ltwo = 8 * itwo;
+    
+    return lone + ltwo;
+  }
+  
+  public Object cMethod (Object op)
+  {
+    Object oone, otwo;
+    oone = op;
+    otwo = oone;
+    oone = null;
+    
+    return otwo;
+  }
+
+  public static native int do_getlocalvartable_tests ();
+
+  public static void main (String[] args)
+  {
+    System.out.println ("JVMTI getlocalvartable Interpreted Test");
+
+    do_getlocalvartable_tests ();
+  }
+}
diff --git a/libjava/testsuite/libjava.jvmti/interp/getlocalvartable.out b/libjava/testsuite/libjava.jvmti/interp/getlocalvartable.out
new file mode 100644 (file)
index 0000000..2e0ec40
--- /dev/null
@@ -0,0 +1,109 @@
+JVMTI getlocalvartable Interpreted Test
+Slot: 0
+  Name: this
+  Sig: Lgetlocalvartable;
+  Gen Sig: Lgetlocalvartable;
+  Start Loc: 0
+  Length: 28
+Slot: 1
+  Name: pone
+  Sig: F
+  Gen Sig: F
+  Start Loc: 0
+  Length: 28
+Slot: 2
+  Name: ptwo
+  Sig: F
+  Gen Sig: F
+  Start Loc: 0
+  Length: 28
+Slot: 3
+  Name: fone
+  Sig: F
+  Gen Sig: F
+  Start Loc: 2
+  Length: 26
+Slot: 4
+  Name: ftwo
+  Sig: F
+  Gen Sig: F
+  Start Loc: 7
+  Length: 21
+Slot: 5
+  Name: done
+  Sig: D
+  Gen Sig: D
+  Start Loc: 14
+  Length: 14
+Slot: 7
+  Name: dtwo
+  Sig: D
+  Gen Sig: D
+  Start Loc: 22
+  Length: 6
+Slot: 0
+  Name: this
+  Sig: Lgetlocalvartable;
+  Gen Sig: Lgetlocalvartable;
+  Start Loc: 0
+  Length: 25
+Slot: 1
+  Name: ipone
+  Sig: I
+  Gen Sig: I
+  Start Loc: 0
+  Length: 25
+Slot: 2
+  Name: iptwo
+  Sig: I
+  Gen Sig: I
+  Start Loc: 0
+  Length: 25
+Slot: 3
+  Name: ione
+  Sig: I
+  Gen Sig: I
+  Start Loc: 2
+  Length: 23
+Slot: 4
+  Name: itwo
+  Sig: I
+  Gen Sig: I
+  Start Loc: 7
+  Length: 18
+Slot: 5
+  Name: lone
+  Sig: J
+  Gen Sig: J
+  Start Loc: 11
+  Length: 14
+Slot: 7
+  Name: ltwo
+  Sig: J
+  Gen Sig: J
+  Start Loc: 19
+  Length: 6
+Slot: 0
+  Name: this
+  Sig: Lgetlocalvartable;
+  Gen Sig: Lgetlocalvartable;
+  Start Loc: 0
+  Length: 8
+Slot: 1
+  Name: op
+  Sig: Ljava/lang/Object;
+  Gen Sig: Ljava/lang/Object;
+  Start Loc: 0
+  Length: 8
+Slot: 2
+  Name: oone
+  Sig: Ljava/lang/Object;
+  Gen Sig: Ljava/lang/Object;
+  Start Loc: 2
+  Length: 6
+Slot: 3
+  Name: otwo
+  Sig: Ljava/lang/Object;
+  Gen Sig: Ljava/lang/Object;
+  Start Loc: 4
+  Length: 4
diff --git a/libjava/testsuite/libjava.jvmti/interp/natgetlocalvartable.cc b/libjava/testsuite/libjava.jvmti/interp/natgetlocalvartable.cc
new file mode 100644 (file)
index 0000000..3ca112d
--- /dev/null
@@ -0,0 +1,67 @@
+#include <jni.h>
+
+#include <jvmti.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "getlocalvartable.h"
+
+JNIEXPORT jint JNICALL Java_getlocalvartable_do_1getlocalvartable_1tests
+(JNIEnv *env, jclass klass)
+{
+  JavaVM *vm;
+  jint err = env->GetJavaVM (&vm);
+  if (err < 0)
+    {
+      fprintf (stderr, "error getting VM\n");
+      exit (1);
+    }
+
+  jvmtiEnv *jvmti = NULL;
+  vm->GetEnv ((void **) &jvmti, JVMTI_VERSION_1_0);
+
+  if (jvmti == NULL)
+    {
+      fprintf (stderr, "error getting jvmti environment\n");
+      exit (1);
+    }
+  
+  jint entrys;
+  jvmtiLocalVariableEntry *var_table;
+
+  jvmtiError jerr;
+  
+  jmethodID meth_ids[3];
+  
+  meth_ids[0] = env->GetMethodID (klass, "aMethod", "(FF)D");
+  meth_ids[1] = env->GetMethodID (klass, "bMethod", "(II)J");
+  meth_ids[2] = env->GetMethodID (klass, "cMethod", 
+                                  "(Ljava/lang/Object;)Ljava/lang/Object;");
+  for (int i = 0; i < 3; i++)
+    {
+      jerr = jvmti->GetLocalVariableTable (meth_ids[i], &entrys, &var_table);
+      if (jerr != JVMTI_ERROR_NONE)
+        {
+          char *error_name;
+          jvmti->GetErrorName (jerr, &error_name);
+          fprintf (stderr, "JVMTI Error: %s\n", error_name);
+          jvmti->Deallocate (reinterpret_cast<unsigned char *> (error_name));
+        }
+      else
+        {
+          for (int j = 0; j < entrys; j++)
+            {
+              printf ("Slot: %d\n", static_cast<int> (var_table[j].slot));
+              printf ("  Name: %s\n", var_table[j].name);
+              printf ("  Sig: %s\n", var_table[j].signature);
+              printf ("  Gen Sig: %s\n", var_table[j].generic_signature);
+              printf ("  Start Loc: %ld\n", static_cast<long> (var_table[j].start_location));
+              printf ("  Length: %d\n", static_cast<int> (var_table[j].length));
+            }
+          
+          jvmti->Deallocate (reinterpret_cast<unsigned char *> (var_table));
+        }
+    }
+    
+    return 0;
+}