mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-01 01:00:17 +08:00
jvmti.cc (_Jv_JVMTI_GetMethodName): New function.
* jvmti.cc (_Jv_JVMTI_GetMethodName): New function. (_Jv_JVMTI_Interface): Define GetMethodName. * testsuite/libjava.jvmti/getmethodname.java: New file. * testsuite/libjava.jvmti/natgetmethodname.cc: New file. * testsuite/libjava.jvmti/getmethodname.out: New file. From-SVN: r121179
This commit is contained in:
parent
7d52200069
commit
ff393407cf
@ -1,3 +1,11 @@
|
||||
2007-01-25 Keith Seitz <keiths@redhat.com>
|
||||
|
||||
* jvmti.cc (_Jv_JVMTI_GetMethodName): New function.
|
||||
(_Jv_JVMTI_Interface): Define GetMethodName.
|
||||
* testsuite/libjava.jvmti/getmethodname.java: New file.
|
||||
* testsuite/libjava.jvmti/natgetmethodname.cc: New file.
|
||||
* testsuite/libjava.jvmti/getmethodname.out: New file.
|
||||
|
||||
2007-01-24 Kyle Galloway <kgallowa@redhat.com>
|
||||
|
||||
* libjava/testsuite/libjava.jvmti/jvmti-interp.exp: New file.
|
||||
|
@ -567,6 +567,48 @@ _Jv_JVMTI_IsFieldSynthetic (MAYBE_UNUSED jvmtiEnv *env, jclass klass,
|
||||
return JVMTI_ERROR_NONE;
|
||||
}
|
||||
|
||||
static jvmtiError JNICALL
|
||||
_Jv_JVMTI_GetMethodName (MAYBE_UNUSED jvmtiEnv *env, jmethodID method,
|
||||
char **name_ptr, char **signature_ptr,
|
||||
char **generic_ptr)
|
||||
{
|
||||
REQUIRE_PHASE (env, JVMTI_PHASE_START | JVMTI_PHASE_LIVE);
|
||||
|
||||
if (method == NULL)
|
||||
return JVMTI_ERROR_INVALID_METHODID;
|
||||
|
||||
if (name_ptr != NULL)
|
||||
{
|
||||
int len = static_cast<int> (method->name->len ());
|
||||
*name_ptr = (char *) _Jv_MallocUnchecked (len + 1);
|
||||
if (*name_ptr == NULL)
|
||||
return JVMTI_ERROR_OUT_OF_MEMORY;
|
||||
strncpy (*name_ptr, method->name->chars (), len);
|
||||
(*name_ptr)[len] = '\0';
|
||||
}
|
||||
|
||||
if (signature_ptr != NULL)
|
||||
{
|
||||
int len = static_cast<int> (method->signature->len ());
|
||||
*signature_ptr = (char *) _Jv_MallocUnchecked (len + 1);
|
||||
if (*signature_ptr == NULL)
|
||||
{
|
||||
if (name_ptr != NULL)
|
||||
_Jv_Free (*name_ptr);
|
||||
return JVMTI_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
strncpy (*signature_ptr, method->signature->chars (), len);
|
||||
(*signature_ptr)[len] = '\0';
|
||||
}
|
||||
|
||||
if (generic_ptr != NULL)
|
||||
{
|
||||
*generic_ptr = NULL;
|
||||
}
|
||||
|
||||
return JVMTI_ERROR_NONE;
|
||||
}
|
||||
|
||||
static jvmtiError JNICALL
|
||||
_Jv_JVMTI_GetMethodModifiers (MAYBE_UNUSED jvmtiEnv *env, jmethodID method,
|
||||
jint *result)
|
||||
@ -1497,7 +1539,7 @@ struct _Jv_jvmtiEnv _Jv_JVMTI_Interface =
|
||||
UNIMPLEMENTED, // GetFieldDeclaringClass
|
||||
_Jv_JVMTI_GetFieldModifiers, // GetFieldModifiers
|
||||
_Jv_JVMTI_IsFieldSynthetic, // IsFieldSynthetic
|
||||
UNIMPLEMENTED, // GetMethodName
|
||||
_Jv_JVMTI_GetMethodName, // GetMethodName
|
||||
_Jv_JVMTI_GetMethodDeclaringClass, // GetMethodDeclaringClass
|
||||
_Jv_JVMTI_GetMethodModifiers, // GetMethodModifers
|
||||
RESERVED, // reserved67
|
||||
|
10
libjava/testsuite/libjava.jvmti/getmethodname.java
Normal file
10
libjava/testsuite/libjava.jvmti/getmethodname.java
Normal file
@ -0,0 +1,10 @@
|
||||
public class getmethodname
|
||||
{
|
||||
public static native void do_getmethodname_tests ();
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
System.out.println ("JVMTI GetMethodName tests");
|
||||
do_getmethodname_tests ();
|
||||
}
|
||||
}
|
59
libjava/testsuite/libjava.jvmti/getmethodname.out
Normal file
59
libjava/testsuite/libjava.jvmti/getmethodname.out
Normal file
@ -0,0 +1,59 @@
|
||||
JVMTI GetMethodName tests
|
||||
null jmethodID: invalid method ID
|
||||
GetClassMethods: none
|
||||
GetMethodName - name: none
|
||||
GetMethodName - signature: none
|
||||
GetMethodName - generic: none
|
||||
GetMethodName - name: none
|
||||
GetMethodName - signature: none
|
||||
GetMethodName - generic: none
|
||||
GetMethodName - name: none
|
||||
GetMethodName - signature: none
|
||||
GetMethodName - generic: none
|
||||
GetMethodName - name: none
|
||||
GetMethodName - signature: none
|
||||
GetMethodName - generic: none
|
||||
GetMethodName - name: none
|
||||
GetMethodName - signature: none
|
||||
GetMethodName - generic: none
|
||||
GetMethodName - name: none
|
||||
GetMethodName - signature: none
|
||||
GetMethodName - generic: none
|
||||
GetMethodName - name: none
|
||||
GetMethodName - signature: none
|
||||
GetMethodName - generic: none
|
||||
GetMethodName - name: none
|
||||
GetMethodName - signature: none
|
||||
GetMethodName - generic: none
|
||||
name=clone, signature=()Ljava.lang.Object;, generic=null
|
||||
names match
|
||||
signatures match
|
||||
generic not yet
|
||||
name=equals, signature=(Ljava.lang.Object;)Z, generic=null
|
||||
names match
|
||||
signatures match
|
||||
generic not yet
|
||||
name=finalize, signature=()V, generic=null
|
||||
names match
|
||||
signatures match
|
||||
generic not yet
|
||||
name=getClass, signature=()Ljava.lang.Class;, generic=null
|
||||
names match
|
||||
signatures match
|
||||
generic not yet
|
||||
name=hashCode, signature=()I, generic=null
|
||||
names match
|
||||
signatures match
|
||||
generic not yet
|
||||
name=notify, signature=()V, generic=null
|
||||
names match
|
||||
signatures match
|
||||
generic not yet
|
||||
name=notifyAll, signature=()V, generic=null
|
||||
names match
|
||||
signatures match
|
||||
generic not yet
|
||||
name=toString, signature=()Ljava.lang.String;, generic=null
|
||||
names match
|
||||
signatures match
|
||||
generic not yet
|
116
libjava/testsuite/libjava.jvmti/natgetmethodname.cc
Normal file
116
libjava/testsuite/libjava.jvmti/natgetmethodname.cc
Normal file
@ -0,0 +1,116 @@
|
||||
#include <gcj/cni.h>
|
||||
|
||||
#include <jvm.h>
|
||||
#include <jvmti.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <java/lang/Object.h>
|
||||
|
||||
#include "getmethodname.h"
|
||||
|
||||
static void
|
||||
print_error (jvmtiEnv *env, const char *msg, jvmtiError err)
|
||||
{
|
||||
char *error_msg;
|
||||
env->GetErrorName (err, &error_msg);
|
||||
printf ("%s: %s\n", msg, error_msg);
|
||||
env->Deallocate (reinterpret_cast<unsigned char *> (error_msg));
|
||||
}
|
||||
|
||||
#define NUM_METHODS 8
|
||||
static const char *function_names[] = { "clone",
|
||||
"equals",
|
||||
"finalize",
|
||||
"getClass",
|
||||
"hashCode",
|
||||
"notify",
|
||||
"notifyAll",
|
||||
"toString" };
|
||||
static int
|
||||
function_index (const char *name)
|
||||
{
|
||||
for (int i = 0; i < NUM_METHODS; ++i)
|
||||
{
|
||||
if (strcmp (function_names[i], name) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
getmethodname::do_getmethodname_tests ()
|
||||
{
|
||||
jvmtiEnv *env;
|
||||
JavaVM *vm = _Jv_GetJavaVM ();
|
||||
vm->GetEnv (reinterpret_cast<void **> (&env), JVMTI_VERSION_1_0);
|
||||
|
||||
jvmtiError err;
|
||||
err = env->GetMethodName (reinterpret_cast<jmethodID> (NULL),
|
||||
reinterpret_cast<char **> (NULL),
|
||||
reinterpret_cast<char **> (NULL),
|
||||
reinterpret_cast<char **> (NULL));
|
||||
print_error (env, "null jmethodID", err);
|
||||
|
||||
jint count;
|
||||
jmethodID *methods;
|
||||
err = env->GetClassMethods (&java::lang::Object::class$, &count, &methods);
|
||||
print_error (env, "GetClassMethods", err);
|
||||
|
||||
char *names[NUM_METHODS], *solo_names[NUM_METHODS];
|
||||
char *signatures[NUM_METHODS], *solo_signatures[NUM_METHODS];
|
||||
char *generics[NUM_METHODS], *solo_generics[NUM_METHODS];
|
||||
|
||||
for (jint i = 0; i < count; ++i)
|
||||
{
|
||||
char *name, *n;
|
||||
char *signature, *s;
|
||||
char *generic, *g;
|
||||
err = env->GetMethodName (methods[i], &name, &signature, &generic);
|
||||
|
||||
int idx = -1;
|
||||
if (err != JVMTI_ERROR_NONE)
|
||||
{
|
||||
print_error (env, "GetMethodName - all fields", err);
|
||||
continue;
|
||||
}
|
||||
|
||||
idx = function_index (name);
|
||||
if (idx == -1)
|
||||
continue;
|
||||
|
||||
names[idx] = name;
|
||||
signatures[idx] = signature;
|
||||
generics[idx] = generic;
|
||||
|
||||
err = env->GetMethodName (methods[i], &n, NULL, NULL);
|
||||
print_error (env, "GetMethodName - name", err);
|
||||
solo_names[idx] = n;
|
||||
|
||||
err = env->GetMethodName (methods[i], NULL, &s, NULL);
|
||||
print_error (env, "GetMethodName - signature", err);
|
||||
solo_signatures[idx] = s;
|
||||
|
||||
err = env->GetMethodName (methods[i], NULL, NULL, &g);
|
||||
print_error (env, "GetMethodName - generic", err);
|
||||
solo_generics[idx] = g;
|
||||
}
|
||||
|
||||
#define WRAP(X) ((X) == NULL ? "null" : (X))
|
||||
#define MATCH(X,Y) (strcmp ((X),(Y)) == 0 ? "match" : "do not match")
|
||||
for (int i = 0; i < NUM_METHODS; ++i)
|
||||
{
|
||||
printf ("name=%s, signature=%s, generic=%s\n",
|
||||
WRAP (names[i]), WRAP (signatures[i]), WRAP (generics[i]));
|
||||
printf ("names %s\n", MATCH (solo_names[i], names[i]));
|
||||
printf ("signatures %s\n", MATCH (solo_signatures[i], signatures[i]));
|
||||
printf ("generic %s\n", "not yet");
|
||||
|
||||
env->Deallocate (reinterpret_cast<unsigned char *> (names[i]));
|
||||
env->Deallocate (reinterpret_cast<unsigned char *> (solo_names[i]));
|
||||
env->Deallocate (reinterpret_cast<unsigned char *> (signatures[i]));
|
||||
env->Deallocate (reinterpret_cast<unsigned char *> (solo_signatures[i]));
|
||||
env->Deallocate (reinterpret_cast<unsigned char *> (generics[i]));
|
||||
env->Deallocate (reinterpret_cast<unsigned char *> (solo_generics[i]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user