javaClasses.hpp 45.5 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31 32 33
#ifndef SHARE_VM_CLASSFILE_JAVACLASSES_HPP
#define SHARE_VM_CLASSFILE_JAVACLASSES_HPP

#include "classfile/systemDictionary.hpp"
#include "jvmtifiles/jvmti.h"
#include "oops/oop.hpp"
#include "runtime/os.hpp"
#include "utilities/utf8.hpp"

D
duke 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
// Interface for manipulating the basic Java classes.
//
// All dependencies on layout of actual Java classes should be kept here.
// If the layout of any of the classes above changes the offsets must be adjusted.
//
// For most classes we hardwire the offsets for performance reasons. In certain
// cases (e.g. java.security.AccessControlContext) we compute the offsets at
// startup since the layout here differs between JDK1.2 and JDK1.3.
//
// Note that fields (static and non-static) are arranged with oops before non-oops
// on a per class basis. The offsets below have to reflect this ordering.
//
// When editing the layouts please update the check_offset verification code
// correspondingly. The names in the enums must be identical to the actual field
// names in order for the verification code to work.


// Interface to java.lang.String objects

class java_lang_String : AllStatic {
 private:
  static int value_offset;
  static int offset_offset;
  static int count_offset;
  static int hash_offset;

K
kvn 已提交
60 61
  static bool initialized;

62
  static Handle basic_create(int length, TRAPS);
D
duke 已提交
63

K
kvn 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  static void set_value( oop string, typeArrayOop buffer) {
    assert(initialized, "Must be initialized");
    string->obj_field_put(value_offset,  (oop)buffer);
  }
  static void set_offset(oop string, int offset) {
    assert(initialized, "Must be initialized");
    if (offset_offset > 0) {
      string->int_field_put(offset_offset, offset);
    }
  }
  static void set_count( oop string, int count) {
    assert(initialized, "Must be initialized");
    if (count_offset > 0) {
      string->int_field_put(count_offset,  count);
    }
  }
D
duke 已提交
80 81

 public:
K
kvn 已提交
82 83
  static void compute_offsets();

D
duke 已提交
84 85 86 87 88
  // Instance creation
  static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
  static oop    create_oop_from_unicode(jchar* unicode, int len, TRAPS);
  static Handle create_from_str(const char* utf8_str, TRAPS);
  static oop    create_oop_from_str(const char* utf8_str, TRAPS);
89
  static Handle create_from_symbol(Symbol* symbol, TRAPS);
D
duke 已提交
90 91 92
  static Handle create_from_platform_dependent_str(const char* str, TRAPS);
  static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);

K
kvn 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
  static bool has_offset_field()  {
    assert(initialized, "Must be initialized");
    return (offset_offset > 0);
  }

  static bool has_count_field()  {
    assert(initialized, "Must be initialized");
    return (count_offset > 0);
  }

  static bool has_hash_field()  {
    assert(initialized, "Must be initialized");
    return (hash_offset > 0);
  }

  static int value_offset_in_bytes()  {
    assert(initialized && (value_offset > 0), "Must be initialized");
    return value_offset;
  }
  static int count_offset_in_bytes()  {
    assert(initialized && (count_offset > 0), "Must be initialized");
    return count_offset;
  }
  static int offset_offset_in_bytes() {
    assert(initialized && (offset_offset > 0), "Must be initialized");
    return offset_offset;
  }
  static int hash_offset_in_bytes()   {
    assert(initialized && (hash_offset > 0), "Must be initialized");
    return hash_offset;
  }
D
duke 已提交
124 125 126

  // Accessors
  static typeArrayOop value(oop java_string) {
K
kvn 已提交
127
    assert(initialized && (value_offset > 0), "Must be initialized");
D
duke 已提交
128 129 130 131
    assert(is_instance(java_string), "must be java_string");
    return (typeArrayOop) java_string->obj_field(value_offset);
  }
  static int offset(oop java_string) {
K
kvn 已提交
132
    assert(initialized, "Must be initialized");
D
duke 已提交
133
    assert(is_instance(java_string), "must be java_string");
K
kvn 已提交
134 135 136 137 138
    if (offset_offset > 0) {
      return java_string->int_field(offset_offset);
    } else {
      return 0;
    }
D
duke 已提交
139 140
  }
  static int length(oop java_string) {
K
kvn 已提交
141
    assert(initialized, "Must be initialized");
D
duke 已提交
142
    assert(is_instance(java_string), "must be java_string");
K
kvn 已提交
143 144 145 146 147
    if (count_offset > 0) {
      return java_string->int_field(count_offset);
    } else {
      return ((typeArrayOop)java_string->obj_field(value_offset))->length();
    }
D
duke 已提交
148 149 150 151 152
  }
  static int utf8_length(oop java_string);

  // String converters
  static char*  as_utf8_string(oop java_string);
153
  static char*  as_utf8_string(oop java_string, char* buf, int buflen);
D
duke 已提交
154
  static char*  as_utf8_string(oop java_string, int start, int len);
155
  static char*  as_platform_dependent_str(Handle java_string, TRAPS);
156
  static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
157 158
  // produce an ascii string with all other values quoted using \u####
  static char*  as_quoted_ascii(oop java_string);
D
duke 已提交
159

160
  // Compute the hash value for a java.lang.String object which would
161
  // contain the characters passed in.
162
  //
163 164 165 166 167
  // As the hash value used by the String object itself, in
  // String.hashCode().  This value is normally calculated in Java code
  // in the String.hashCode method(), but is precomputed for String
  // objects in the shared archive file.
  // hash P(31) from Kernighan & Ritchie
168
  //
169 170
  // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
  template <typename T> static unsigned int hash_code(T* s, int len) {
171 172 173 174 175 176 177
    unsigned int h = 0;
    while (len-- > 0) {
      h = 31*h + (unsigned int) *s;
      s++;
    }
    return h;
  }
178
  static unsigned int hash_code(oop java_string);
179 180

  // This is the string hash code used by the StringTable, which may be
