|
Added
Link Here
|
| 1 |
/********************************************************************** |
| 2 |
* Copyright (c) 2008 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* $Id$ |
| 8 |
* |
| 9 |
* Contributors: |
| 10 |
* Intel - Initial API and implementation |
| 11 |
**********************************************************************/ |
| 12 |
|
| 13 |
#include <stdlib.h> |
| 14 |
#include <string.h> |
| 15 |
|
| 16 |
#include <map> |
| 17 |
|
| 18 |
#include <assert.h> |
| 19 |
#include "BCIEng.h" |
| 20 |
#include "JClassBuilder.h" |
| 21 |
#include "ModuleJ.h" |
| 22 |
|
| 23 |
#include "JMemStream.h" |
| 24 |
#include "class_inerface_int.h" |
| 25 |
|
| 26 |
|
| 27 |
#include <jni.h> |
| 28 |
|
| 29 |
typedef unsigned long intptr; |
| 30 |
|
| 31 |
static JNIEnv *(*m_get_vm_pointer)(void **); |
| 32 |
|
| 33 |
static jclass m_j_l_class; |
| 34 |
static jclass m_j_l_classloader; |
| 35 |
static jmethodID m_j_l_class_getName; /*()Ljava/lang/String;*/ |
| 36 |
static jmethodID m_j_l_class_isInterface;/* ()Z */ |
| 37 |
static jmethodID m_j_l_class_getClassLoader; /*()Ljava/lang/ClassLoader;*/ |
| 38 |
static jmethodID m_j_l_classloader_findLoadedClass; /*(Ljava/lang/String;)Ljava/lang/Class;*/ |
| 39 |
static jmethodID m_j_l_classloader_getSystemClassLoader; /*()Ljava/lang/ClassLoader;*/ |
| 40 |
static jobject m_system_classloader; |
| 41 |
/** |
| 42 |
* Define class handler |
| 43 |
*/ |
| 44 |
/*[0xdead0001 - simplefied, 0xdead0002 - instrumented, 0xdead0000 - none]*/ |
| 45 |
#define CLASS_HANDLER_MASK 0xdeadffff |
| 46 |
#define CLASS_HANDLER_SIMPLEFIED 0xdead0001 |
| 47 |
#define CLASS_HANDLER_INSTRUMENTED 0xdead0002 |
| 48 |
#define CLASS_HANDLER_NONE 0xdead0000 |
| 49 |
#define IS_CLASS_INSTRUMENTED(x) (((x)->magic & CLASS_HANDLER_MASK) == CLASS_HANDLER_INSTRUMENTED) |
| 50 |
struct Class{ |
| 51 |
int magic; |
| 52 |
struct { |
| 53 |
class CModuleJ *instrumented_class; |
| 54 |
void *simplefied_class; |
| 55 |
} X; /*XXX: possible union here will be more applieble */ |
| 56 |
int loaded; |
| 57 |
const char *class_name; /*used if loaded = 0*/ |
| 58 |
struct Class *super_class; |
| 59 |
}; |
| 60 |
|
| 61 |
typedef std::map<std::string,class_handler> name2ch_t; |
| 62 |
static name2ch_t m_name2ch; |
| 63 |
|
| 64 |
#define MEHTOD_HANDLER_MASK 0xbabeffff |
| 65 |
#define METHOD_HANDLER_SELF 0xbabe0001 |
| 66 |
#define METHOD_HANDLER_EXT 0xbabe0002 |
| 67 |
#define METHOD_HANDLER_NONE 0xbabe0000 |
| 68 |
struct Method { |
| 69 |
int magic; |
| 70 |
struct { |
| 71 |
class CMethodJ *instrumented_method; |
| 72 |
void *simplefied_method; |
| 73 |
} X; /*XXX: possible union here will be more applieble */ |
| 74 |
class_handler class_owner; |
| 75 |
const char *method_name; /*used for METHOD_HANDLER_EXT only*/ |
| 76 |
const char *method_descriptor; /*used for METHOD_HANDLER_EXT only*/ |
| 77 |
}; |
| 78 |
|
| 79 |
static struct Class *m_j_l_object_ch; |
| 80 |
/** |
| 81 |
* Define field handler |
| 82 |
*/ |
| 83 |
typedef struct Field_ * field_handler; |
| 84 |
|
| 85 |
/** |
| 86 |
* Define method handler |
| 87 |
*/ |
| 88 |
//typedef struct Method_ * method_handler; |
| 89 |
|
| 90 |
/** |
| 91 |
* Define class loader handler |
| 92 |
*/ |
| 93 |
typedef struct ClassLoader_ * classloader_handler; |
| 94 |
|
| 95 |
static int |
| 96 |
create_class_handler(class_handler *pch, int flag, const char *class_name, int loaded, void *dsk) |
| 97 |
{ |
| 98 |
class_handler ch0 = m_name2ch[class_name]; /*for debug*/ |
| 99 |
if (m_name2ch[class_name] != NULL |
| 100 |
&& m_name2ch[class_name]->magic == flag) { |
| 101 |
*pch = m_name2ch[class_name]; |
| 102 |
return (0); |
| 103 |
} |
| 104 |
class_handler ch = (class_handler)malloc(sizeof(struct Class)); |
| 105 |
memset(ch, 0, sizeof(struct Class)); |
| 106 |
assert(ch); |
| 107 |
ch->loaded = loaded; |
| 108 |
if (loaded == 0) { |
| 109 |
ch->class_name = class_name; |
| 110 |
} |
| 111 |
ch->magic = flag; |
| 112 |
switch(flag) { |
| 113 |
case (CLASS_HANDLER_SIMPLEFIED): |
| 114 |
ch->X.simplefied_class = dsk; |
| 115 |
if (loaded == 0) { |
| 116 |
ch->class_name = class_name; |
| 117 |
} |
| 118 |
ch->loaded = loaded; |
| 119 |
break; |
| 120 |
case (CLASS_HANDLER_INSTRUMENTED): |
| 121 |
ch->X.instrumented_class = (CModuleJ *)dsk; |
| 122 |
break; |
| 123 |
default: |
| 124 |
assert(!"shouldn't be here!!!"); |
| 125 |
} |
| 126 |
*pch = ch; |
| 127 |
m_name2ch[class_name] = ch; |
| 128 |
return (0); |
| 129 |
} |
| 130 |
|
| 131 |
extern "C" int |
| 132 |
create_method_handler(method_handler *pmh, class_handler ch, int flag, void *dsk) |
| 133 |
{ |
| 134 |
method_handler mh = (method_handler)malloc(sizeof(struct Method)); |
| 135 |
assert(mh); |
| 136 |
memset(mh, 0, sizeof(struct Method)); |
| 137 |
switch (flag) { |
| 138 |
case METHOD_HANDLER_SELF: |
| 139 |
mh->X.instrumented_method = (class CMethodJ *)dsk; |
| 140 |
break; |
| 141 |
case METHOD_HANDLER_EXT: |
| 142 |
mh->X.simplefied_method = dsk; |
| 143 |
break; |
| 144 |
default: |
| 145 |
assert(!"shouldn't enter here"); |
| 146 |
} |
| 147 |
mh->magic = (IS_CLASS_INSTRUMENTED(ch))?METHOD_HANDLER_SELF:flag; |
| 148 |
mh->class_owner = ch; |
| 149 |
*pmh = mh; |
| 150 |
return (0); |
| 151 |
} |
| 152 |
/** |
| 153 |
* Class interface |
| 154 |
*/ |
| 155 |
|
| 156 |
/** |
| 157 |
* Function returns class major version. |
| 158 |
* @param klass - class handler |
| 159 |
* @return Class name bytes. |
| 160 |
* @note Assertion is raised if klass is equal to null. |
| 161 |
*/ |
| 162 |
extern "C" unsigned short |
| 163 |
class_get_version( class_handler klass ) { |
| 164 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 165 |
return klass->X.instrumented_class->GetClassBuilder().GetMajorVersion(); |
| 166 |
} else { |
| 167 |
assert (!"not implemented yet!"); |
| 168 |
} |
| 169 |
return (0); |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* Function returns class name. |
| 174 |
* @param klass - class handler |
| 175 |
* @return Class name bytes. |
| 176 |
* @note Assertion is raised if klass is equal to null. |
| 177 |
*/ |
| 178 |
extern "C" const char * |
| 179 |
class_get_name( class_handler klass ) |
| 180 |
{ |
| 181 |
JNIEnv *env; |
| 182 |
jstring class_name; |
| 183 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 184 |
return klass->X.instrumented_class->GetName(); |
| 185 |
} |
| 186 |
else { |
| 187 |
if (klass->loaded == 0) { |
| 188 |
return(klass->class_name); |
| 189 |
} |
| 190 |
env = m_get_vm_pointer((void **)&env); |
| 191 |
class_name = (jstring)env->CallObjectMethod((jobject)klass->X.simplefied_class, m_j_l_class_getName); |
| 192 |
if (class_name == NULL) |
| 193 |
return (NULL); |
| 194 |
char *class_name_simple = (char *)env->GetStringUTFChars(class_name, NULL); |
| 195 |
char *ch = strchr(class_name_simple, '.'); |
| 196 |
while (ch != NULL) { |
| 197 |
*ch = '/'; |
| 198 |
ch = strchr(ch, '.'); |
| 199 |
} |
| 200 |
return(class_name_simple); |
| 201 |
|
| 202 |
} |
| 203 |
return (NULL); |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Function returns class loader. |
| 208 |
* @param klass - class handler |
| 209 |
* @return Class class loader handler. |
| 210 |
* @note Assertion is raised if klass is equal to null. |
| 211 |
*/ |
| 212 |
extern "C" classloader_handler |
| 213 |
class_get_class_loader( class_handler klass ) |
| 214 |
{ |
| 215 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 216 |
return (0); |
| 217 |
} else { |
| 218 |
assert(!"simplefied"); |
| 219 |
} |
| 220 |
return (NULL); |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Function returns super class of current class. |
| 225 |
* @param klass - class handler |
| 226 |
* @return Super class of current class. |
| 227 |
* @note Assertion is raised if klass is equal to null. |
| 228 |
*/ |
| 229 |
extern "C" class_handler |
| 230 |
class_get_super_class( class_handler klass ) |
| 231 |
{ |
| 232 |
|
| 233 |
const char *class_name; |
| 234 |
const char *super_class_name = NULL; |
| 235 |
jobject this_class = NULL; |
| 236 |
jobject super_class; |
| 237 |
JNIEnv *env = NULL; |
| 238 |
env = m_get_vm_pointer((void **)&env); |
| 239 |
assert(env); |
| 240 |
int loaded = 1; |
| 241 |
if (klass->loaded == 0 && strcmp(klass->class_name,"java/lang/Object") == 0) return (NULL); |
| 242 |
if (klass->super_class != NULL) return (klass->super_class); |
| 243 |
|
| 244 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 245 |
class_name = klass->X.instrumented_class->GetName(); |
| 246 |
CConstPool* cpool = klass->X.instrumented_class->GetClass().GetConstPool(); |
| 247 |
CCPUtf8Info* utfinfo = cpool->GetClass(klass->X.instrumented_class->GetClass().GetSuperClass()); |
| 248 |
super_class_name = (const char *)utfinfo->GetBytes(); |
| 249 |
assert(super_class_name); |
| 250 |
super_class = (jclass)env->FindClass(super_class_name); |
| 251 |
} |
| 252 |
else { |
| 253 |
if (klass->loaded == 0) { |
| 254 |
assert(klass->class_name); |
| 255 |
this_class = (jclass)env->FindClass(klass->class_name); |
| 256 |
if (this_class == NULL && env->ExceptionCheck()) { |
| 257 |
env->ExceptionDescribe(); |
| 258 |
env->ExceptionClear(); |
| 259 |
//XXX: class wasn't found or loaded |
| 260 |
return (m_j_l_object_ch); |
| 261 |
//return (NULL); |
| 262 |
} |
| 263 |
} |
| 264 |
this_class = this_class?this_class:(jobject)klass->X.simplefied_class; |
| 265 |
super_class = (jobject)env->GetSuperclass((jclass)this_class); |
| 266 |
} |
| 267 |
|
| 268 |
if (super_class == NULL) { |
| 269 |
if (env->ExceptionCheck()) { |
| 270 |
env->ExceptionDescribe(); |
| 271 |
env->ExceptionClear(); |
| 272 |
//XXX: class wasn't found or loaded |
| 273 |
loaded = 0; |
| 274 |
//return (NULL); |
| 275 |
} |
| 276 |
else { |
| 277 |
klass->super_class = m_j_l_object_ch; |
| 278 |
return (m_j_l_object_ch); |
| 279 |
//return (NULL); /*it happends when klass is java.lang.Object*/ |
| 280 |
} |
| 281 |
} |
| 282 |
else { |
| 283 |
jstring jclass_name = (jstring)env->CallObjectMethod(super_class, m_j_l_class_getName); |
| 284 |
if (jclass_name == NULL) { |
| 285 |
return (m_j_l_object_ch); |
| 286 |
} |
| 287 |
char *class_name_simple = (char *)env->GetStringUTFChars(jclass_name, NULL); |
| 288 |
assert (class_name_simple); |
| 289 |
char *ch = strchr(class_name_simple, '.'); |
| 290 |
while (ch != NULL) { |
| 291 |
*ch = '/'; |
| 292 |
ch = strchr(ch, '.'); |
| 293 |
} |
| 294 |
super_class_name = class_name_simple; |
| 295 |
} |
| 296 |
|
| 297 |
//assert(super_class); |
| 298 |
class_handler ch; |
| 299 |
int status = create_class_handler(&ch, CLASS_HANDLER_SIMPLEFIED, super_class_name, loaded, super_class); |
| 300 |
assert(status == 0); |
| 301 |
return (ch); |
| 302 |
} |
| 303 |
|
| 304 |
/** |
| 305 |
* Function checks if classes are equal. |
| 306 |
* @param klass1 - class handler |
| 307 |
* @param klass2 - class handler |
| 308 |
* @return If classes are equal returns <code>true</code>, else returns <code>false</code>. |
| 309 |
* @note Assertion is raised if klass1 or klass2 are equal to null. |
| 310 |
*/ |
| 311 |
extern "C" unsigned |
| 312 |
class_is_same_class( class_handler klass1, class_handler klass2 ) |
| 313 |
{ |
| 314 |
assert(!"verifier entered!!"); |
| 315 |
return 0; |
| 316 |
} |
| 317 |
|
| 318 |
static char* |
| 319 |
package_name(const char* kname) |
| 320 |
{ |
| 321 |
char *tokp; |
| 322 |
char *tok0; |
| 323 |
tokp = tok0 = (char *)&kname[0]; |
| 324 |
tok0 = strchr(kname, '/'); |
| 325 |
while (tok0 != NULL) { |
| 326 |
tokp = tok0; |
| 327 |
tok0 = strchr(tok0 + 1, '/'); |
| 328 |
} |
| 329 |
return (tokp); |
| 330 |
} |
| 331 |
|
| 332 |
/** |
| 333 |
* Function checks if classes have the same package. |
| 334 |
* @param klass1 - class handler |
| 335 |
* @param klass2 - class handler |
| 336 |
* @return If classes have the same package returns <code>true</code>, else returns <code>false</code>. |
| 337 |
* @note Assertion is raised if klass1 or klass2 are equal to null. |
| 338 |
*/ |
| 339 |
extern "C" unsigned |
| 340 |
class_is_same_package( class_handler klass1, class_handler klass2 ) |
| 341 |
{ |
| 342 |
if (klass1 == klass2) { |
| 343 |
return (1); |
| 344 |
} |
| 345 |
else { |
| 346 |
const char *klass1_name = class_get_name(klass1); |
| 347 |
const char *klass2_name = class_get_name(klass2); |
| 348 |
char* package1 = package_name(klass1_name); |
| 349 |
char* package2 = package_name(klass2_name); |
| 350 |
int package1_len = (package1 - klass1_name); |
| 351 |
int package2_len = (package2 - klass2_name); |
| 352 |
if (package1_len != package2_len) |
| 353 |
return (0); |
| 354 |
return(strncmp(klass1_name, klass2_name, package2_len) == 0); |
| 355 |
assert(!"verifier entered!!"); |
| 356 |
} |
| 357 |
return (0); |
| 358 |
} |
| 359 |
|
| 360 |
/** |
| 361 |
* Function checks if current class is interface. |
| 362 |
* @param klass - class handler |
| 363 |
* @return If class is interface returns <code>true</code>, else returns <code>false</code>. |
| 364 |
* @note Assertion is raised if klass is equal to null. |
| 365 |
*/ |
| 366 |
// FIXME - There is a macro class_is_interface in Class.h |
| 367 |
extern "C" unsigned |
| 368 |
class_is_interface( class_handler klass ) |
| 369 |
{ |
| 370 |
JNIEnv *env; |
| 371 |
env = m_get_vm_pointer((void **)&env); |
| 372 |
assert(env); |
| 373 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 374 |
return (0); |
| 375 |
} |
| 376 |
else { |
| 377 |
return (unsigned)(env->CallBooleanMethod((jobject)klass->X.simplefied_class, m_j_l_class_isInterface)); |
| 378 |
} |
| 379 |
|
| 380 |
return (0); |
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* Function checks if current class is array. |
| 385 |
* @param klass - class handler |
| 386 |
* @return If class is array returns <code>true</code>, else returns <code>false</code>. |
| 387 |
* @note Assertion is raised if klass is equal to null. |
| 388 |
*/ |
| 389 |
extern "C" unsigned |
| 390 |
class_is_array( class_handler klass ) |
| 391 |
{ |
| 392 |
assert(!"verifier entered!!"); |
| 393 |
return (0); |
| 394 |
} |
| 395 |
|
| 396 |
/** |
| 397 |
* Function checks if current class is final. |
| 398 |
* @param klass - class handler |
| 399 |
* @return If class is final returns <code>true</code>, else returns <code>false</code>. |
| 400 |
* @note Assertion is raised if klass is equal to null. |
| 401 |
*/ |
| 402 |
// FIXME - There is a macro class_is_final in Class.h |
| 403 |
extern "C" unsigned |
| 404 |
class_is_final_( class_handler klass ) |
| 405 |
{ |
| 406 |
assert(!"verifier entered!!"); |
| 407 |
return (0); |
| 408 |
} |
| 409 |
|
| 410 |
/** |
| 411 |
* Function receives number of super interfaces of class. |
| 412 |
* @param klass - class handler |
| 413 |
* @return Number of super interfaces of class. |
| 414 |
* @note Assertion is raised if klass is equal to null. |
| 415 |
*/ |
| 416 |
extern "C" unsigned short |
| 417 |
class_get_superinterface_number( class_handler klass ) |
| 418 |
{ |
| 419 |
assert(!"verifier entered!!"); |
| 420 |
return (0); |
| 421 |
} |
| 422 |
|
| 423 |
/** |
| 424 |
* Function receives super interface of class. |
| 425 |
* @param klass - class handler |
| 426 |
* @param index - super interface number |
| 427 |
* @return Super interface of class. |
| 428 |
* @note Assertion is raised if klass is equal to null or index is out of range. |
| 429 |
*/ |
| 430 |
extern "C" class_handler |
| 431 |
class_get_superinterface( class_handler klass, unsigned short index ) |
| 432 |
{ |
| 433 |
assert(!"verifier entered!!"); |
| 434 |
return (NULL); |
| 435 |
} |
| 436 |
|
| 437 |
/** |
| 438 |
* Function receives element class of array class. |
| 439 |
* @param klass - class handler |
| 440 |
* @return Element class of array class. |
| 441 |
* @note Assertion is raised if klass is equal to null or isn't array class. |
| 442 |
*/ |
| 443 |
extern "C" class_handler |
| 444 |
class_get_array_element_class( class_handler klass ) |
| 445 |
{ |
| 446 |
assert(!"verifier entered!!"); |
| 447 |
return (NULL); |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
/** |
| 452 |
* Function checks if class extends current class with given name. |
| 453 |
* @param klass - checked klass |
| 454 |
* @param super_name - parent class name |
| 455 |
* @return If given class extends current class with given name, |
| 456 |
* function returns its class handler, else function returns 0. |
| 457 |
* @note Assertion is raised if <i>klass</i> or <i>super_name</i> are equal to null. |
| 458 |
*/ |
| 459 |
extern "C" class_handler |
| 460 |
class_get_extended_class( class_handler klass, const char *super_name ) |
| 461 |
{ |
| 462 |
return (NULL); |
| 463 |
} |
| 464 |
|
| 465 |
/** |
| 466 |
* Function returns number of methods for current class. |
| 467 |
* @param klass - class handler |
| 468 |
* @return Number of methods for class. |
| 469 |
* @note Assertion is raised if klass is equal to null. |
| 470 |
*/ |
| 471 |
extern "C" unsigned short |
| 472 |
class_get_method_number( class_handler klass ) |
| 473 |
{ |
| 474 |
assert(!"verifier entered!!"); |
| 475 |
return (0); |
| 476 |
} |
| 477 |
|
| 478 |
/** |
| 479 |
* Function returns method of current class. |
| 480 |
* @param klass - class handler |
| 481 |
* @param index - method index |
| 482 |
* @return Method handler. |
| 483 |
* @note Assertion is raised if klass is equal to null or index is out of range. |
| 484 |
*/ |
| 485 |
extern "C" method_handler |
| 486 |
class_get_method( class_handler klass, unsigned short index ) |
| 487 |
{ |
| 488 |
assert(!"verifier entered!!"); |
| 489 |
return (NULL); |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
/** |
| 494 |
* Constant pool inteface |
| 495 |
*/ |
| 496 |
|
| 497 |
/** |
| 498 |
* Function returns class constant pool size. |
| 499 |
* @param klass - class handler |
| 500 |
* @return constant pool size |
| 501 |
* @note Assertion is raised if klass is equal to null. |
| 502 |
*/ |
| 503 |
extern "C" unsigned short |
| 504 |
class_cp_get_size( class_handler klass ) |
| 505 |
{ |
| 506 |
assert(klass); |
| 507 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 508 |
assert(klass->X.instrumented_class); |
| 509 |
assert(klass->X.instrumented_class->GetClassBuilder().GetConstPool()); |
| 510 |
return klass->X.instrumented_class->GetClassBuilder().GetConstPool()->GetSize(); |
| 511 |
} else { |
| 512 |
assert (!"not implemented yet!"); |
| 513 |
} |
| 514 |
assert(!"verifier entered!!"); |
| 515 |
return (0); |
| 516 |
} |
| 517 |
|
| 518 |
|
| 519 |
/** |
| 520 |
* Function returns constant pool entry tag. |
| 521 |
* @param klass - class handler |
| 522 |
* @param index - constant pool entry index |
| 523 |
* @return constant pool entry tag |
| 524 |
* @note Assertion is raised if klass is equal to null or index is out of range. |
| 525 |
*/ |
| 526 |
extern "C" unsigned char |
| 527 |
class_cp_get_tag( class_handler klass, unsigned short index ) |
| 528 |
{ |
| 529 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 530 |
return (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index]->GetTag(); |
| 531 |
} else { |
| 532 |
assert (!"not implemented yet!"); |
| 533 |
} |
| 534 |
return (0); |
| 535 |
} |
| 536 |
|
| 537 |
/** |
| 538 |
* Function returns class name entry index in constant pool. |
| 539 |
* @param klass - class handler |
| 540 |
* @param index - constant pool entry index |
| 541 |
* @return class name entry index |
| 542 |
* @note Function is legal only for constant pool entry with CONSTANT_Class tags. |
| 543 |
* @note Assertion is raised if klass is equal to null or index is out of range. |
| 544 |
*/ |
| 545 |
extern "C" unsigned short |
| 546 |
class_cp_get_class_name_index( class_handler klass, unsigned short index ) |
| 547 |
{ |
| 548 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 549 |
CCPInfo * ccinfo = (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index]; |
| 550 |
assert(ccinfo->GetTag() == CONSTANT_Class); |
| 551 |
return ((CCPClassInfo *)ccinfo)->GetClassInd(); |
| 552 |
} else { |
| 553 |
assert (!"not implemented yet!"); |
| 554 |
} |
| 555 |
return (0); |
| 556 |
} |
| 557 |
|
| 558 |
/** |
| 559 |
* Function returns class name entry index in constant pool. |
| 560 |
* @param klass - class handler |
| 561 |
* @param index - constant pool entry index |
| 562 |
* @return class name entry index |
| 563 |
* @note Function is legal for constant pool entry with |
| 564 |
* CONSTANT_Fieldref, CONSTANT_Methodref and CONSTANT_InterfaceMethodref tags. |
| 565 |
* @note Assertion is raised if klass is equal to null or index is out of range. |
| 566 |
*/ |
| 567 |
extern "C" unsigned short |
| 568 |
class_cp_get_ref_class_index( class_handler klass, unsigned short index ) |
| 569 |
{ |
| 570 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 571 |
CCPInfo * ccinfo = (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index]; |
| 572 |
unsigned char tag = ccinfo->GetTag(); |
| 573 |
switch(tag) { |
| 574 |
case CONSTANT_Fieldref: |
| 575 |
return ((CCPFieldrefInfo *)ccinfo)->GetClassInd(); |
| 576 |
break; |
| 577 |
case CONSTANT_Methodref: |
| 578 |
return ((CCPMethodrefInfo *)ccinfo)->GetClassInd(); |
| 579 |
break; |
| 580 |
case CONSTANT_InterfaceMethodref: |
| 581 |
return ((CCPInterfaceMethodrefInfo *)ccinfo)->GetClassInd(); |
| 582 |
break; |
| 583 |
default: |
| 584 |
assert(!"unsupported tag"); |
| 585 |
} |
| 586 |
} else { |
| 587 |
assert (!"not implemented yet!"); |
| 588 |
} |
| 589 |
return (0); |
| 590 |
} |
| 591 |
|
| 592 |
/** |
| 593 |
* Function returns name_and_type entry index in constant pool. |
| 594 |
* @param klass - class handler |
| 595 |
* @param index - constant pool entry index |
| 596 |
* @return name_and_type entry index |
| 597 |
* @note Function is legal for constant pool entry with |
| 598 |
* CONSTANT_Fieldref, CONSTANT_Methodref and CONSTANT_InterfaceMethodref tags. |
| 599 |
* @note Assertion is raised if klass is equal to null or index is out of range. |
| 600 |
*/ |
| 601 |
extern "C" unsigned short |
| 602 |
class_cp_get_ref_name_and_type_index( class_handler klass, unsigned short index ) |
| 603 |
{ |
| 604 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 605 |
CCPInfo * ccinfo = (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index]; |
| 606 |
unsigned char tag = ccinfo->GetTag(); |
| 607 |
switch(tag) { |
| 608 |
case CONSTANT_Fieldref: |
| 609 |
return ((CCPFieldrefInfo *)ccinfo)->GetNameAndTypeInd(); |
| 610 |
break; |
| 611 |
case CONSTANT_Methodref: |
| 612 |
return ((CCPMethodrefInfo *)ccinfo)->GetNameAndTypeInd(); |
| 613 |
break; |
| 614 |
case CONSTANT_InterfaceMethodref: |
| 615 |
return ((CCPInterfaceMethodrefInfo *)ccinfo)->GetNameAndTypeInd(); |
| 616 |
break; |
| 617 |
default: |
| 618 |
assert(!"unsupported tag"); |
| 619 |
} |
| 620 |
} else { |
| 621 |
assert (!"not implemented yet!"); |
| 622 |
} |
| 623 |
return (0); |
| 624 |
} |
| 625 |
|
| 626 |
/** |
| 627 |
* Function returns string entry index in constant pool. |
| 628 |
* @param klass - class handler |
| 629 |
* @param index - constant pool entry index |
| 630 |
* @return string entry index |
| 631 |
* @note Function is legal for constant pool entry with CONSTANT_String tags. |
| 632 |
* @note Assertion is raised if klass is equal to null or index is out of range. |
| 633 |
*/ |
| 634 |
extern "C" unsigned short |
| 635 |
class_cp_get_string_index( class_handler klass, unsigned short index ) |
| 636 |
{ |
| 637 |
assert(!"verifier entered!!"); |
| 638 |
return (0); |
| 639 |
} |
| 640 |
|
| 641 |
/** |
| 642 |
* Function returns name entry index in constant pool. |
| 643 |
* @param klass - class handler |
| 644 |
* @param index - constant pool entry index |
| 645 |
* @return name entry index |
| 646 |
* @note Function is legal for constant pool entry with CONSTANT_NameAndType tags. |
| 647 |
* @note Assertion is raised if klass is equal to null or index is out of range. |
| 648 |
*/ |
| 649 |
extern "C" unsigned short |
| 650 |
class_cp_get_name_index( class_handler klass, unsigned short index ) |
| 651 |
{ |
| 652 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 653 |
CCPInfo * ccinfo = (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index]; |
| 654 |
unsigned char tag = ccinfo->GetTag(); |
| 655 |
assert(tag == CONSTANT_NameAndType); |
| 656 |
return ((CCPNameAndTypeInfo *)ccinfo)->GetNameInd(); |
| 657 |
} else { |
| 658 |
assert (!"not implemented yet!"); |
| 659 |
} |
| 660 |
return (0); |
| 661 |
} |
| 662 |
|
| 663 |
/** |
| 664 |
* Function returns descriptor entry index in constant pool. |
| 665 |
* @param klass - class handler |
| 666 |
* @param index - constant pool entry index |
| 667 |
* @return descriptor entry index |
| 668 |
* @note Function is legal for constant pool entry with CONSTANT_NameAndType tags. |
| 669 |
* @note Assertion is raised if klass is equal to null or index is out of range. |
| 670 |
*/ |
| 671 |
extern "C" unsigned short |
| 672 |
class_cp_get_descriptor_index( class_handler klass, unsigned short index ) |
| 673 |
{ |
| 674 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 675 |
CCPInfo * ccinfo = (*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index]; |
| 676 |
unsigned char tag = ccinfo->GetTag(); |
| 677 |
assert(tag == CONSTANT_NameAndType); |
| 678 |
return ((CCPNameAndTypeInfo *)ccinfo)->GetDescriptorInd(); |
| 679 |
} else { |
| 680 |
assert (!"not implemented yet!"); |
| 681 |
} |
| 682 |
return (0); |
| 683 |
} |
| 684 |
|
| 685 |
/** |
| 686 |
* Function returns bytes for UTF8 constant pool entry. |
| 687 |
* @param klass - class handler |
| 688 |
* @param index - constant pool entry index |
| 689 |
* @return bytes for UTF8 constant pool entry |
| 690 |
* @note Function is legal for constant pool entry with CONSTANT_UTF8 tags. |
| 691 |
* @note Assertion is raised if klass is equal to null or index is out of range. |
| 692 |
*/ |
| 693 |
extern "C" const char * |
| 694 |
class_cp_get_utf8_bytes( class_handler klass, unsigned short index ) |
| 695 |
{ |
| 696 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 697 |
return (const char *)((CCPUtf8Info *)(*klass->X.instrumented_class->GetClassBuilder().GetConstPool())[index])->GetBytes(); |
| 698 |
} else { |
| 699 |
assert (!"not implemented yet!"); |
| 700 |
} |
| 701 |
return (0); |
| 702 |
} |
| 703 |
|
| 704 |
/** |
| 705 |
* Function sets verify data to a given class. |
| 706 |
* @param klass - class handler |
| 707 |
* @param data - verify data |
| 708 |
* @note Assertion is raised if class is equal to null. |
| 709 |
* @note Function makes non thread save operation and |
| 710 |
* must be called in thread safe point. |
| 711 |
*/ |
| 712 |
extern "C" void |
| 713 |
class_set_verify_data_ptr( class_handler klass, void *data ) |
| 714 |
{ |
| 715 |
assert(!"verifier entered!!"); |
| 716 |
return; |
| 717 |
} |
| 718 |
|
| 719 |
/** |
| 720 |
* Function returns verify data for a given class. |
| 721 |
* @param klass - class handler |
| 722 |
* @return Verify data for a given class. |
| 723 |
* @note Assertion is raised if klass is equal to null. |
| 724 |
*/ |
| 725 |
extern "C" void * |
| 726 |
class_get_verify_data_ptr( class_handler klass ) |
| 727 |
{ |
| 728 |
assert(!"verifier entered!!"); |
| 729 |
return (NULL); |
| 730 |
} |
| 731 |
|
| 732 |
/** |
| 733 |
* Function resolves class nonstatic method for constant pool entry. |
| 734 |
* |
| 735 |
* @param klass - class handle |
| 736 |
* @param index - constant pool entry index |
| 737 |
* @param exc - pointer to exception |
| 738 |
* |
| 739 |
* @return Return nonstatic method resolved for constant pool entry. |
| 740 |
*/ |
| 741 |
extern "C" method_handler |
| 742 |
class_resolve_method( class_handler klass, unsigned short index ) |
| 743 |
{ |
| 744 |
assert(!"verifier entered!!"); |
| 745 |
return (NULL); |
| 746 |
} |
| 747 |
|
| 748 |
/** |
| 749 |
* Function resolves class nonstatic field for constant pool entry. |
| 750 |
* |
| 751 |
* @param klass - class handle |
| 752 |
* @param index - constant pool entry index |
| 753 |
* @param exc - pointer to exception |
| 754 |
* |
| 755 |
* @return Return nonstatic field resolved for constant pool entry. |
| 756 |
*/ |
| 757 |
extern "C" field_handler |
| 758 |
class_resolve_nonstatic_field( class_handler klass, unsigned short index ) |
| 759 |
{ |
| 760 |
assert(!"verifier entered!!"); |
| 761 |
return (NULL); |
| 762 |
} |
| 763 |
|
| 764 |
/** |
| 765 |
* Method interface |
| 766 |
*/ |
| 767 |
|
| 768 |
/** |
| 769 |
* Function returns a class in which the method is declared. |
| 770 |
* @param method - method handler |
| 771 |
* @return Return a class in which the method is declared. |
| 772 |
* @note Assertion is raised if <i>method</i> is equal to null. |
| 773 |
*/ |
| 774 |
extern "C" class_handler |
| 775 |
method_get_class( method_handler hmethod ) |
| 776 |
{ |
| 777 |
|
| 778 |
if (hmethod == NULL) return (NULL); |
| 779 |
else |
| 780 |
return hmethod->class_owner; |
| 781 |
#if 0 |
| 782 |
if (hmethod->magic == METHOD_HANDLER_SELF) { |
| 783 |
if (hmethod->X.instrumented_method) return (NULL); |
| 784 |
return (((CModuleJ *)hmethod->X.instrumented_method->GetModule())->GetClassHandler()); |
| 785 |
} |
| 786 |
else { |
| 787 |
assert(!"verifier entered!!"); |
| 788 |
} |
| 789 |
|
| 790 |
return (NULL); |
| 791 |
#endif |
| 792 |
} |
| 793 |
|
| 794 |
/** |
| 795 |
* Function returns method name. |
| 796 |
* @param method - method handler |
| 797 |
* @return Method name bytes. |
| 798 |
* @note Assertion is raised if method is equal to null. |
| 799 |
*/ |
| 800 |
extern "C" const char * |
| 801 |
method_get_name( method_handler method ) |
| 802 |
{ |
| 803 |
if (method->magic == METHOD_HANDLER_SELF) { |
| 804 |
return (method->X.instrumented_method->GetName()); |
| 805 |
} |
| 806 |
else { |
| 807 |
assert(!"verifier entered!!"); |
| 808 |
} |
| 809 |
return (NULL); |
| 810 |
} |
| 811 |
|
| 812 |
/** |
| 813 |
* Function returns method descriptor. |
| 814 |
* @param method - method handler |
| 815 |
* @return Method descriptor bytes. |
| 816 |
* @note Assertion is raised if method is equal to null. |
| 817 |
*/ |
| 818 |
extern "C" const char * |
| 819 |
method_get_descriptor( method_handler method ) |
| 820 |
{ |
| 821 |
if (method->magic == METHOD_HANDLER_SELF) { |
| 822 |
return (method->X.instrumented_method->GetSignature()); |
| 823 |
} |
| 824 |
else { |
| 825 |
assert(!"verifier entered!!"); |
| 826 |
} |
| 827 |
return (NULL); |
| 828 |
} |
| 829 |
|
| 830 |
/** |
| 831 |
* Function returns method code length. |
| 832 |
* @param method - method handler |
| 833 |
* @return Method code length. |
| 834 |
* @note Assertion is raised if method is equal to null. |
| 835 |
*/ |
| 836 |
extern "C" unsigned |
| 837 |
method_get_bytecode_length( method_handler method ) |
| 838 |
{ |
| 839 |
/*insert check about instrumentation*/ |
| 840 |
if (method->magic == METHOD_HANDLER_SELF) { |
| 841 |
unsigned size = 0; |
| 842 |
CInstructions::const_iterator insIterator; |
| 843 |
if (method->X.instrumented_method->GetCodeAttribute() == NULL) return (0); |
| 844 |
return (method->X.instrumented_method->GetCodeAttribute()->GetCodeLength()); |
| 845 |
} |
| 846 |
else { |
| 847 |
assert(!"verifier entered!!"); |
| 848 |
} |
| 849 |
return (0); |
| 850 |
} |
| 851 |
|
| 852 |
/** |
| 853 |
* Function returns method bytecode array. |
| 854 |
* @param method - method handler |
| 855 |
* @return Method bytecode array. |
| 856 |
* @note Assertion is raised if method is equal to null. |
| 857 |
*/ |
| 858 |
extern "C" unsigned char * |
| 859 |
method_get_bytecode( method_handler method ) |
| 860 |
{ |
| 861 |
if (method->magic == METHOD_HANDLER_SELF) { |
| 862 |
return (method->X.instrumented_method->GetCodeAttribute()->GetCode()); |
| 863 |
} |
| 864 |
else { |
| 865 |
assert(!"verifier entered!!"); |
| 866 |
} |
| 867 |
return (NULL); |
| 868 |
} |
| 869 |
|
| 870 |
/** |
| 871 |
* Function returns maximal local variables number of method. |
| 872 |
* @param method - method handler |
| 873 |
* @return Maximal local variables number of method. |
| 874 |
* @note Assertion is raised if method is equal to null. |
| 875 |
*/ |
| 876 |
extern "C" unsigned |
| 877 |
method_get_max_locals( method_handler method ) |
| 878 |
{ |
| 879 |
if (method->magic == METHOD_HANDLER_SELF) { |
| 880 |
/*XXX: add check for instrumented method*/ |
| 881 |
CMethodJ * jmethod = (CMethodJ *)(method->X.instrumented_method); |
| 882 |
return (jmethod->GetCodeAttribute()->GetMaxLocals()); |
| 883 |
} |
| 884 |
else { |
| 885 |
assert(!"verifier entered!!"); |
| 886 |
} |
| 887 |
return (0); |
| 888 |
|
| 889 |
} |
| 890 |
|
| 891 |
/** |
| 892 |
* Function returns maximal stack deep of method. |
| 893 |
* @param method - method handler |
| 894 |
* @return Maximal stack deep of method. |
| 895 |
* @note Assertion is raised if method is equal to null. |
| 896 |
*/ |
| 897 |
extern "C" unsigned |
| 898 |
method_get_max_stack( method_handler method ) |
| 899 |
{ |
| 900 |
if (method->magic == METHOD_HANDLER_SELF) { |
| 901 |
CMethodJ * jmethod = (CMethodJ *)(method->X.instrumented_method); |
| 902 |
return (jmethod->GetCodeAttribute()->GetMaxStack()); |
| 903 |
} |
| 904 |
else { |
| 905 |
assert(!"verifier entered!!"); |
| 906 |
} |
| 907 |
return (0); |
| 908 |
} |
| 909 |
|
| 910 |
/** |
| 911 |
* Function checks if method is static. |
| 912 |
* @param method - method handler |
| 913 |
* @return If method is static, function returns <code>true</code>, |
| 914 |
* else returns <code>false</code>. |
| 915 |
* @note Assertion is raised if method is equal to null. |
| 916 |
*/ |
| 917 |
extern "C" unsigned |
| 918 |
method_is_static( method_handler method ) |
| 919 |
{ |
| 920 |
if (method->magic == METHOD_HANDLER_SELF) { |
| 921 |
return (method->X.instrumented_method->GetAccessFlags() & ACC_STATIC); |
| 922 |
} |
| 923 |
else { |
| 924 |
//assert(!"verifier entered!!"); |
| 925 |
return (0); /*we're assuming that this function called after class_resolve_method and couldn't return static methods*/ |
| 926 |
} |
| 927 |
return (0); |
| 928 |
|
| 929 |
} |
| 930 |
|
| 931 |
/** |
| 932 |
* Function checks if a given method is protected. |
| 933 |
* |
| 934 |
* @param method - method handle |
| 935 |
* |
| 936 |
* @return Return <code>TRUE</code> if a given method is protected. |
| 937 |
* |
| 938 |
* @note Assertion is raised if <i>method</i> is equal to null. |
| 939 |
*/ |
| 940 |
extern "C" unsigned |
| 941 |
method_is_protected( method_handler method ) |
| 942 |
{ |
| 943 |
assert(!"verifier entered!!"); |
| 944 |
return (0); |
| 945 |
} |
| 946 |
|
| 947 |
/** |
| 948 |
* Method exception handler |
| 949 |
*/ |
| 950 |
|
| 951 |
/** |
| 952 |
* Function returns number of method exception handlers. |
| 953 |
* @param method - method handler |
| 954 |
* @return Number of method exception handlers. |
| 955 |
* @note Assertion is raised if method is equal to null. |
| 956 |
*/ |
| 957 |
extern "C" unsigned short |
| 958 |
method_get_exc_handler_number( method_handler method ) |
| 959 |
{ |
| 960 |
return (method->X.instrumented_method->GetExTable()->size()); |
| 961 |
} |
| 962 |
|
| 963 |
/** |
| 964 |
* Function obtains method exception handler info. |
| 965 |
* @param method - method handler |
| 966 |
* @param index - exception handler index number |
| 967 |
* @param start_pc - resulting pointer to exception handler start program count |
| 968 |
* @param end_pc - resulting pointer to exception handler end program count |
| 969 |
* @param handler_pc - resulting pointer to exception handler program count |
| 970 |
* @param catch_type - resulting pointer to constant pool entry index |
| 971 |
* @note Assertion is raised if method is equal to null or |
| 972 |
* exception handler index is out of range or |
| 973 |
* any pointer is equal to null. |
| 974 |
*/ |
| 975 |
extern "C" void |
| 976 |
method_get_exc_handler_info( method_handler method, unsigned short index, |
| 977 |
unsigned short *start_pc, unsigned short *end_pc, |
| 978 |
unsigned short *handler_pc, unsigned short *catch_type ) |
| 979 |
{ |
| 980 |
class CExTable& exc = method->X.instrumented_method->GetCodeAttribute()->GetExTable(); |
| 981 |
*start_pc = exc[index].GetStartPC(); |
| 982 |
*end_pc = exc[index].GetEndPC(); |
| 983 |
*handler_pc = exc[index].GetHandlerPC(); |
| 984 |
*catch_type = exc[index].GetCatchtype(); |
| 985 |
|
| 986 |
return; |
| 987 |
} |
| 988 |
|
| 989 |
/** |
| 990 |
* Gets number of exceptions a method can throw. |
| 991 |
* Parameter <i>hmethod</i> must not equal to <code>NULL</code>. |
| 992 |
* |
| 993 |
* @param hmethod method handle |
| 994 |
* |
| 995 |
* @return number of exceptions |
| 996 |
*/ |
| 997 |
extern "C" unsigned short |
| 998 |
method_get_number_exc_method_can_throw( method_handler hmethod ) |
| 999 |
{ |
| 1000 |
assert(!"verifier entered!!"); |
| 1001 |
return (0); |
| 1002 |
} |
| 1003 |
|
| 1004 |
/** |
| 1005 |
* Gets name of exception a method can throw. |
| 1006 |
* Parameter <i>hmethod</i> must not equal to <code>NULL</code>. |
| 1007 |
* If parameter <i>index</i> is out of range, returns <code>NULL</code>. |
| 1008 |
* |
| 1009 |
* @param hmethod method handle |
| 1010 |
* @param index index of exception |
| 1011 |
* |
| 1012 |
* @return name of exception |
| 1013 |
*/ |
| 1014 |
extern "C" const char * |
| 1015 |
method_get_exc_method_can_throw( method_handler hmethod, unsigned short index ) |
| 1016 |
{ |
| 1017 |
assert(!"verifier entered!!"); |
| 1018 |
return (NULL); |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
/** |
| 1023 |
* Gets StackMapTable attribute. |
| 1024 |
* Parameter <i>hmethod</i> must not equal to <code>NULL</code>. |
| 1025 |
* If parameter <i>index</i> is out of range, returns <code>NULL</code>. |
| 1026 |
* |
| 1027 |
* @param hmethod method handle |
| 1028 |
* |
| 1029 |
* @return StackMapTable bytes |
| 1030 |
*/ |
| 1031 |
extern "C" unsigned char * |
| 1032 |
method_get_stackmaptable( method_handler hmethod ) |
| 1033 |
{ |
| 1034 |
|
| 1035 |
CStackMapTableAttribute *attr = hmethod->X.instrumented_method->GetCodeAttribute()->GetStackMaps(); |
| 1036 |
if (attr == NULL) |
| 1037 |
return (NULL); |
| 1038 |
u4 length = attr->GetLength(); |
| 1039 |
u1 *stackmap = (u1 *)malloc(length); |
| 1040 |
CJMemStream mem_stream; |
| 1041 |
mem_stream.Open(stackmap, length); |
| 1042 |
CJStream stream(&mem_stream); |
| 1043 |
attr->Write(stream); |
| 1044 |
//return (attr->GetInfo()); |
| 1045 |
return (stackmap); |
| 1046 |
} |
| 1047 |
|
| 1048 |
|
| 1049 |
//modifies start_pc, end_pc |
| 1050 |
extern "C" void |
| 1051 |
method_modify_exc_handler_info(method_handler method, |
| 1052 |
unsigned short idx, |
| 1053 |
unsigned short start_pc, |
| 1054 |
unsigned short end_pc, |
| 1055 |
unsigned short handler_pc, |
| 1056 |
unsigned short handler_cp_index ) |
| 1057 |
{ |
| 1058 |
|
| 1059 |
assert(!"verifier entered!!"); |
| 1060 |
return; |
| 1061 |
} |
| 1062 |
|
| 1063 |
// removes given exception handler (handlers with greater indexes shift) |
| 1064 |
extern "C" void |
| 1065 |
method_remove_exc_handler( method_handler method, unsigned short idx ) |
| 1066 |
{ |
| 1067 |
assert(!"verifier entered!!"); |
| 1068 |
return; |
| 1069 |
} |
| 1070 |
|
| 1071 |
/** |
| 1072 |
* Class loader interface |
| 1073 |
*/ |
| 1074 |
|
| 1075 |
/** |
| 1076 |
* Function sets verify data in class loader. |
| 1077 |
* @param classloader - class loader handler |
| 1078 |
* @param data - verify data |
| 1079 |
* @note Assertion is raised if classloader is equal to null. |
| 1080 |
* @note Function makes non thread save operation and |
| 1081 |
* must be called in thread safe point. |
| 1082 |
*/ |
| 1083 |
extern "C" void |
| 1084 |
class_loader_set_verifier_data_ptr( classloader_handler classloader, void *data ) |
| 1085 |
{ |
| 1086 |
assert(!"verifier entered!!"); |
| 1087 |
return; |
| 1088 |
} |
| 1089 |
|
| 1090 |
/** |
| 1091 |
* Function returns verify data in class loader. |
| 1092 |
* @param classloader - class loader handler |
| 1093 |
* @return Verify data in class loader. |
| 1094 |
* @note Assertion is raised if classloader is equal to null. |
| 1095 |
*/ |
| 1096 |
extern "C" void * |
| 1097 |
class_loader_get_verifier_data_ptr( classloader_handler classloader ) |
| 1098 |
{ |
| 1099 |
assert(!"verifier entered!!"); |
| 1100 |
return (NULL); |
| 1101 |
} |
| 1102 |
|
| 1103 |
/** |
| 1104 |
* Function locks class loader. |
| 1105 |
* @param classloader - class loader handler |
| 1106 |
* @note Assertion is raised if classloader is equal to null. |
| 1107 |
*/ |
| 1108 |
extern "C" void |
| 1109 |
class_loader_lock( classloader_handler classloader ) |
| 1110 |
{ |
| 1111 |
assert(!"verifier entered!!"); |
| 1112 |
return; |
| 1113 |
} |
| 1114 |
|
| 1115 |
/** |
| 1116 |
* Function releases class loader. |
| 1117 |
* @param classloader - class loader handler |
| 1118 |
* @note Assertion is raised if classloader is equal to null. |
| 1119 |
*/ |
| 1120 |
extern "C" void |
| 1121 |
class_loader_unlock( classloader_handler classloader ) |
| 1122 |
{ |
| 1123 |
assert(!"verifier entered!!"); |
| 1124 |
return; |
| 1125 |
} |
| 1126 |
|
| 1127 |
/** |
| 1128 |
* Function returns loaded class in class loader. |
| 1129 |
* @param classloader - class loader handler |
| 1130 |
* @param name - class name |
| 1131 |
* @return Loaded class in classloader or null if class isn't loaded in class loader. |
| 1132 |
* @note Assertion is raised if classloader or name are equal to null. |
| 1133 |
*/ |
| 1134 |
extern "C" class_handler |
| 1135 |
class_loader_lookup_class( classloader_handler classloader, const char *name ) |
| 1136 |
{ |
| 1137 |
if (m_name2ch[name] != NULL && IS_CLASS_INSTRUMENTED(m_name2ch[name])) |
| 1138 |
return (m_name2ch[name]); |
| 1139 |
else |
| 1140 |
return (NULL); |
| 1141 |
} |
| 1142 |
|
| 1143 |
/** |
| 1144 |
* Function returns loaded class in class loader. |
| 1145 |
* @param classloader - class loader handler |
| 1146 |
* @param name - class name |
| 1147 |
* @return Loaded class in classloader if class isn't loaded in class loader |
| 1148 |
* function loads it. |
| 1149 |
* @note Assertion is raised if classloader or name are equal to null. |
| 1150 |
*/ |
| 1151 |
extern "C" class_handler |
| 1152 |
class_loader_load_class( classloader_handler classloader, const char *name ) |
| 1153 |
{ |
| 1154 |
assert(!"verifier entered!!"); |
| 1155 |
return (NULL); |
| 1156 |
} |
| 1157 |
|
| 1158 |
/** |
| 1159 |
* Function checks if the field is protected. |
| 1160 |
* @param field - field handler |
| 1161 |
* @return Returns <code>TRUE</code> if the field is protected. |
| 1162 |
*/ |
| 1163 |
extern "C" unsigned |
| 1164 |
field_is_protected( field_handler field ) |
| 1165 |
{ |
| 1166 |
assert(!"verifier entered!!"); |
| 1167 |
return (0); |
| 1168 |
} |
| 1169 |
|
| 1170 |
class_handler |
| 1171 |
get_class_handler_from_builder(class CModuleJ *module) |
| 1172 |
{ |
| 1173 |
class_handler ch; |
| 1174 |
|
| 1175 |
m_name2ch.clear(); |
| 1176 |
int status = create_class_handler(&m_j_l_object_ch, CLASS_HANDLER_SIMPLEFIED, "java/lang/Object", 0, NULL); |
| 1177 |
assert(!status); |
| 1178 |
|
| 1179 |
status = create_class_handler(&ch, CLASS_HANDLER_INSTRUMENTED, module->GetName(), 1, module); |
| 1180 |
assert(!status); |
| 1181 |
return (ch); |
| 1182 |
} |
| 1183 |
|
| 1184 |
method_handler |
| 1185 |
get_method_handler_for_cmethod(class CMethod *method) |
| 1186 |
{ |
| 1187 |
class_handler ch = NULL; |
| 1188 |
method_handler mh = NULL; |
| 1189 |
int status; |
| 1190 |
status = create_class_handler(&ch, CLASS_HANDLER_INSTRUMENTED, (const char *)method->GetModule()->GetName(), 1, method->GetModule()); |
| 1191 |
assert(!status); |
| 1192 |
status = create_method_handler(&mh, ch, METHOD_HANDLER_SELF, method); |
| 1193 |
assert(!status); |
| 1194 |
return (mh); |
| 1195 |
} |
| 1196 |
|
| 1197 |
extern "C" unsigned short |
| 1198 |
class_cp_get_class_entry(class_handler klass, const char* name) |
| 1199 |
{ |
| 1200 |
|
| 1201 |
|
| 1202 |
CCPClassInfo *cinfo; |
| 1203 |
if (IS_CLASS_INSTRUMENTED(klass)) { |
| 1204 |
/*for this class we'll have entry somewhere in some future */ |
| 1205 |
if (strcmp(klass->X.instrumented_class->GetName(), name) == 0) { |
| 1206 |
return (klass->X.instrumented_class->GetClass().GetThisClass()); |
| 1207 |
} |
| 1208 |
assert(name); |
| 1209 |
cinfo = (klass->X.instrumented_class->GetClassBuilder().FindClass(name)); |
| 1210 |
if (cinfo == NULL) { |
| 1211 |
/*should be created new class antry */ |
| 1212 |
cinfo = *klass->X.instrumented_class->GetClassBuilder().CreateClassConstant(name); |
| 1213 |
assert(cinfo); |
| 1214 |
} |
| 1215 |
return(cinfo->GetCpIndex()); |
| 1216 |
} else { |
| 1217 |
assert (!"not implemented yet!"); |
| 1218 |
} |
| 1219 |
return (0); |
| 1220 |
} |
| 1221 |
|
| 1222 |
int |
| 1223 |
initialize_dynamic(get_vm_pointer_t a_get_vm_pointer) |
| 1224 |
{ |
| 1225 |
m_get_vm_pointer = (JNIEnv *(*)(void **))a_get_vm_pointer; |
| 1226 |
JNIEnv *env; |
| 1227 |
env = m_get_vm_pointer((void **)&env); |
| 1228 |
assert(env); |
| 1229 |
if (m_j_l_class) return (0); |
| 1230 |
|
| 1231 |
m_j_l_class = env->FindClass("java/lang/Class"); |
| 1232 |
assert(m_j_l_class); |
| 1233 |
m_j_l_class_getName = env->GetMethodID(m_j_l_class, "getName", "()Ljava/lang/String;"); |
| 1234 |
assert(m_j_l_class_getName); |
| 1235 |
m_j_l_class_getClassLoader = env->GetMethodID(m_j_l_class, "getClassLoader", "()Ljava/lang/ClassLoader;"); |
| 1236 |
assert(m_j_l_class_getClassLoader); |
| 1237 |
m_j_l_class_isInterface = env->GetMethodID(m_j_l_class, "isInterface", "()Z"); |
| 1238 |
assert(m_j_l_class_isInterface); |
| 1239 |
|
| 1240 |
m_j_l_classloader = env->FindClass("java/lang/ClassLoader"); |
| 1241 |
assert(m_j_l_classloader); |
| 1242 |
m_j_l_classloader_findLoadedClass = env->GetMethodID(m_j_l_classloader, "findLoadedClass", "(Ljava/lang/String;)Ljava/lang/Class;"); |
| 1243 |
assert(m_j_l_classloader_findLoadedClass); |
| 1244 |
|
| 1245 |
return (0); |
| 1246 |
} |
| 1247 |
|