OSDN Git Service

2007-02-21 Kyle Galloway <kgallowa@redhat.com>
authorkgallowa <kgallowa@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Feb 2007 18:09:24 +0000 (18:09 +0000)
committerkgallowa <kgallowa@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Feb 2007 18:09:24 +0000 (18:09 +0000)
* jvmti.cc (_Jv_JVMTI_GetArgumentsSize): New function.
* testsuite/libjava.jvmti/interp/getargssize.java: New test.
* testsuite/libjava.jvmti/interp/getargssize.h: Ditto.
* testsuite/libjava.jvmti/interp/getargssize.jar: Ditto.
* testsuite/libjava.jvmti/interp/getargssize.out: Ditto.
* testsuite/libjava.jvmti/interp/natgetargssize.cc: Ditto.

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

libjava/ChangeLog
libjava/jvmti.cc
libjava/testsuite/libjava.jvmti/interp/getargssize.h [new file with mode: 0644]
libjava/testsuite/libjava.jvmti/interp/getargssize.jar [new file with mode: 0644]
libjava/testsuite/libjava.jvmti/interp/getargssize.java [new file with mode: 0644]
libjava/testsuite/libjava.jvmti/interp/getargssize.out [new file with mode: 0644]
libjava/testsuite/libjava.jvmti/interp/natgetargssize.cc [new file with mode: 0644]

index 34c18cf..c3ff95a 100644 (file)
@@ -1,3 +1,12 @@
+2007-02-21  Kyle Galloway  <kgallowa@redhat.com>
+
+       * jvmti.cc (_Jv_JVMTI_GetArgumentsSize): New function.
+       * testsuite/libjava.jvmti/interp/getargssize.java: New test.
+       * testsuite/libjava.jvmti/interp/getargssize.h: Ditto.
+       * testsuite/libjava.jvmti/interp/getargssize.jar: Ditto.
+       * testsuite/libjava.jvmti/interp/getargssize.out: Ditto.
+       * testsuite/libjava.jvmti/interp/natgetargssize.cc: Ditto.
+
 2007-02-21  Gary Benson  <gbenson@redhat.com>
 
        * java/util/GregorianCalendar.java: Removed.
index 51f9d1d..faa7401 100644 (file)
@@ -1086,6 +1086,45 @@ _Jv_JVMTI_GetMaxLocals (jvmtiEnv *env, jmethodID method, jint *max_locals)
 }
 
 static jvmtiError JNICALL
+_Jv_JVMTI_GetArgumentsSize (jvmtiEnv *env, jmethodID method, jint *size)
+{
+  REQUIRE_PHASE (env, JVMTI_PHASE_START | JVMTI_PHASE_LIVE);
+  NULL_CHECK (size);
+  
+  CHECK_FOR_NATIVE_METHOD (method);
+  
+  jvmtiError jerr;
+  char *sig;
+  jint num_slots = 0;
+  
+  jerr = env->GetMethodName (method, NULL, &sig, NULL);
+  if (jerr != JVMTI_ERROR_NONE)
+    return jerr;
+  
+  // If the method is non-static add a slot for the "this" pointer.
+  if ((method->accflags & java::lang::reflect::Modifier::STATIC) == 0)
+    num_slots++;
+  
+  for (int i = 0; sig[i] != ')'; i++)
+    {
+      if (sig[i] == 'Z' || sig[i] == 'B' || sig[i] == 'C' || sig[i] == 'S'
+          || sig[i] == 'I' || sig[i] == 'F')
+        num_slots++;
+      else if (sig[i] == 'J' || sig[i] == 'D')
+        num_slots+=2;
+      else if (sig[i] == 'L')
+        {
+          num_slots++;
+          while (sig[i] != ';')
+            i++;
+        }
+    }
+  
+  *size = num_slots;
+  return JVMTI_ERROR_NONE;
+}
+
+static jvmtiError JNICALL
 _Jv_JVMTI_GetMethodDeclaringClass (MAYBE_UNUSED jvmtiEnv *env,
                                   jmethodID method,
                                   jclass *declaring_class_ptr)