181
  // the same as String.hashCode or an alternate hash code.
182 183
  static unsigned int hash_string(oop java_string);

D
duke 已提交
184 185 186 187 188 189 190
  static bool equals(oop java_string, jchar* chars, int len);

  // Conversion between '.' and '/' formats
  static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
  static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }

  // Conversion
191 192
  static Symbol* as_symbol(Handle java_string, TRAPS);
  static Symbol* as_symbol_or_null(oop java_string);
D
duke 已提交
193 194 195

  // Testers
  static bool is_instance(oop obj) {
196
    return obj != NULL && obj->klass() == SystemDictionary::String_klass();
D
duke 已提交
197 198 199 200 201 202 203 204 205 206
  }

  // Debugging
  static void print(Handle java_string, outputStream* st);
  friend class JavaClasses;
};


// Interface to java.lang.Class objects

207
#define CLASS_INJECTED_FIELDS(macro)                                       \
208 209
  macro(java_lang_Class, klass,                  intptr_signature,  false) \
  macro(java_lang_Class, array_klass,            intptr_signature,  false) \
210
  macro(java_lang_Class, oop_size,               int_signature,     false) \
211 212 213 214
  macro(java_lang_Class, static_oop_field_count, int_signature,     false) \
  macro(java_lang_Class, protection_domain,      object_signature,  false) \
  macro(java_lang_Class, init_lock,              object_signature,  false) \
  macro(java_lang_Class, signers,                object_signature,  false)
215

D
duke 已提交
216
class java_lang_Class : AllStatic {
217 218
  friend class VMStructs;

D
duke 已提交
219 220 221
 private:
  // The fake offsets are added by the class loader when java.lang.Class is loaded

222 223
  static int _klass_offset;
  static int _array_klass_offset;
D
duke 已提交
224

225 226
  static int _oop_size_offset;
  static int _static_oop_field_count_offset;
227

228 229 230 231
  static int _protection_domain_offset;
  static int _init_lock_offset;
  static int _signers_offset;

D
duke 已提交
232 233
  static bool offsets_computed;
  static int classRedefinedCount_offset;
234
  static GrowableArray<Klass*>* _fixup_mirror_list;
D
duke 已提交
235

236
  static void set_init_lock(oop java_class, oop init_lock);
237
  static void set_protection_domain(oop java_class, oop protection_domain);
D
duke 已提交
238
 public:
239 240
  static void compute_offsets();

D
duke 已提交
241
  // Instance creation
242
  static oop  create_mirror(KlassHandle k, Handle protection_domain, TRAPS);
243
  static void fixup_mirror(KlassHandle k, TRAPS);
D
duke 已提交
244 245
  static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
  // Conversion
246 247 248
  static Klass* as_Klass(oop java_class);
  static void set_klass(oop java_class, Klass* klass);
  static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL);
249
  static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
250
    Klass* refk_oop = NULL;
251 252 253 254
    BasicType result = as_BasicType(java_class, &refk_oop);
    (*reference_klass) = KlassHandle(refk_oop);
    return result;
  }
255
  static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS);
256
  static void print_signature(oop java_class, outputStream *st);
D
duke 已提交
257
  // Testing
258
  static bool is_instance(oop obj) {
259
    return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
260
  }
D
duke 已提交
261 262 263 264
  static bool is_primitive(oop java_class);
  static BasicType primitive_type(oop java_class);
  static oop primitive_mirror(BasicType t);
  // JVM_NewArray support
265 266
  static Klass* array_klass(oop java_class);
  static void set_array_klass(oop java_class, Klass* klass);
D
duke 已提交
267
  // compiler support for class operations
268 269
  static int klass_offset_in_bytes()                { return _klass_offset; }
  static int array_klass_offset_in_bytes()          { return _array_klass_offset; }
D
duke 已提交
270 271 272
  // Support for classRedefinedCount field
  static int classRedefinedCount(oop the_class_mirror);
  static void set_classRedefinedCount(oop the_class_mirror, int value);
273

274 275 276 277 278 279
  // Support for embedded per-class oops
  static oop  protection_domain(oop java_class);
  static oop  init_lock(oop java_class);
  static objArrayOop  signers(oop java_class);
  static void set_signers(oop java_class, objArrayOop signers);

280 281 282 283 284
  static int oop_size(oop java_class);
  static void set_oop_size(oop java_class, int size);
  static int static_oop_field_count(oop java_class);
  static void set_static_oop_field_count(oop java_class, int size);

285 286 287 288 289 290
  static GrowableArray<Klass*>* fixup_mirror_list() {
    return _fixup_mirror_list;
  }
  static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
    _fixup_mirror_list = v;
  }
D
duke 已提交
291 292
  // Debugging
  friend class JavaClasses;
293
  friend class InstanceKlass;   // verification code accesses offsets
D
duke 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
  friend class ClassFileParser; // access to number_of_fake_fields
};

// Interface to java.lang.Thread objects

class java_lang_Thread : AllStatic {
 private:
  // Note that for this class the layout changed between JDK1.2 and JDK1.3,
  // so we compute the offsets at startup rather than hard-wiring them.
  static int _name_offset;
  static int _group_offset;
  static int _contextClassLoader_offset;
  static int _inheritedAccessControlContext_offset;
  static int _priority_offset;
  static int _eetop_offset;
  static int _daemon_offset;
  static int _stillborn_offset;
  static int _stackSize_offset;
  static int _tid_offset;
  static int _thread_status_offset;
  static int _park_blocker_offset;
  static int _park_event_offset ;

  static void compute_offsets();

