This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] JVMTI GetArgumentsSize


Tom Tromey wrote:
"Kyle" == Kyle Galloway <kgallowa@redhat.com> writes:

Kyle> As requested, I have changed this to determine the arguments size by Kyle> looking at the method signature. Patch is attached.


Kyle> + sig = strtok (sig, ")");

Don't use strtok. It writes to the string and it is not thread-safe.
Kyle> + for (int i = 0; i < strlen (sig); i++)


You generally don't want to use strlen(sig) in a loop test.
Instead, here, end when sig[i] == ')'.
Cool. I have changed this as requested.
Kyle> + || sig[i] == 'I' || sig[i] == 'F' || sig[i] == 'L')

For the 'L' case you have to search forward to the terminating ';'.
Done, forgot class names could have 'L's in them.

New Patch attached.

Thanks,
Kyle

Index: libjava/testsuite/libjava.jvmti/interp/getargssize.out
===================================================================
--- libjava/testsuite/libjava.jvmti/interp/getargssize.out	(revision 0)
+++ libjava/testsuite/libjava.jvmti/interp/getargssize.out	(revision 0)
@@ -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
Index: libjava/testsuite/libjava.jvmti/interp/getlocalvartable.h
===================================================================
--- libjava/testsuite/libjava.jvmti/interp/getlocalvartable.h	(revision 122165)
+++ libjava/testsuite/libjava.jvmti/interp/getlocalvartable.h	(working copy)
@@ -1,19 +1,34 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
 
+// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*-
+
 #ifndef __getlocalvartable__
 #define __getlocalvartable__
 
-#include <jni.h>
+#pragma interface
 
-#ifdef __cplusplus
-extern "C"
+#include <java/lang/Object.h>
+#include <gcj/array.h>
+
+extern "Java"
 {
-#endif
+    class getlocalvartable;
+}
 
-JNIEXPORT jint JNICALL Java_getlocalvartable_do_1getlocalvartable_1tests (JNIEnv *env, jclass);
+class getlocalvartable : public ::java::lang::Object
+{
 
-#ifdef __cplusplus
-}
-#endif
+public:
+  getlocalvartable();
+  virtual jdouble aMethod(jfloat, jfloat);
+  virtual jlong bMethod(jint, jint);
+  virtual ::java::lang::Object * cMethod(::java::lang::Object *);
+  static jint do_getlocalvartable_tests();
+  static void main(JArray< ::java::lang::String * > *);
+  jboolean __attribute__((aligned(__alignof__( ::java::lang::Object)))) done;
+  jint num_frames;
+  jint thread_num;
+  static jint num_threads;
+  static ::java::lang::Class class$;
+};
 
-#endif /* __getlocalvartable__ */
+#endif // __getlocalvartable__
Index: libjava/testsuite/libjava.jvmti/interp/getargssize.jar
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream

Property changes on: libjava/testsuite/libjava.jvmti/interp/getargssize.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Index: libjava/testsuite/libjava.jvmti/interp/getargssize.java
===================================================================
--- libjava/testsuite/libjava.jvmti/interp/getargssize.java	(revision 0)
+++ libjava/testsuite/libjava.jvmti/interp/getargssize.java	(revision 0)
@@ -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 ();
+  }
+}
Index: libjava/testsuite/libjava.jvmti/interp/getargssize.h
===================================================================
--- libjava/testsuite/libjava.jvmti/interp/getargssize.h	(revision 0)
+++ libjava/testsuite/libjava.jvmti/interp/getargssize.h	(revision 0)
@@ -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__ */
Index: libjava/testsuite/libjava.jvmti/interp/natgetargssize.cc
===================================================================
--- libjava/testsuite/libjava.jvmti/interp/natgetargssize.cc	(revision 0)
+++ libjava/testsuite/libjava.jvmti/interp/natgetargssize.cc	(revision 0)
@@ -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;
+}
Index: libjava/jvmti.cc
===================================================================
--- libjava/jvmti.cc	(revision 122165)
+++ libjava/jvmti.cc	(working copy)
@@ -1086,6 +1086,44 @@
 }
 
 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++;
+          for (;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 +2049,7 @@
   _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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]