| 1 |
756 |
jeremybenn |
// natVMMethod.cc -- native support for VMMethod
|
| 2 |
|
|
|
| 3 |
|
|
/* Copyright (C) 2006, 2007 Free Software Foundation
|
| 4 |
|
|
|
| 5 |
|
|
This file is part of libgcj.
|
| 6 |
|
|
|
| 7 |
|
|
This software is copyrighted work licensed under the terms of the
|
| 8 |
|
|
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
| 9 |
|
|
details. */
|
| 10 |
|
|
|
| 11 |
|
|
#include <config.h>
|
| 12 |
|
|
#include <gcj/cni.h>
|
| 13 |
|
|
#include <java-interp.h>
|
| 14 |
|
|
#include <jvmti.h>
|
| 15 |
|
|
#include "jvmti-int.h"
|
| 16 |
|
|
|
| 17 |
|
|
#include <java/lang/reflect/Modifier.h>
|
| 18 |
|
|
#include <gnu/classpath/jdwp/VMMethod.h>
|
| 19 |
|
|
#include <gnu/classpath/jdwp/exception/AbsentInformationException.h>
|
| 20 |
|
|
#include <gnu/classpath/jdwp/exception/InvalidMethodException.h>
|
| 21 |
|
|
#include <gnu/classpath/jdwp/exception/JdwpInternalErrorException.h>
|
| 22 |
|
|
#include <gnu/classpath/jdwp/util/LineTable.h>
|
| 23 |
|
|
#include <gnu/classpath/jdwp/util/VariableTable.h>
|
| 24 |
|
|
|
| 25 |
|
|
using namespace java::lang;
|
| 26 |
|
|
|
| 27 |
|
|
#define CHECK_INTERP_CLASS() \
|
| 28 |
|
|
do \
|
| 29 |
|
|
{ \
|
| 30 |
|
|
if (!_Jv_IsInterpretedClass (getDeclaringClass ())) \
|
| 31 |
|
|
{ \
|
| 32 |
|
|
::java::lang::String *msg = JvNewStringLatin1 ("native class"); \
|
| 33 |
|
|
throw new exception::JdwpInternalErrorException (msg); \
|
| 34 |
|
|
} \
|
| 35 |
|
|
} \
|
| 36 |
|
|
while (0)
|
| 37 |
|
|
|
| 38 |
|
|
jstring
|
| 39 |
|
|
gnu::classpath::jdwp::VMMethod::getName ()
|
| 40 |
|
|
{
|
| 41 |
|
|
jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
|
| 42 |
|
|
jmethodID method = reinterpret_cast<jmethodID> (_methodId);
|
| 43 |
|
|
char *name;
|
| 44 |
|
|
env->GetMethodName (method, &name, NULL, NULL);
|
| 45 |
|
|
jstring string = JvNewStringUTF (name);
|
| 46 |
|
|
env->Deallocate (reinterpret_cast<unsigned char *> (name));
|
| 47 |
|
|
return string;
|
| 48 |
|
|
}
|
| 49 |
|
|
|
| 50 |
|
|
jstring
|
| 51 |
|
|
gnu::classpath::jdwp::VMMethod::getSignature ()
|
| 52 |
|
|
{
|
| 53 |
|
|
jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
|
| 54 |
|
|
jmethodID method = reinterpret_cast<jmethodID> (_methodId);
|
| 55 |
|
|
char *signature;
|
| 56 |
|
|
env->GetMethodName (method, NULL, &signature, NULL);
|
| 57 |
|
|
jstring string = JvNewStringUTF (signature);
|
| 58 |
|
|
env->Deallocate (reinterpret_cast<unsigned char *> (signature));
|
| 59 |
|
|
return string;
|
| 60 |
|
|
}
|
| 61 |
|
|
|
| 62 |
|
|
jint
|
| 63 |
|
|
gnu::classpath::jdwp::VMMethod::getModifiers ()
|
| 64 |
|
|
{
|
| 65 |
|
|
jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
|
| 66 |
|
|
jmethodID method = reinterpret_cast<jmethodID> (_methodId);
|
| 67 |
|
|
jint flags;
|
| 68 |
|
|
env->GetMethodModifiers (method, &flags);
|
| 69 |
|
|
|
| 70 |
|
|
// If this class is compiled, as far as JDWP is concerned, its methods are
|
| 71 |
|
|
// native. This will set the native flag for these methods.
|
| 72 |
|
|
if (!_Jv_IsInterpretedClass (getDeclaringClass ()))
|
| 73 |
|
|
flags |= ::java::lang::reflect::Modifier::NATIVE;
|
| 74 |
|
|
|
| 75 |
|
|
return flags;
|
| 76 |
|
|
}
|
| 77 |
|
|
|
| 78 |
|
|
gnu::classpath::jdwp::util::LineTable *
|
| 79 |
|
|
gnu::classpath::jdwp::VMMethod::getLineTable ()
|
| 80 |
|
|
{
|
| 81 |
|
|
CHECK_INTERP_CLASS ();
|
| 82 |
|
|
|
| 83 |
|
|
jmethodID desired_method = reinterpret_cast<jmethodID> (_methodId);
|
| 84 |
|
|
|
| 85 |
|
|
_Jv_MethodBase *theMethod
|
| 86 |
|
|
= _Jv_FindInterpreterMethod (getDeclaringClass (), desired_method);
|
| 87 |
|
|
|
| 88 |
|
|
if (theMethod == NULL)
|
| 89 |
|
|
{
|
| 90 |
|
|
// this should not happen
|
| 91 |
|
|
::java::lang::String *msg
|
| 92 |
|
|
= JvNewStringLatin1 ("could not find method in class");
|
| 93 |
|
|
throw new exception::JdwpInternalErrorException (msg);
|
| 94 |
|
|
}
|
| 95 |
|
|
|
| 96 |
|
|
if (::java::lang::reflect::Modifier::isNative (desired_method->accflags))
|
| 97 |
|
|
{
|
| 98 |
|
|
jintArray lines = JvNewIntArray (0);
|
| 99 |
|
|
jlongArray indices = JvNewLongArray (0);
|
| 100 |
|
|
return new util::LineTable (-1, -1, lines, indices);
|
| 101 |
|
|
}
|
| 102 |
|
|
|
| 103 |
|
|
// get the linetable
|
| 104 |
|
|
_Jv_InterpMethod *imeth = reinterpret_cast<_Jv_InterpMethod *> (theMethod);
|
| 105 |
|
|
jlong start;
|
| 106 |
|
|
jlong end;
|
| 107 |
|
|
jintArray lines;
|
| 108 |
|
|
jlongArray indices;
|
| 109 |
|
|
imeth->get_line_table (start, end, lines, indices);
|
| 110 |
|
|
return new util::LineTable (start, end, lines, indices);
|
| 111 |
|
|
}
|
| 112 |
|
|
|
| 113 |
|
|
|
| 114 |
|
|
gnu::classpath::jdwp::util::VariableTable*
|
| 115 |
|
|
gnu::classpath::jdwp::VMMethod::getVariableTable ()
|
| 116 |
|
|
{
|
| 117 |
|
|
using namespace gnu::classpath::jdwp::util;
|
| 118 |
|
|
|
| 119 |
|
|
jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
|
| 120 |
|
|
|
| 121 |
|
|
CHECK_INTERP_CLASS ();
|
| 122 |
|
|
|
| 123 |
|
|
jmethodID meth = reinterpret_cast<jmethodID> (_methodId);
|
| 124 |
|
|
jvmtiLocalVariableEntry *var_table;
|
| 125 |
|
|
jint num_slots, args_len;
|
| 126 |
|
|
|
| 127 |
|
|
jvmtiError jerr = env->GetLocalVariableTable (meth, &num_slots, &var_table);
|
| 128 |
|
|
|
| 129 |
|
|
if (jerr != JVMTI_ERROR_NONE)
|
| 130 |
|
|
goto error;
|
| 131 |
|
|
|
| 132 |
|
|
jerr = env->GetArgumentsSize (meth, &args_len);
|
| 133 |
|
|
|
| 134 |
|
|
if (jerr != JVMTI_ERROR_NONE)
|
| 135 |
|
|
{
|
| 136 |
|
|
error:
|
| 137 |
|
|
using namespace gnu::classpath::jdwp::exception;
|
| 138 |
|
|
char *error;
|
| 139 |
|
|
env->GetErrorName (jerr, &error);
|
| 140 |
|
|
String *msg = JvNewStringUTF (error);
|
| 141 |
|
|
env->Deallocate (reinterpret_cast<unsigned char *> (error));
|
| 142 |
|
|
|
| 143 |
|
|
if (jerr == JVMTI_ERROR_NATIVE_METHOD)
|
| 144 |
|
|
throw new AbsentInformationException (msg);
|
| 145 |
|
|
else if (jerr == JVMTI_ERROR_INVALID_METHODID)
|
| 146 |
|
|
throw new InvalidMethodException (_methodId);
|
| 147 |
|
|
else
|
| 148 |
|
|
throw new JdwpInternalErrorException (msg);
|
| 149 |
|
|
}
|
| 150 |
|
|
|
| 151 |
|
|
jlongArray start_pcs = JvNewLongArray (num_slots);
|
| 152 |
|
|
jlong *start_pcs_ptr = elements (start_pcs);
|
| 153 |
|
|
jintArray lengths = JvNewIntArray (num_slots);
|
| 154 |
|
|
jint *lengths_ptr = elements (lengths);
|
| 155 |
|
|
jintArray slots = JvNewIntArray (num_slots);
|
| 156 |
|
|
jint *slots_ptr = elements (slots);
|
| 157 |
|
|
JArray<String *> *names = reinterpret_cast<JArray<String *> *>
|
| 158 |
|
|
(JvNewObjectArray (num_slots,
|
| 159 |
|
|
&String::class$, NULL));
|
| 160 |
|
|
jstring *names_ptr = elements (names);
|
| 161 |
|
|
JArray<String *> *signatures = reinterpret_cast<JArray<String *> *>
|
| 162 |
|
|
(JvNewObjectArray (num_slots,
|
| 163 |
|
|
&String::class$, NULL));
|
| 164 |
|
|
jstring *signatures_ptr = elements (signatures);
|
| 165 |
|
|
|
| 166 |
|
|
// Get the information out of the JVMTI strucutre and Deallocate the strings.
|
| 167 |
|
|
for (int i = 0; i < num_slots; i++)
|
| 168 |
|
|
{
|
| 169 |
|
|
start_pcs_ptr[i] = var_table[i].start_location;
|
| 170 |
|
|
lengths_ptr[i] = var_table[i].length;
|
| 171 |
|
|
slots_ptr[i] = var_table[i].slot;
|
| 172 |
|
|
names_ptr[i] = JvNewStringUTF (var_table[i].name);
|
| 173 |
|
|
env->Deallocate (reinterpret_cast<unsigned char *>
|
| 174 |
|
|
(var_table[i].name));
|
| 175 |
|
|
signatures_ptr[i] = JvNewStringUTF (var_table[i].signature);
|
| 176 |
|
|
env->Deallocate (reinterpret_cast<unsigned char *>
|
| 177 |
|
|
(var_table[i].signature));
|
| 178 |
|
|
env->Deallocate (reinterpret_cast<unsigned char *>
|
| 179 |
|
|
(var_table[i].generic_signature));
|
| 180 |
|
|
}
|
| 181 |
|
|
|
| 182 |
|
|
// Now Deallocate the table since it's strings have already been freed.
|
| 183 |
|
|
env->Deallocate (reinterpret_cast<unsigned char *> (var_table));
|
| 184 |
|
|
|
| 185 |
|
|
// Create the new JDWP VariableTable to return with the now filled arrays.
|
| 186 |
|
|
VariableTable* jdwp_vtable = new VariableTable (args_len, num_slots,
|
| 187 |
|
|
start_pcs, names, signatures,
|
| 188 |
|
|
lengths, slots);
|
| 189 |
|
|
|
| 190 |
|
|
return jdwp_vtable;
|
| 191 |
|
|
}
|