 public:
  // Instance creation
  static oop create();
  // Returns the JavaThread associated with the thread obj
  static JavaThread* thread(oop java_thread);
  // Set JavaThread for instance
  static void set_thread(oop java_thread, JavaThread* thread);
  // Name
  static typeArrayOop name(oop java_thread);
  static void set_name(oop java_thread, typeArrayOop name);
  // Priority
  static ThreadPriority priority(oop java_thread);
  static void set_priority(oop java_thread, ThreadPriority priority);
  // Thread group
  static oop  threadGroup(oop java_thread);
  // Stillborn
  static bool is_stillborn(oop java_thread);
  static void set_stillborn(oop java_thread);
  // Alive (NOTE: this is not really a field, but provides the correct
  // definition without doing a Java call)
  static bool is_alive(oop java_thread);
  // Daemon
  static bool is_daemon(oop java_thread);
  static void set_daemon(oop java_thread);
  // Context ClassLoader
  static oop context_class_loader(oop java_thread);
  // Control context
  static oop inherited_access_control_context(oop java_thread);
  // Stack size hint
  static jlong stackSize(oop java_thread);
  // Thread ID
  static jlong thread_id(oop java_thread);

  // Blocker object responsible for thread parking
  static oop park_blocker(oop java_thread);

  // Pointer to type-stable park handler, encoded as jlong.
  // Should be set when apparently null
  // For details, see unsafe.cpp Unsafe_Unpark
  static jlong park_event(oop java_thread);
  static bool set_park_event(oop java_thread, jlong ptr);

  // Java Thread Status for JVMTI and M&M use.
  // This thread status info is saved in threadStatus field of
  // java.lang.Thread java class.
  enum ThreadStatus {
    NEW                      = 0,
    RUNNABLE                 = JVMTI_THREAD_STATE_ALIVE +          // runnable / running
                               JVMTI_THREAD_STATE_RUNNABLE,
    SLEEPING                 = JVMTI_THREAD_STATE_ALIVE +          // Thread.sleep()
                               JVMTI_THREAD_STATE_WAITING +
                               JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
                               JVMTI_THREAD_STATE_SLEEPING,
    IN_OBJECT_WAIT           = JVMTI_THREAD_STATE_ALIVE +          // Object.wait()
                               JVMTI_THREAD_STATE_WAITING +
                               JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
                               JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
    IN_OBJECT_WAIT_TIMED     = JVMTI_THREAD_STATE_ALIVE +          // Object.wait(long)
                               JVMTI_THREAD_STATE_WAITING +
                               JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
                               JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
    PARKED                   = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park()
                               JVMTI_THREAD_STATE_WAITING +
                               JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
                               JVMTI_THREAD_STATE_PARKED,
    PARKED_TIMED             = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park(long)
                               JVMTI_THREAD_STATE_WAITING +
                               JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
                               JVMTI_THREAD_STATE_PARKED,
    BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE +          // (re-)entering a synchronization block
                               JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
    TERMINATED               = JVMTI_THREAD_STATE_TERMINATED
  };
  // Write thread status info to threadStatus field of java.lang.Thread.
  static void set_thread_status(oop java_thread_oop, ThreadStatus status);
  // Read thread status info from threadStatus field of java.lang.Thread.
  static ThreadStatus get_thread_status(oop java_thread_oop);

  static const char*  thread_status_name(oop java_thread_oop);

  // Debugging
  friend class JavaClasses;
};

// Interface to java.lang.ThreadGroup objects

class java_lang_ThreadGroup : AllStatic {
 private:
  static int _parent_offset;
  static int _name_offset;
  static int _threads_offset;
  static int _groups_offset;
  static int _maxPriority_offset;
  static int _destroyed_offset;
  static int _daemon_offset;
  static int _vmAllowSuspension_offset;
  static int _nthreads_offset;
  static int _ngroups_offset;

  static void compute_offsets();

 public:
  // parent ThreadGroup
  static oop  parent(oop java_thread_group);
  // name
  static typeArrayOop name(oop java_thread_group);
  // ("name as oop" accessor is not necessary)
  // Number of threads in group
  static int nthreads(oop java_thread_group);
  // threads
  static objArrayOop threads(oop java_thread_group);
  // Number of threads in group
  static int ngroups(oop java_thread_group);
  // groups
  static objArrayOop groups(oop java_thread_group);
  // maxPriority in group
  static ThreadPriority maxPriority(oop java_thread_group);
  // Destroyed
  static bool is_destroyed(oop java_thread_group);
  // Daemon
  static bool is_daemon(oop java_thread_group);
  // vmAllowSuspension
  static bool is_vmAllowSuspension(oop java_thread_group);
  // Debugging
  friend class JavaClasses;
};



// Interface to java.lang.Throwable objects

class java_lang_Throwable: AllStatic {
  friend class BacktraceBuilder;

 private:
  // Offsets
  enum {
    hc_backtrace_offset     =  0,
    hc_detailMessage_offset =  1,
    hc_cause_offset         =  2,  // New since 1.4
    hc_stackTrace_offset    =  3   // New since 1.4
  };
461 462 463
  enum {
      hc_static_unassigned_stacktrace_offset = 0  // New since 1.7
  };
D
duke 已提交
464 465 466 467
  // Trace constants
  enum {
    trace_methods_offset = 0,
    trace_bcis_offset    = 1,
468 469 470
    trace_mirrors_offset = 2,
    trace_next_offset    = 3,
    trace_size           = 4,
D
duke 已提交
471 472 473 474 475 476 477
    trace_chunk_size     = 32
  };

  static int backtrace_offset;
  static int detailMessage_offset;
  static int cause_offset;
  static int stackTrace_offset;
478
  static int static_unassigned_stacktrace_offset;
D
duke 已提交
479 480

  // Printing
481
  static char* print_stack_element_to_buffer(Handle mirror, int method, int version, int bci);
D
duke 已提交
482 483 484 485
  // StackTrace (programmatic access, new since 1.4)
  static void clear_stacktrace(oop throwable);
  // No stack trace available
  static const char* no_stack_trace_message();
486 487 488
  // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
  static void set_stacktrace(oop throwable, oop st_element_array);
  static oop unassigned_stacktrace();
D
duke 已提交
489 490 491 492 493 494 495 496 497 498 499 500

