| 1 |
756 |
jeremybenn |
// natFrame.cc -- native support for VMFrame.java
|
| 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 <jvm.h>
|
| 14 |
|
|
#include <jvmti.h>
|
| 15 |
|
|
#include "jvmti-int.h"
|
| 16 |
|
|
|
| 17 |
|
|
#include <java-interp.h>
|
| 18 |
|
|
|
| 19 |
|
|
#include <gnu/classpath/jdwp/VMFrame.h>
|
| 20 |
|
|
#include <gnu/classpath/jdwp/VMVirtualMachine.h>
|
| 21 |
|
|
#include <gnu/classpath/jdwp/exception/InvalidFrameException.h>
|
| 22 |
|
|
#include <gnu/classpath/jdwp/exception/InvalidSlotException.h>
|
| 23 |
|
|
#include <gnu/classpath/jdwp/exception/InvalidThreadException.h>
|
| 24 |
|
|
#include <gnu/classpath/jdwp/exception/JdwpInternalErrorException.h>
|
| 25 |
|
|
#include <gnu/classpath/jdwp/exception/TypeMismatchException.h>
|
| 26 |
|
|
#include <gnu/classpath/jdwp/util/NullObject.h>
|
| 27 |
|
|
#include <gnu/classpath/jdwp/value/ArrayValue.h>
|
| 28 |
|
|
#include <gnu/classpath/jdwp/value/ByteValue.h>
|
| 29 |
|
|
#include <gnu/classpath/jdwp/value/BooleanValue.h>
|
| 30 |
|
|
#include <gnu/classpath/jdwp/value/CharValue.h>
|
| 31 |
|
|
#include <gnu/classpath/jdwp/value/DoubleValue.h>
|
| 32 |
|
|
#include <gnu/classpath/jdwp/value/FloatValue.h>
|
| 33 |
|
|
#include <gnu/classpath/jdwp/value/IntValue.h>
|
| 34 |
|
|
#include <gnu/classpath/jdwp/value/LongValue.h>
|
| 35 |
|
|
#include <gnu/classpath/jdwp/value/ObjectValue.h>
|
| 36 |
|
|
#include <gnu/classpath/jdwp/value/ShortValue.h>
|
| 37 |
|
|
#include <gnu/classpath/jdwp/value/Value.h>
|
| 38 |
|
|
#include <gnu/classpath/jdwp/value/VoidValue.h>
|
| 39 |
|
|
|
| 40 |
|
|
using namespace java::lang;
|
| 41 |
|
|
using namespace gnu::classpath::jdwp;
|
| 42 |
|
|
using namespace gnu::classpath::jdwp::exception;
|
| 43 |
|
|
|
| 44 |
|
|
|
| 45 |
|
|
// All the jvmti GetLocalXX and SetLocalXX functions return the same potential
|
| 46 |
|
|
// errors, so this function handles them all and throws the appropriate JDWP
|
| 47 |
|
|
// exception.
|
| 48 |
|
|
static void
|
| 49 |
|
|
checkJVMTIError (jvmtiEnv *env, jthread thread, jvmtiError jerr, jint slot,
|
| 50 |
|
|
jbyte sig)
|
| 51 |
|
|
{
|
| 52 |
|
|
if (jerr != JVMTI_ERROR_NONE)
|
| 53 |
|
|
{
|
| 54 |
|
|
char *error;
|
| 55 |
|
|
env->GetErrorName (jerr, &error);
|
| 56 |
|
|
String *msg = reinterpret_cast<String *> (JvNewStringUTF (error));
|
| 57 |
|
|
env->Deallocate ((unsigned char *) error);
|
| 58 |
|
|
|
| 59 |
|
|
if (jerr == JVMTI_ERROR_INVALID_THREAD)
|
| 60 |
|
|
throw new InvalidThreadException ((jlong) thread);
|
| 61 |
|
|
else if (jerr == JVMTI_ERROR_NO_MORE_FRAMES)
|
| 62 |
|
|
throw new InvalidFrameException (msg);
|
| 63 |
|
|
else if (jerr == JVMTI_ERROR_INVALID_SLOT)
|
| 64 |
|
|
throw new InvalidSlotException (slot);
|
| 65 |
|
|
else if (jerr == JVMTI_ERROR_TYPE_MISMATCH)
|
| 66 |
|
|
throw new TypeMismatchException (sig);
|
| 67 |
|
|
else
|
| 68 |
|
|
throw new JdwpInternalErrorException (msg);
|
| 69 |
|
|
}
|
| 70 |
|
|
}
|
| 71 |
|
|
|
| 72 |
|
|
|
| 73 |
|
|
static jobject
|
| 74 |
|
|
getObjectJVMTI (jvmtiEnv *env, jthread thread, jint slot, jint depth, jbyte sig)
|
| 75 |
|
|
{
|
| 76 |
|
|
jobject value;
|
| 77 |
|
|
jvmtiError jerr = env->GetLocalObject (thread, depth, slot, &value);
|
| 78 |
|
|
|
| 79 |
|
|
checkJVMTIError (env, thread, jerr, slot, sig);
|
| 80 |
|
|
|
| 81 |
|
|
return value;
|
| 82 |
|
|
}
|
| 83 |
|
|
|
| 84 |
|
|
static void
|
| 85 |
|
|
setObjectJVMTI (jvmtiEnv *env, jthread thread, jint slot, jint depth,
|
| 86 |
|
|
jbyte sig, jobject value)
|
| 87 |
|
|
{
|
| 88 |
|
|
if (value->getClass ()->isAssignableFrom (&util::NullObject::class$))
|
| 89 |
|
|
value = NULL;
|
| 90 |
|
|
|
| 91 |
|
|
jvmtiError jerr = env->SetLocalObject (thread, depth, slot, value);
|
| 92 |
|
|
|
| 93 |
|
|
checkJVMTIError (env, thread, jerr, slot, sig);
|
| 94 |
|
|
}
|
| 95 |
|
|
|
| 96 |
|
|
static jint
|
| 97 |
|
|
getIntJVMTI (jvmtiEnv *env, jthread thread, jint slot, jint depth, jbyte sig)
|
| 98 |
|
|
{
|
| 99 |
|
|
jint value;
|
| 100 |
|
|
jvmtiError jerr = env->GetLocalInt (thread, depth, slot, &value);
|
| 101 |
|
|
|
| 102 |
|
|
checkJVMTIError (env, thread, jerr, slot, sig);
|
| 103 |
|
|
return value;
|
| 104 |
|
|
}
|
| 105 |
|
|
|
| 106 |
|
|
static void
|
| 107 |
|
|
setIntJVMTI (jvmtiEnv *env, jthread thread, jint slot, jint depth, jbyte sig,
|
| 108 |
|
|
jint value)
|
| 109 |
|
|
{
|
| 110 |
|
|
jvmtiError jerr = env->SetLocalInt (thread, depth, slot, value);
|
| 111 |
|
|
|
| 112 |
|
|
checkJVMTIError (env, thread, jerr, slot, sig);
|
| 113 |
|
|
}
|
| 114 |
|
|
|
| 115 |
|
|
static jlong
|
| 116 |
|
|
getLongJVMTI (jvmtiEnv *env, jthread thread, jint slot, jint depth, jbyte sig)
|
| 117 |
|
|
{
|
| 118 |
|
|
jlong value;
|
| 119 |
|
|
jvmtiError jerr = env->GetLocalLong (thread, depth, slot, &value);
|
| 120 |
|
|
|
| 121 |
|
|
checkJVMTIError (env, thread, jerr, slot, sig);
|
| 122 |
|
|
|
| 123 |
|
|
return value;
|
| 124 |
|
|
}
|
| 125 |
|
|
|
| 126 |
|
|
static void
|
| 127 |
|
|
setLongJVMTI (jvmtiEnv *env, jthread thread, jint slot, jint depth, jbyte sig,
|
| 128 |
|
|
jlong value)
|
| 129 |
|
|
{
|
| 130 |
|
|
jvmtiError jerr = env->SetLocalLong (thread, depth, slot, value);
|
| 131 |
|
|
|
| 132 |
|
|
checkJVMTIError (env, thread, jerr, slot, sig);
|
| 133 |
|
|
}
|
| 134 |
|
|
|
| 135 |
|
|
static jfloat
|
| 136 |
|
|
getFloatJVMTI (jvmtiEnv *env, jthread thread, jint slot, jint depth, jbyte sig)
|
| 137 |
|
|
{
|
| 138 |
|
|
jfloat value;
|
| 139 |
|
|
jvmtiError jerr = env->GetLocalFloat (thread, depth, slot, &value);
|
| 140 |
|
|
|
| 141 |
|
|
checkJVMTIError (env, thread, jerr, slot, sig);
|
| 142 |
|
|
|
| 143 |
|
|
return value;
|
| 144 |
|
|
}
|
| 145 |
|
|
|
| 146 |
|
|
static void
|
| 147 |
|
|
setFloatJVMTI (jvmtiEnv *env, jthread thread, jint slot, jint depth, jbyte sig,
|
| 148 |
|
|
jfloat value)
|
| 149 |
|
|
{
|
| 150 |
|
|
jvmtiError jerr = env->SetLocalFloat (thread, depth, slot, value);
|
| 151 |
|
|
|
| 152 |
|
|
checkJVMTIError (env, thread, jerr, slot, sig);
|
| 153 |
|
|
}
|
| 154 |
|
|
|
| 155 |
|
|
static jdouble
|
| 156 |
|
|
getDoubleJVMTI (jvmtiEnv *env, jthread thread, jint slot, jint depth,
|
| 157 |
|
|
jbyte sig)
|
| 158 |
|
|
{
|
| 159 |
|
|
jdouble value;
|
| 160 |
|
|
jvmtiError jerr = env->GetLocalDouble (thread, depth, slot, &value);
|
| 161 |
|
|
|
| 162 |
|
|
checkJVMTIError (env, thread, jerr, slot, sig);
|
| 163 |
|
|
|
| 164 |
|
|
return value;
|
| 165 |
|
|
}
|
| 166 |
|
|
|
| 167 |
|
|
static void
|
| 168 |
|
|
setDoubleJVMTI (jvmtiEnv *env, jthread thread, jint slot, jint depth,
|
| 169 |
|
|
jbyte sig, jdouble value)
|
| 170 |
|
|
{
|
| 171 |
|
|
jvmtiError jerr = env->SetLocalDouble (thread, depth, slot, value);
|
| 172 |
|
|
|
| 173 |
|
|
checkJVMTIError (env, thread, jerr, slot, sig);
|
| 174 |
|
|
}
|
| 175 |
|
|
|
| 176 |
|
|
// This is necessary since JVMTI requires a stack depth as a parameter in all
|
| 177 |
|
|
// its local variable functions. Since JDWP needs frameids, we have to run
|
| 178 |
|
|
// through the call stack to translate these ids into the parameters JVMTI
|
| 179 |
|
|
// wants.
|
| 180 |
|
|
static jint
|
| 181 |
|
|
getFrameDepth (_Jv_Frame *frame)
|
| 182 |
|
|
{
|
| 183 |
|
|
jint depth = 0;
|
| 184 |
|
|
_Jv_Frame *top_frame = (_Jv_Frame *) frame->thread->frame;
|
| 185 |
|
|
jint num_frames = VMVirtualMachine::getFrameCount (frame->thread);
|
| 186 |
|
|
|
| 187 |
|
|
while (frame != top_frame)
|
| 188 |
|
|
{
|
| 189 |
|
|
top_frame = top_frame->next;
|
| 190 |
|
|
depth++;
|
| 191 |
|
|
|
| 192 |
|
|
if (depth >= num_frames || top_frame == NULL)
|
| 193 |
|
|
throw new InvalidFrameException ((jlong) frame);
|
| 194 |
|
|
}
|
| 195 |
|
|
|
| 196 |
|
|
return depth;
|
| 197 |
|
|
}
|
| 198 |
|
|
|
| 199 |
|
|
using namespace gnu::classpath::jdwp::value;
|
| 200 |
|
|
|
| 201 |
|
|
Value *
|
| 202 |
|
|
gnu::classpath::jdwp::VMFrame::getValue (jint slot, jbyte sig)
|
| 203 |
|
|
{
|
| 204 |
|
|
_Jv_Frame *frame = reinterpret_cast<_Jv_Frame *> (id);
|
| 205 |
|
|
jint depth = getFrameDepth (frame);
|
| 206 |
|
|
jthread thread = reinterpret_cast<jthread> (frame->thread);
|
| 207 |
|
|
jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
|
| 208 |
|
|
|
| 209 |
|
|
Value *value = NULL;
|
| 210 |
|
|
|
| 211 |
|
|
switch (sig)
|
| 212 |
|
|
{
|
| 213 |
|
|
case 'B':
|
| 214 |
|
|
value = new ByteValue ((jbyte) getIntJVMTI (env, thread, slot, depth,
|
| 215 |
|
|
sig));
|
| 216 |
|
|
break;
|
| 217 |
|
|
case 'Z':
|
| 218 |
|
|
value = new BooleanValue ((jboolean) getIntJVMTI (env, thread, slot,
|
| 219 |
|
|
depth, sig));
|
| 220 |
|
|
break;
|
| 221 |
|
|
case 'C':
|
| 222 |
|
|
value = new CharValue ((jchar) getIntJVMTI (env, thread, slot, depth,
|
| 223 |
|
|
sig));
|
| 224 |
|
|
break;
|
| 225 |
|
|
case 'S':
|
| 226 |
|
|
value = new ShortValue ((jshort) getIntJVMTI (env, thread, slot, depth,
|
| 227 |
|
|
sig));
|
| 228 |
|
|
break;
|
| 229 |
|
|
case 'I':
|
| 230 |
|
|
value = new IntValue (getIntJVMTI (env, thread, slot, depth, sig));
|
| 231 |
|
|
break;
|
| 232 |
|
|
case 'J':
|
| 233 |
|
|
value = new LongValue (getLongJVMTI (env, thread, slot, depth, sig));
|
| 234 |
|
|
break;
|
| 235 |
|
|
case 'F':
|
| 236 |
|
|
value = new FloatValue (getFloatJVMTI (env, thread, slot, depth, sig));
|
| 237 |
|
|
break;
|
| 238 |
|
|
case 'D':
|
| 239 |
|
|
value = new DoubleValue (getDoubleJVMTI (env, thread, slot, depth, sig));
|
| 240 |
|
|
break;
|
| 241 |
|
|
case 'V':
|
| 242 |
|
|
value = new VoidValue ();
|
| 243 |
|
|
break;
|
| 244 |
|
|
case '[':
|
| 245 |
|
|
{
|
| 246 |
|
|
Object *obj = getObjectJVMTI (env, thread, slot, depth, sig);
|
| 247 |
|
|
if (obj == NULL)
|
| 248 |
|
|
obj = new util::NullObject ();
|
| 249 |
|
|
value = new ArrayValue (obj);
|
| 250 |
|
|
break;
|
| 251 |
|
|
}
|
| 252 |
|
|
default:
|
| 253 |
|
|
Object *obj = getObjectJVMTI (env, thread, slot, depth, sig);
|
| 254 |
|
|
if (obj == NULL)
|
| 255 |
|
|
obj = new util::NullObject ();
|
| 256 |
|
|
value = new ObjectValue (obj);
|
| 257 |
|
|
break;
|
| 258 |
|
|
}
|
| 259 |
|
|
|
| 260 |
|
|
return value;
|
| 261 |
|
|
}
|
| 262 |
|
|
|
| 263 |
|
|
void
|
| 264 |
|
|
gnu::classpath::jdwp::VMFrame::setValue (jint slot, Value* value)
|
| 265 |
|
|
{
|
| 266 |
|
|
jbyte sig = value->getTag ();
|
| 267 |
|
|
|
| 268 |
|
|
_Jv_Frame *frame = reinterpret_cast<_Jv_Frame *> (id);
|
| 269 |
|
|
jint depth = getFrameDepth (frame);
|
| 270 |
|
|
jthread thread = reinterpret_cast<jthread> (frame->thread);
|
| 271 |
|
|
jvmtiEnv *env = _Jv_GetJDWP_JVMTIEnv ();
|
| 272 |
|
|
|
| 273 |
|
|
switch (sig)
|
| 274 |
|
|
{
|
| 275 |
|
|
case 'B':
|
| 276 |
|
|
{
|
| 277 |
|
|
ByteValue *val = reinterpret_cast<ByteValue *> (value);
|
| 278 |
|
|
setIntJVMTI (env, thread, slot, depth, sig, (jint) val->getValue ());
|
| 279 |
|
|
break;
|
| 280 |
|
|
}
|
| 281 |
|
|
case 'Z':
|
| 282 |
|
|
{
|
| 283 |
|
|
BooleanValue *val = reinterpret_cast<BooleanValue *> (value);
|
| 284 |
|
|
setIntJVMTI (env, thread, slot, depth, sig, (jint) val->getValue ());
|
| 285 |
|
|
break;
|
| 286 |
|
|
}
|
| 287 |
|
|
case 'C':
|
| 288 |
|
|
{
|
| 289 |
|
|
CharValue *val = reinterpret_cast<CharValue *> (value);
|
| 290 |
|
|
setIntJVMTI (env, thread, slot, depth, sig, (jint) val->getValue ());
|
| 291 |
|
|
break;
|
| 292 |
|
|
}
|
| 293 |
|
|
case 'S':
|
| 294 |
|
|
{
|
| 295 |
|
|
ShortValue *val = reinterpret_cast<ShortValue *> (value);
|
| 296 |
|
|
setIntJVMTI (env, thread, slot, depth, sig, (jint) val->getValue ());
|
| 297 |
|
|
break;
|
| 298 |
|
|
}
|
| 299 |
|
|
case 'I':
|
| 300 |
|
|
{
|
| 301 |
|
|
IntValue *val = reinterpret_cast<IntValue *> (value);
|
| 302 |
|
|
setIntJVMTI (env, thread, slot, depth, sig, val->getValue ());
|
| 303 |
|
|
break;
|
| 304 |
|
|
}
|
| 305 |
|
|
case 'J':
|
| 306 |
|
|
{
|
| 307 |
|
|
LongValue *val = reinterpret_cast<LongValue *> (value);
|
| 308 |
|
|
setLongJVMTI (env, thread, slot, depth, sig, val->getValue ());
|
| 309 |
|
|
break;
|
| 310 |
|
|
}
|
| 311 |
|
|
case 'F':
|
| 312 |
|
|
{
|
| 313 |
|
|
FloatValue *val = reinterpret_cast<FloatValue *> (value);
|
| 314 |
|
|
setFloatJVMTI (env, thread, slot, depth, sig, val->getValue ());
|
| 315 |
|
|
break;
|
| 316 |
|
|
}
|
| 317 |
|
|
case 'D':
|
| 318 |
|
|
{
|
| 319 |
|
|
DoubleValue *val = reinterpret_cast<DoubleValue *> (value);
|
| 320 |
|
|
setDoubleJVMTI (env, thread, slot, depth, sig, val->getValue ());
|
| 321 |
|
|
break;
|
| 322 |
|
|
}
|
| 323 |
|
|
case 'V':
|
| 324 |
|
|
break;
|
| 325 |
|
|
case '[':
|
| 326 |
|
|
{
|
| 327 |
|
|
ArrayValue *val = reinterpret_cast<ArrayValue *> (value);
|
| 328 |
|
|
setObjectJVMTI (env, thread, slot, depth, sig, val->getObject ());
|
| 329 |
|
|
break;
|
| 330 |
|
|
}
|
| 331 |
|
|
default:
|
| 332 |
|
|
{
|
| 333 |
|
|
ObjectValue *val = reinterpret_cast<ObjectValue *> (value);
|
| 334 |
|
|
setObjectJVMTI (env, thread, slot, depth, sig, val->getObject());
|
| 335 |
|
|
break;
|
| 336 |
|
|
}
|
| 337 |
|
|
}
|
| 338 |
|
|
}
|