1 // natVMMethod.cc -- native support for VMMethod
3 /* Copyright (C) 2006, 2007 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
13 #include <java-interp.h>
15 #include "jvmti-int.h"
17 #include <gnu/classpath/jdwp/VMMethod.h>
18 #include <gnu/classpath/jdwp/exception/AbsentInformationException.h>
19 #include <gnu/classpath/jdwp/exception/InvalidMethodException.h>
20 #include <gnu/classpath/jdwp/exception/JdwpInternalErrorException.h>
21 #include <gnu/classpath/jdwp/util/LineTable.h>
22 #include <gnu/classpath/jdwp/util/VariableTable.h>
24 using namespace java::lang;
26 #define CHECK_INTERP_CLASS() \
29 if (!_Jv_IsInterpretedClass (getDeclaringClass ())) \
31 ::java::lang::String *msg = JvNewStringLatin1 ("native class"); \
32 throw new exception::JdwpInternalErrorException (msg); \
38 gnu::classpath::jdwp::VMMethod::getName ()
40 jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
41 jmethodID method = reinterpret_cast<jmethodID> (_methodId);
43 env->GetMethodName (method, &name, NULL, NULL);
44 jstring string = JvNewStringUTF (name);
45 env->Deallocate (reinterpret_cast<unsigned char *> (name));
50 gnu::classpath::jdwp::VMMethod::getSignature ()
52 jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
53 jmethodID method = reinterpret_cast<jmethodID> (_methodId);
55 env->GetMethodName (method, NULL, &signature, NULL);
56 jstring string = JvNewStringUTF (signature);
57 env->Deallocate (reinterpret_cast<unsigned char *> (signature));
62 gnu::classpath::jdwp::VMMethod::getModifiers ()
64 jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
65 jmethodID method = reinterpret_cast<jmethodID> (_methodId);
67 env->GetMethodModifiers (method, &flags);
71 gnu::classpath::jdwp::util::LineTable *
72 gnu::classpath::jdwp::VMMethod::getLineTable ()
74 CHECK_INTERP_CLASS ();
76 jmethodID desired_method = reinterpret_cast<jmethodID> (_methodId);
78 _Jv_MethodBase *theMethod
79 = _Jv_FindInterpreterMethod (getDeclaringClass (), desired_method);
81 if (theMethod == NULL)
83 // this should not happen
84 ::java::lang::String *msg
85 = JvNewStringLatin1 ("could not find method in class");
86 throw new exception::JdwpInternalErrorException (msg);
89 if (::java::lang::reflect::Modifier::isNative (desired_method->accflags))
91 jintArray lines = JvNewIntArray (0);
92 jlongArray indices = JvNewLongArray (0);
93 return new util::LineTable (-1, -1, lines, indices);
97 _Jv_InterpMethod *imeth = reinterpret_cast<_Jv_InterpMethod *> (theMethod);
102 imeth->get_line_table (start, end, lines, indices);
103 return new util::LineTable (start, end, lines, indices);
107 gnu::classpath::jdwp::util::VariableTable*
108 gnu::classpath::jdwp::VMMethod::getVariableTable ()
110 using namespace gnu::classpath::jdwp::util;
112 jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
114 CHECK_INTERP_CLASS ();
116 jmethodID meth = reinterpret_cast<jmethodID> (_methodId);
117 jvmtiLocalVariableEntry *var_table;
118 jint num_slots, args_len;
120 jvmtiError jerr = env->GetLocalVariableTable (meth, &num_slots, &var_table);
122 if (jerr != JVMTI_ERROR_NONE)
125 jerr = env->GetArgumentsSize (meth, &args_len);
127 if (jerr != JVMTI_ERROR_NONE)
130 using namespace gnu::classpath::jdwp::exception;
132 env->GetErrorName (jerr, &error);
133 String *msg = JvNewStringUTF (error);
134 env->Deallocate (reinterpret_cast<unsigned char *> (error));
136 if (jerr == JVMTI_ERROR_NATIVE_METHOD)
137 throw new AbsentInformationException (msg);
138 else if (jerr == JVMTI_ERROR_INVALID_METHODID)
139 throw new InvalidMethodException (_methodId);
141 throw new JdwpInternalErrorException (msg);
144 jlongArray start_pcs = JvNewLongArray (num_slots);
145 jlong *start_pcs_ptr = elements (start_pcs);
146 jintArray lengths = JvNewIntArray (num_slots);
147 jint *lengths_ptr = elements (lengths);
148 jintArray slots = JvNewIntArray (num_slots);
149 jint *slots_ptr = elements (slots);
150 JArray<String *> *names = reinterpret_cast<JArray<String *> *>
151 (JvNewObjectArray (num_slots,
152 &String::class$, NULL));
153 jstring *names_ptr = elements (names);
154 JArray<String *> *signatures = reinterpret_cast<JArray<String *> *>
155 (JvNewObjectArray (num_slots,
156 &String::class$, NULL));
157 jstring *signatures_ptr = elements (signatures);
159 // Get the information out of the JVMTI strucutre and Deallocate the strings.
160 for (int i = 0; i < num_slots; i++)
162 start_pcs_ptr[i] = var_table[i].start_location;
163 lengths_ptr[i] = var_table[i].length;
164 slots_ptr[i] = var_table[i].slot;
165 names_ptr[i] = JvNewStringUTF (var_table[i].name);
166 env->Deallocate (reinterpret_cast<unsigned char *>
167 (var_table[i].name));
168 signatures_ptr[i] = JvNewStringUTF (var_table[i].signature);
169 env->Deallocate (reinterpret_cast<unsigned char *>
170 (var_table[i].signature));
171 env->Deallocate (reinterpret_cast<unsigned char *>
172 (var_table[i].generic_signature));
175 // Now Deallocate the table since it's strings have already been freed.
176 env->Deallocate (reinterpret_cast<unsigned char *> (var_table));
178 // Create the new JDWP VariableTable to return with the now filled arrays.
179 VariableTable* jdwp_vtable = new VariableTable (args_len, num_slots,
180 start_pcs, names, signatures,