 public:
  // Backtrace
  static oop backtrace(oop throwable);
  static void set_backtrace(oop throwable, oop value);
  // Needed by JVMTI to filter out this internal field.
  static int get_backtrace_offset() { return backtrace_offset;}
  static int get_detailMessage_offset() { return detailMessage_offset;}
  // Message
  static oop message(oop throwable);
  static oop message(Handle throwable);
  static void set_message(oop throwable, oop value);
501 502 503
  static void print_stack_element(outputStream *st, Handle mirror, int method,
                                  int version, int bci);
  static void print_stack_element(outputStream *st, methodHandle method, int bci);
D
duke 已提交
504 505 506 507 508 509 510
  static void print_stack_usage(Handle stream);

  // Allocate space for backtrace (created but stack trace not filled in)
  static void allocate_backtrace(Handle throwable, TRAPS);
  // Fill in current stack trace for throwable with preallocated backtrace (no GC)
  static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
  // Fill in current stack trace, can cause GC
511 512
  static void fill_in_stack_trace(Handle throwable, methodHandle method, TRAPS);
  static void fill_in_stack_trace(Handle throwable, methodHandle method = methodHandle());
D
duke 已提交
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
  // Programmatic access to stack trace
  static oop  get_stack_trace_element(oop throwable, int index, TRAPS);
  static int  get_stack_trace_depth(oop throwable, TRAPS);
  // Printing
  static void print(oop throwable, outputStream* st);
  static void print(Handle throwable, outputStream* st);
  static void print_stack_trace(oop throwable, outputStream* st);
  // Debugging
  friend class JavaClasses;
};


// Interface to java.lang.reflect.AccessibleObject objects

class java_lang_reflect_AccessibleObject: AllStatic {
 private:
  // Note that to reduce dependencies on the JDK we compute these
  // offsets at run-time.
  static int override_offset;

  static void compute_offsets();

 public:
  // Accessors
  static jboolean override(oop reflect);
  static void set_override(oop reflect, jboolean value);

  // Debugging
  friend class JavaClasses;
};


// Interface to java.lang.reflect.Method objects

class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
 private:
  // Note that to reduce dependencies on the JDK we compute these
  // offsets at run-time.
  static int clazz_offset;
  static int name_offset;
  static int returnType_offset;
  static int parameterTypes_offset;
  static int exceptionTypes_offset;
  static int slot_offset;
  static int modifiers_offset;
  static int signature_offset;
  static int annotations_offset;
  static int parameter_annotations_offset;
  static int annotation_default_offset;
562
  static int type_annotations_offset;
D
duke 已提交
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607

  static void compute_offsets();

 public:
  // Allocation
  static Handle create(TRAPS);

  // Accessors
  static oop clazz(oop reflect);
  static void set_clazz(oop reflect, oop value);

  static oop name(oop method);
  static void set_name(oop method, oop value);

  static oop return_type(oop method);
  static void set_return_type(oop method, oop value);

  static oop parameter_types(oop method);
  static void set_parameter_types(oop method, oop value);

  static oop exception_types(oop method);
  static void set_exception_types(oop method, oop value);

  static int slot(oop reflect);
  static void set_slot(oop reflect, int value);

  static int modifiers(oop method);
  static void set_modifiers(oop method, int value);

  static bool has_signature_field();
  static oop signature(oop method);
  static void set_signature(oop method, oop value);

  static bool has_annotations_field();
  static oop annotations(oop method);
  static void set_annotations(oop method, oop value);

  static bool has_parameter_annotations_field();
  static oop parameter_annotations(oop method);
  static void set_parameter_annotations(oop method, oop value);

  static bool has_annotation_default_field();
  static oop annotation_default(oop method);
  static void set_annotation_default(oop method, oop value);

608 609 610 611
  static bool has_type_annotations_field();
  static oop type_annotations(oop method);
  static void set_type_annotations(oop method, oop value);

D
duke 已提交
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
  // Debugging
  friend class JavaClasses;
};


// Interface to java.lang.reflect.Constructor objects

class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
 private:
  // Note that to reduce dependencies on the JDK we compute these
  // offsets at run-time.
  static int clazz_offset;
  static int parameterTypes_offset;
  static int exceptionTypes_offset;
  static int slot_offset;
  static int modifiers_offset;
  static int signature_offset;
  static int annotations_offset;
  static int parameter_annotations_offset;
631
  static int type_annotations_offset;
D
duke 已提交
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666

  static void compute_offsets();

 public:
  // Allocation
  static Handle create(TRAPS);

  // Accessors
  static oop clazz(oop reflect);
  static void set_clazz(oop reflect, oop value);

  static oop parameter_types(oop constructor);
  static void set_parameter_types(oop constructor, oop value);

  static oop exception_types(oop constructor);
  static void set_exception_types(oop constructor, oop value);

  static int slot(oop reflect);
  static void set_slot(oop reflect, int value);

  static int modifiers(oop constructor);
  static void set_modifiers(oop constructor, int value);

  static bool has_signature_field();
  static oop signature(oop constructor);
  static void set_signature(oop constructor, oop value);

  static bool has_annotations_field();
  static oop annotations(oop constructor);
  static void set_annotations(oop constructor, oop value);

  static bool has_parameter_annotations_field();
  static oop parameter_annotations(oop method);
  static void set_parameter_annotations(oop method, oop value);

667 668 669 670
  static bool has_type_annotations_field();
  static oop type_annotations(oop constructor);
  static void set_type_annotations(oop constructor, oop value);

D
duke 已提交
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
  // Debugging
  friend class JavaClasses;
};


// Interface to java.lang.reflect.Field objects

class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
 private:
  // Note that to reduce dependencies on the JDK we compute these
  // offsets at run-time.
  static int clazz_offset;
  static int name_offset;
  static int type_offset;
  static int slot_offset;
  static int modifiers_offset;
  static int signature_offset;
  static int annotations_offset;
689
  static int type_annotations_offset;