@@ -2011,7 +2050,7 @@ struct _Jv_jvmtiEnv _Jv_JVMTI_Interface =
   _Jv_JVMTI_GetMethodModifiers,        // GetMethodModifers
   RESERVED,                    // reserved67
   _Jv_JVMTI_GetMaxLocals,              // GetMaxLocals
-  UNIMPLEMENTED,               // GetArgumentsSize
+  _Jv_JVMTI_GetArgumentsSize,          // GetArgumentsSize
   _Jv_JVMTI_GetLineNumberTable,        // GetLineNumberTable
   UNIMPLEMENTED,               // GetMethodLocation
   _Jv_JVMTI_GetLocalVariableTable,             // GetLocalVariableTable
diff --git a/libjava/testsuite/libjava.jvmti/interp/getargssize.h b/libjava/testsuite/libjava.jvmti/interp/getargssize.h
new file mode 100644 (file)
index 0000000..e1e1767
--- /dev/null
@@ -0,0 +1,19 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+
+#ifndef __getargssize__
+#define __getargssize__
+
+#include <jni.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+JNIEXPORT jint JNICALL Java_getargssize_do_1getargssize_1tests (JNIEnv *env, jclass);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __getargssize__ */
diff --git a/libjava/testsuite/libjava.jvmti/interp/getargssize.jar b/libjava/testsuite/libjava.jvmti/interp/getargssize.jar
new file mode 100644 (file)
index 0000000..4b92216
Binary files /dev/null and b/libjava/testsuite/libjava.jvmti/interp/getargssize.jar differ
diff --git a/libjava/testsuite/libjava.jvmti/interp/getargssize.java b/libjava/testsuite/libjava.jvmti/interp/getargssize.java
new file mode 100644 (file)
index 0000000..f5a2f25
--- /dev/null
@@ -0,0 +1,36 @@
+public class getargssize
+{
+  static
+    {
+      System.loadLibrary("natgetargssize");
+    }
+
+  public int aMethod (float fone, int ione)
+  {
+    return 0;
+  }
+  
+  public long bMethod (long lone, double done, int ione)
+  {
+    return 0;
+  }
+  
+  public static boolean cMethod ()
+  {
+    return false;
+  }
+  
+  public static Object dMethod (Object op)
+  {
+    return op;
+  }
+
+  public static native int do_getargssize_tests ();
+
+  public static void main (String[] args)
+  {
+    System.out.println ("JVMTI getargssize Interpreted Test");
+
+    do_getargssize_tests ();
+  }
+}
diff --git a/libjava/testsuite/libjava.jvmti/interp/getargssize.out b/libjava/testsuite/libjava.jvmti/interp/getargssize.out
new file mode 100644 (file)
index 0000000..cd91066
--- /dev/null
@@ -0,0 +1,5 @@
+JVMTI getargssize Interpreted Test
+Method 0 requires 3 slots for its arguments
+Method 1 requires 6 slots for its arguments
+Method 2 requires 0 slots for its arguments
+Method 3 requires 1 slots for its arguments
diff --git a/libjava/testsuite/libjava.jvmti/interp/natgetargssize.cc b/libjava/testsuite/libjava.jvmti/interp/natgetargssize.cc
new file mode 100644 (file)
index 0000000..326b5a6
--- /dev/null
@@ -0,0 +1,58 @@
+#include <jni.h>
+
+#include <jvmti.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "getargssize.h"
+
+JNIEXPORT jint JNICALL Java_getargssize_do_1getargssize_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 args_size;
+
+  jvmtiError jerr;
+  
+  jmethodID meth_ids[4];
+  
+  meth_ids[0] = env->GetMethodID (klass, "aMethod", "(FI)I");
+  meth_ids[1] = env->GetMethodID (klass, "bMethod", "(JDI)J");
+  meth_ids[2] = env->GetStaticMethodID (klass, "cMethod", "()Z");
+  meth_ids[3] = env->GetStaticMethodID (klass, "dMethod", 
+                                     "(Ljava/lang/Object;)Ljava/lang/Object;");
+  for (int i = 0; i < 4; i++)
+    {
+      jerr = jvmti->GetArgumentsSize (meth_ids[i], &args_size);
+      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
+        {
+          printf ("Method %d requires %d slots for its arguments\n", i,
+                  args_size);
+        }
+    }
+    
+    return 0;
+}