D
duke 已提交
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728

  static void compute_offsets();

 public:
  // Allocation
  static Handle create(TRAPS);

  // Accessors
  static oop clazz(oop reflect);
  static void set_clazz(oop reflect, oop value);

  static oop name(oop field);
  static void set_name(oop field, oop value);

  static oop type(oop field);
  static void set_type(oop field, oop value);

  static int slot(oop reflect);
  static void set_slot(oop reflect, int value);

  static int modifiers(oop field);
  static void set_modifiers(oop field, int value);

  static bool has_signature_field();
  static oop signature(oop constructor);
  static void set_signature(oop constructor, oop value);

  static bool has_annotations_field();
  static oop annotations(oop constructor);
  static void set_annotations(oop constructor, oop value);

  static bool has_parameter_annotations_field();
  static oop parameter_annotations(oop method);
  static void set_parameter_annotations(oop method, oop value);

  static bool has_annotation_default_field();
  static oop annotation_default(oop method);
  static void set_annotation_default(oop method, oop value);

729 730 731 732
  static bool has_type_annotations_field();
  static oop type_annotations(oop field);
  static void set_type_annotations(oop field, oop value);

D
duke 已提交
733 734 735 736
  // Debugging
  friend class JavaClasses;
};

737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
class java_lang_reflect_Parameter {
 private:
  // Note that to reduce dependencies on the JDK we compute these
  // offsets at run-time.
  static int name_offset;
  static int modifiers_offset;
  static int index_offset;
  static int executable_offset;

  static void compute_offsets();

 public:
  // Allocation
  static Handle create(TRAPS);

  // Accessors
  static oop name(oop field);
  static void set_name(oop field, oop value);

  static int index(oop reflect);
  static void set_index(oop reflect, int value);

  static int modifiers(oop reflect);
  static void set_modifiers(oop reflect, int value);

  static oop executable(oop constructor);
  static void set_executable(oop constructor, oop value);

  friend class JavaClasses;
};

D
duke 已提交
768 769 770 771 772
// Interface to sun.reflect.ConstantPool objects
class sun_reflect_ConstantPool {
 private:
  // Note that to reduce dependencies on the JDK we compute these
  // offsets at run-time.
773
  static int _oop_offset;
D
duke 已提交
774 775 776 777 778 779 780 781

  static void compute_offsets();

 public:
  // Allocation
  static Handle create(TRAPS);

  // Accessors
782 783 784
  static void set_cp(oop reflect, ConstantPool* value);
  static int oop_offset() {
    return _oop_offset;
D
duke 已提交
785 786
  }

787 788
  static ConstantPool* get_cp(oop reflect);

D
duke 已提交
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
  // Debugging
  friend class JavaClasses;
};

// Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
class sun_reflect_UnsafeStaticFieldAccessorImpl {
 private:
  static int _base_offset;
  static void compute_offsets();

 public:
  static int base_offset() {
    return _base_offset;
  }

  // Debugging
  friend class JavaClasses;
};

// Interface to java.lang primitive type boxing objects:
//  - java.lang.Boolean
//  - java.lang.Character
//  - java.lang.Float
//  - java.lang.Double
//  - java.lang.Byte
//  - java.lang.Short
//  - java.lang.Integer
//  - java.lang.Long

// This could be separated out into 8 individual classes.

class java_lang_boxing_object: AllStatic {
 private:
  enum {
   hc_value_offset = 0
  };
  static int value_offset;
826
  static int long_value_offset;
D
duke 已提交
827

828
  static oop initialize_and_allocate(BasicType type, TRAPS);
D
duke 已提交
829 830 831 832 833 834
 public:
  // Allocation. Returns a boxed value, or NULL for invalid type.
  static oop create(BasicType type, jvalue* value, TRAPS);
  // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
  static BasicType get_value(oop box, jvalue* value);
  static BasicType set_value(oop box, jvalue* value);
835 836 837
  static BasicType basic_type(oop box);
  static bool is_instance(oop box)                 { return basic_type(box) != T_ILLEGAL; }
  static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
838 839
  static void print(oop box, outputStream* st)     { jvalue value;  print(get_value(box, &value), &value, st); }
  static void print(BasicType type, jvalue* value, outputStream* st);
D
duke 已提交
840

841 842 843 844
  static int value_offset_in_bytes(BasicType type) {
    return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :
                                                    value_offset;
  }
D
duke 已提交
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875

  // Debugging
  friend class JavaClasses;
};



// Interface to java.lang.ref.Reference objects

class java_lang_ref_Reference: AllStatic {
 public:
  enum {
   hc_referent_offset   = 0,
   hc_queue_offset      = 1,
   hc_next_offset       = 2,
   hc_discovered_offset = 3  // Is not last, see SoftRefs.
  };
  enum {
   hc_static_lock_offset    = 0,
   hc_static_pending_offset = 1
  };

  static int referent_offset;
  static int queue_offset;
  static int next_offset;
  static int discovered_offset;
  static int static_lock_offset;
  static int static_pending_offset;
  static int number_of_fake_oop_fields;

  // Accessors
876 877 878 879 880 881 882
  static oop referent(oop ref) {
    return ref->obj_field(referent_offset);
  }
  static void set_referent(oop ref, oop value) {
    ref->obj_field_put(referent_offset, value);
  }
  static void set_referent_raw(oop ref, oop value) {
883
    ref->obj_field_put_raw(referent_offset, value);
884 885 886 887 888 889 890 891 892 893 894
  }
  static HeapWord* referent_addr(oop ref) {
    return ref->obj_field_addr<HeapWord>(referent_offset);
  }
  static oop next(oop ref) {
    return ref->obj_field(next_offset);
  }
  static void set_next(oop ref, oop value) {
    ref->obj_field_put(next_offset, value);
  }
  static void set_next_raw(oop ref, oop value) {
895
    ref->obj_field_put_raw(next_offset, value);
896 897 898 899 900 901 902 903 904 905 906
  }
  static HeapWord* next_addr(oop ref) {
    return ref->obj_field_addr<HeapWord>(next_offset);
  }
  static oop discovered(oop ref) {
    return ref->obj_field(discovered_offset);
  }
  static void set_discovered(oop ref, oop value) {
    ref->obj_field_put(discovered_offset, value);
  }
  static void set_discovered_raw(oop ref, oop value) {
907
    ref->obj_field_put_raw(discovered_offset, value);
908 909 910 911
  }
  static HeapWord* discovered_addr(oop ref) {
    return ref->obj_field_addr<HeapWord>(discovered_offset);
  }
D
duke 已提交
912
  // Accessors for statics
913 914
  static oop  pending_list_lock();
  static oop  pending_list();
D
duke 已提交
915

916
  static HeapWord*  pending_list_lock_addr();
917
  static HeapWord*  pending_list_addr();
D
duke 已提交
918 919 920 921 922 923 924 925 926
};


// Interface to java.lang.ref.SoftReference objects

class java_lang_ref_SoftReference: public java_lang_ref_Reference {
 public:
  enum {
   // The timestamp is a long field and may need to be adjusted for alignment.
927
   hc_timestamp_offset  = hc_discovered_offset + 1
D
duke 已提交
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
  };
  enum {
   hc_static_clock_offset = 0
  };

  static int timestamp_offset;
  static int static_clock_offset;

  // Accessors
  static jlong timestamp(oop ref);

  // Accessors for statics
  static jlong clock();
  static void set_clock(jlong value);
};


945
// Interface to java.lang.invoke.MethodHandle objects
946 947 948

class MethodHandleEntry;

949
class java_lang_invoke_MethodHandle: AllStatic {
950 951 952
  friend class JavaClasses;

 private:
953 954
  static int _type_offset;               // the MethodType of this MH
  static int _form_offset;               // the LambdaForm of this MH
955 956 957 958 959 960 961 962

  static void compute_offsets();

 public:
  // Accessors
  static oop            type(oop mh);
  static void       set_type(oop mh, oop mtype);

963 964
  static oop            form(oop mh);
  static void       set_form(oop mh, oop lform);
965 966

  // Testers
967
  static bool is_subclass(Klass* klass) {
H
hseigel 已提交
968
    return klass->is_subclass_of(SystemDictionary::MethodHandle_klass());
969 970 971 972 973 974 975
  }
  static bool is_instance(oop obj) {
    return obj != NULL && is_subclass(obj->klass());
  }

  // Accessors for code generation:
  static int type_offset_in_bytes()             { return _type_offset; }
976
  static int form_offset_in_bytes()             { return _form_offset; }
977 978
};

979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
// Interface to java.lang.invoke.DirectMethodHandle objects

class java_lang_invoke_DirectMethodHandle: AllStatic {
  friend class JavaClasses;

 private:
  static int _member_offset;               // the MemberName of this DMH

  static void compute_offsets();

 public:
  // Accessors
  static oop  member(oop mh);

  // Testers
  static bool is_subclass(Klass* klass) {
    return klass->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
  }
  static bool is_instance(oop obj) {
    return obj != NULL && is_subclass(obj->klass());
  }

  // Accessors for code generation:
  static int member_offset_in_bytes()           { return _member_offset; }
};

1005 1006
// Interface to java.lang.invoke.LambdaForm objects
// (These are a private interface for managing adapter code generation.)
1007

1008
class java_lang_invoke_LambdaForm: AllStatic {
1009 1010 1011
  friend class JavaClasses;

 private:
1012
  static int _vmentry_offset;  // type is MemberName
1013

1014 1015 1016 1017
  static void compute_offsets();

 public:
  // Accessors
1018 1019
  static oop            vmentry(oop lform);
  static void       set_vmentry(oop lform, oop invoker);
1020 1021

  // Testers
1022
  static bool is_subclass(Klass* klass) {
1023
    return SystemDictionary::LambdaForm_klass() != NULL &&
H
hseigel 已提交
1024
      klass->is_subclass_of(SystemDictionary::LambdaForm_klass());
1025 1026 1027 1028 1029 1030
  }
  static bool is_instance(oop obj) {
    return obj != NULL && is_subclass(obj->klass());
  }

  // Accessors for code generation:
1031
  static int vmentry_offset_in_bytes()          { return _vmentry_offset; }
1032 1033 1034
};


1035
// Interface to java.lang.invoke.MemberName objects
1036 1037
// (These are a private interface for Java code to query the class hierarchy.)

1038
#define MEMBERNAME_INJECTED_FIELDS(macro)                               \
1039
  macro(java_lang_invoke_MemberName, vmloader, object_signature, false) \
1040
  macro(java_lang_invoke_MemberName, vmindex,  intptr_signature, false) \
1041
  macro(java_lang_invoke_MemberName, vmtarget, intptr_signature, false)
1042

1043
class java_lang_invoke_MemberName: AllStatic {
1044 1045 1046
  friend class JavaClasses;

 private:
1047
  // From java.lang.invoke.MemberName:
1048 1049 1050 1051
  //    private Class<?>   clazz;       // class in which the method is defined
  //    private String     name;        // may be null if not yet materialized
  //    private Object     type;        // may be null if not yet materialized
  //    private int        flags;       // modifier bits; see reflect.Modifier
1052
  //    private intptr     vmtarget;    // VM-specific target value
1053
  //    private intptr_t   vmindex;     // member index within class or interface
1054 1055 1056 1057 1058
  static int _clazz_offset;
  static int _name_offset;
  static int _type_offset;
  static int _flags_offset;
  static int _vmtarget_offset;
1059
  static int _vmloader_offset;
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
  static int _vmindex_offset;

  static void compute_offsets();

 public:
  // Accessors
  static oop            clazz(oop mname);
  static void       set_clazz(oop mname, oop clazz);

  static oop            type(oop mname);
  static void       set_type(oop mname, oop type);

  static oop            name(oop mname);
  static void       set_name(oop mname, oop name);

  static int            flags(oop mname);
  static void       set_flags(oop mname, int flags);

1078 1079
  static Metadata*      vmtarget(oop mname);
  static void       set_vmtarget(oop mname, Metadata* target);
1080 1081 1082
#if INCLUDE_JVMTI
  static void       adjust_vmtarget(oop mname, Metadata* target);
#endif // INCLUDE_JVMTI
1083

1084 1085
  static intptr_t       vmindex(oop mname);
  static void       set_vmindex(oop mname, intptr_t index);
1086 1087

  // Testers
1088
  static bool is_subclass(Klass* klass) {
H
hseigel 已提交
1089
    return klass->is_subclass_of(SystemDictionary::MemberName_klass());
1090 1091 1092 1093 1094 1095 1096
  }
  static bool is_instance(oop obj) {
    return obj != NULL && is_subclass(obj->klass());
  }

  // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
  enum {
1097 1098 1099 1100 1101
    MN_IS_METHOD            = 0x00010000, // method (not constructor)
    MN_IS_CONSTRUCTOR       = 0x00020000, // constructor
    MN_IS_FIELD             = 0x00040000, // field
    MN_IS_TYPE              = 0x00080000, // nested type
    MN_CALLER_SENSITIVE     = 0x00100000, // @CallerSensitive annotation detected
1102
    MN_REFERENCE_KIND_SHIFT = 24, // refKind
1103
    MN_REFERENCE_KIND_MASK  = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1104
    // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
1105 1106
    MN_SEARCH_SUPERCLASSES  = 0x00100000, // walk super classes
    MN_SEARCH_INTERFACES    = 0x00200000  // walk implemented interfaces
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
  };

  // Accessors for code generation:
  static int clazz_offset_in_bytes()            { return _clazz_offset; }
  static int type_offset_in_bytes()             { return _type_offset; }
  static int name_offset_in_bytes()             { return _name_offset; }
  static int flags_offset_in_bytes()            { return _flags_offset; }
  static int vmtarget_offset_in_bytes()         { return _vmtarget_offset; }
  static int vmindex_offset_in_bytes()          { return _vmindex_offset; }
};


1119
// Interface to java.lang.invoke.MethodType objects
1120

1121
class java_lang_invoke_MethodType: AllStatic {
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
  friend class JavaClasses;

 private:
  static int _rtype_offset;
  static int _ptypes_offset;

  static void compute_offsets();

 public:
  // Accessors
  static oop            rtype(oop mt);
  static objArrayOop    ptypes(oop mt);

  static oop            ptype(oop mt, int index);
1136
  static int            ptype_count(oop mt);
1137

1138 1139 1140
  static int            ptype_slot_count(oop mt);  // extra counts for long/double
  static int            rtype_slot_count(oop mt);  // extra counts for long/double

1141
  static Symbol*        as_signature(oop mt, bool intern_if_not_found, TRAPS);
1142 1143 1144 1145 1146 1147
  static void           print_signature(oop mt, outputStream* st);

  static bool is_instance(oop obj) {
    return obj != NULL && obj->klass() == SystemDictionary::MethodType_klass();
  }

1148 1149
  static bool equals(oop mt1, oop mt2);

1150 1151 1152 1153 1154 1155
  // Accessors for code generation:
  static int rtype_offset_in_bytes()            { return _rtype_offset; }
  static int ptypes_offset_in_bytes()           { return _ptypes_offset; }
};


1156
// Interface to java.lang.invoke.CallSite objects
1157

1158
class java_lang_invoke_CallSite: AllStatic {
1159 1160 1161 1162 1163 1164 1165 1166 1167
  friend class JavaClasses;

private:
  static int _target_offset;

  static void compute_offsets();

public:
  // Accessors
1168 1169
  static oop              target(         oop site)             { return site->obj_field(             _target_offset);         }
  static void         set_target(         oop site, oop target) {        site->obj_field_put(         _target_offset, target); }
1170

1171 1172
  static volatile oop     target_volatile(oop site)             { return site->obj_field_volatile(    _target_offset);         }
  static void         set_target_volatile(oop site, oop target) {        site->obj_field_put_volatile(_target_offset, target); }
1173

1174
  // Testers
1175
  static bool is_subclass(Klass* klass) {
H
hseigel 已提交
1176
    return klass->is_subclass_of(SystemDictionary::CallSite_klass());
1177 1178 1179 1180 1181
  }
  static bool is_instance(oop obj) {
    return obj != NULL && is_subclass(obj->klass());
  }

1182 1183 1184
  // Accessors for code generation:
  static int target_offset_in_bytes()           { return _target_offset; }
};
1185 1186


D
duke 已提交
1187 1188 1189 1190 1191 1192 1193 1194 1195
// Interface to java.security.AccessControlContext objects

class java_security_AccessControlContext: AllStatic {
 private:
  // Note that for this class the layout changed between JDK1.2 and JDK1.3,
  // so we compute the offsets at startup rather than hard-wiring them.
  static int _context_offset;
  static int _privilegedContext_offset;
  static int _isPrivileged_offset;
M
mullan 已提交
1196
  static int _isAuthorized_offset;
D
duke 已提交
1197 1198 1199 1200 1201

  static void compute_offsets();
 public:
  static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);

M
mullan 已提交
1202 1203
  static bool is_authorized(Handle context);

D
duke 已提交
1204 1205 1206 1207 1208 1209 1210
  // Debugging/initialization
  friend class JavaClasses;
};


// Interface to java.lang.ClassLoader objects

1211
#define CLASSLOADER_INJECTED_FIELDS(macro)                            \
1212
  macro(java_lang_ClassLoader, loader_data,  intptr_signature, false)
1213

D
duke 已提交
1214 1215
class java_lang_ClassLoader : AllStatic {
 private:
1216
  // The fake offsets are added by the class loader when java.lang.Class is loaded
D
duke 已提交
1217 1218 1219
  enum {
   hc_parent_offset = 0
  };
1220
  static int _loader_data_offset;
1221
  static bool offsets_computed;
D
duke 已提交
1222
  static int parent_offset;
1223 1224
  static int parallelCapable_offset;

1225
 public:
1226
  static void compute_offsets();
D
duke 已提交
1227

1228 1229 1230
  static ClassLoaderData** loader_data_addr(oop loader);
  static ClassLoaderData* loader_data(oop loader);

D
duke 已提交
1231
  static oop parent(oop loader);
1232
  static bool isAncestor(oop loader, oop cl);
D
duke 已提交
1233

1234 1235 1236
  // Support for parallelCapable field
  static bool parallelCapable(oop the_class_mirror);

D
duke 已提交
1237 1238 1239 1240 1241
  static bool is_trusted_loader(oop loader);

  // Fix for 4474172
  static oop  non_reflection_class_loader(oop loader);

1242
  // Testers
1243
  static bool is_subclass(Klass* klass) {
H
hseigel 已提交
1244
    return klass->is_subclass_of(SystemDictionary::ClassLoader_klass());
1245 1246 1247 1248 1249
  }
  static bool is_instance(oop obj) {
    return obj != NULL && is_subclass(obj->klass());
  }

D
duke 已提交
1250 1251
  // Debugging
  friend class JavaClasses;
1252
  friend class ClassFileParser; // access to number_of_fake_fields
D
duke 已提交
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
};


// Interface to java.lang.System objects

class java_lang_System : AllStatic {
 private:
  enum {
   hc_static_in_offset  = 0,
   hc_static_out_offset = 1,
M
mullan 已提交
1263 1264
   hc_static_err_offset = 2,
   hc_static_security_offset = 3
D
duke 已提交
1265 1266 1267 1268 1269
  };

  static int  static_in_offset;
  static int static_out_offset;
  static int static_err_offset;
M
mullan 已提交
1270
  static int static_security_offset;
D
duke 已提交
1271 1272 1273 1274 1275 1276

 public:
  static int  in_offset_in_bytes();
  static int out_offset_in_bytes();
  static int err_offset_in_bytes();

M
mullan 已提交
1277 1278
  static bool has_security_manager();

D
duke 已提交
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
  // Debugging
  friend class JavaClasses;
};


// Interface to java.lang.StackTraceElement objects

class java_lang_StackTraceElement: AllStatic {
 private:
  enum {
    hc_declaringClass_offset  = 0,
    hc_methodName_offset = 1,
    hc_fileName_offset   = 2,
    hc_lineNumber_offset = 3
  };

  static int declaringClass_offset;
  static int methodName_offset;
  static int fileName_offset;
  static int lineNumber_offset;

 public:
  // Setters
  static void set_declaringClass(oop element, oop value);
  static void set_methodName(oop element, oop value);
  static void set_fileName(oop element, oop value);
  static void set_lineNumber(oop element, int value);

  // Create an instance of StackTraceElement
1308 1309
  static oop create(Handle mirror, int method, int version, int bci, TRAPS);
  static oop create(methodHandle method, int bci, TRAPS);
D
duke 已提交
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362

  // Debugging
  friend class JavaClasses;
};


// Interface to java.lang.AssertionStatusDirectives objects

class java_lang_AssertionStatusDirectives: AllStatic {
 private:
  enum {
    hc_classes_offset,
    hc_classEnabled_offset,
    hc_packages_offset,
    hc_packageEnabled_offset,
    hc_deflt_offset
  };

  static int classes_offset;
  static int classEnabled_offset;
  static int packages_offset;
  static int packageEnabled_offset;
  static int deflt_offset;

 public:
  // Setters
  static void set_classes(oop obj, oop val);
  static void set_classEnabled(oop obj, oop val);
  static void set_packages(oop obj, oop val);
  static void set_packageEnabled(oop obj, oop val);
  static void set_deflt(oop obj, bool val);
  // Debugging
  friend class JavaClasses;
};


class java_nio_Buffer: AllStatic {
 private:
  static int _limit_offset;

 public:
  static int  limit_offset();
  static void compute_offsets();
};

class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
 private:
  static int  _owner_offset;
 public:
  static void initialize(TRAPS);
  static oop  get_owner_threadObj(oop obj);
};

1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379
// Use to declare fields that need to be injected into Java classes
// for the JVM to use.  The name_index and signature_index are
// declared in vmSymbols.  The may_be_java flag is used to declare
// fields that might already exist in Java but should be injected if
// they don't.  Otherwise the field is unconditionally injected and
// the JVM uses the injected one.  This is to ensure that name
// collisions don't occur.  In general may_be_java should be false
// unless there's a good reason.

class InjectedField {
 public:
  const SystemDictionary::WKID klass_id;
  const vmSymbols::SID name_index;
  const vmSymbols::SID signature_index;
  const bool           may_be_java;


1380
  Klass* klass() const    { return SystemDictionary::well_known_klass(klass_id); }
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
  Symbol* name() const      { return lookup_symbol(name_index); }
  Symbol* signature() const { return lookup_symbol(signature_index); }

  int compute_offset();

  // Find the Symbol for this index
  static Symbol* lookup_symbol(int symbol_index) {
    return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
  }
};

#define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \
  klass##_##name##_enum,

#define ALL_INJECTED_FIELDS(macro)          \
  CLASS_INJECTED_FIELDS(macro)              \
1397
  CLASSLOADER_INJECTED_FIELDS(macro)        \
1398
  MEMBERNAME_INJECTED_FIELDS(macro)
1399

D
duke 已提交
1400 1401 1402 1403
// Interface to hard-coded offset checking

class JavaClasses : AllStatic {
 private:
1404 1405 1406

  static InjectedField _injected_fields[];

D
duke 已提交
1407 1408
  static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
  static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1409
  static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1410

D
duke 已提交
1411
 public:
1412 1413 1414 1415 1416 1417 1418
  enum InjectedFieldID {
    ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM)
    MAX_enum
  };

  static int compute_injected_offset(InjectedFieldID id);

D
duke 已提交
1419 1420 1421
  static void compute_hard_coded_offsets();
  static void compute_offsets();
  static void check_offsets() PRODUCT_RETURN;
1422 1423

  static InjectedField* get_injected(Symbol* class_name, int* field_count);
D
duke 已提交
1424
};
1425

1426 1427
#undef DECLARE_INJECTED_FIELD_ENUM

1428
#endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP