javaClasses.hpp revision 9248:6ab7e19c9220
111819Sjulian/*
211819Sjulian * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
311819Sjulian * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
411819Sjulian *
511819Sjulian * This code is free software; you can redistribute it and/or modify it
611819Sjulian * under the terms of the GNU General Public License version 2 only, as
711819Sjulian * published by the Free Software Foundation.
811819Sjulian *
911819Sjulian * This code is distributed in the hope that it will be useful, but WITHOUT
1011819Sjulian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1111819Sjulian * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1211819Sjulian * version 2 for more details (a copy is included in the LICENSE file that
1311819Sjulian * accompanied this code).
1411819Sjulian *
1511819Sjulian * You should have received a copy of the GNU General Public License version
1611819Sjulian * 2 along with this work; if not, write to the Free Software Foundation,
1711819Sjulian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1811819Sjulian *
1911819Sjulian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2011819Sjulian * or visit www.oracle.com if you need additional information or have any
2111819Sjulian * questions.
2211819Sjulian *
2311819Sjulian */
2411819Sjulian
2511819Sjulian#ifndef SHARE_VM_CLASSFILE_JAVACLASSES_HPP
2611819Sjulian#define SHARE_VM_CLASSFILE_JAVACLASSES_HPP
2711819Sjulian
2811819Sjulian#include "classfile/systemDictionary.hpp"
2911819Sjulian#include "jvmtifiles/jvmti.h"
3011819Sjulian#include "oops/oop.hpp"
3111819Sjulian#include "runtime/os.hpp"
3211819Sjulian#include "utilities/utf8.hpp"
3311819Sjulian
3412057Sjulian// Interface for manipulating the basic Java classes.
3512057Sjulian//
3612057Sjulian// All dependencies on layout of actual Java classes should be kept here.
3711819Sjulian// If the layout of any of the classes above changes the offsets must be adjusted.
3811819Sjulian//
3911819Sjulian// For most classes we hardwire the offsets for performance reasons. In certain
4011819Sjulian// cases (e.g. java.security.AccessControlContext) we compute the offsets at
4111819Sjulian// startup since the layout here differs between JDK1.2 and JDK1.3.
4211819Sjulian//
4311819Sjulian// Note that fields (static and non-static) are arranged with oops before non-oops
4411819Sjulian// on a per class basis. The offsets below have to reflect this ordering.
4511819Sjulian//
4611819Sjulian// When editing the layouts please update the check_offset verification code
4711819Sjulian// correspondingly. The names in the enums must be identical to the actual field
4811819Sjulian// names in order for the verification code to work.
4911819Sjulian
5011819Sjulian
5111819Sjulian// Interface to java.lang.String objects
5211819Sjulian
5311819Sjulianclass java_lang_String : AllStatic {
5411819Sjulian private:
5511819Sjulian  static int value_offset;
5611819Sjulian  static int offset_offset;
5711819Sjulian  static int count_offset;
5811819Sjulian  static int hash_offset;
5911819Sjulian
6011819Sjulian  static bool initialized;
6111819Sjulian
6211819Sjulian  static Handle basic_create(int length, TRAPS);
6311819Sjulian
6411819Sjulian  static void set_offset(oop string, int offset) {
6511819Sjulian    assert(initialized, "Must be initialized");
6611819Sjulian    if (offset_offset > 0) {
6711819Sjulian      string->int_field_put(offset_offset, offset);
6811819Sjulian    }
6911819Sjulian  }
7011819Sjulian  static void set_count( oop string, int count) {
7111819Sjulian    assert(initialized, "Must be initialized");
7211819Sjulian    if (count_offset > 0) {
7311819Sjulian      string->int_field_put(count_offset,  count);
7411819Sjulian    }
7511819Sjulian  }
7611819Sjulian
7711819Sjulian public:
7811819Sjulian  static void compute_offsets();
7911819Sjulian
8011819Sjulian  // Instance creation
8111819Sjulian  static Handle create_from_unicode(jchar* unicode, int len, TRAPS);
8211819Sjulian  static oop    create_oop_from_unicode(jchar* unicode, int len, TRAPS);
8311819Sjulian  static Handle create_from_str(const char* utf8_str, TRAPS);
8411819Sjulian  static oop    create_oop_from_str(const char* utf8_str, TRAPS);
8511819Sjulian  static Handle create_from_symbol(Symbol* symbol, TRAPS);
8611819Sjulian  static Handle create_from_platform_dependent_str(const char* str, TRAPS);
8711819Sjulian  static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS);
8811819Sjulian
8911819Sjulian  static bool has_offset_field()  {
9011819Sjulian    assert(initialized, "Must be initialized");
9111819Sjulian    return (offset_offset > 0);
9211819Sjulian  }
9311819Sjulian
9411819Sjulian  static bool has_count_field()  {
9511819Sjulian    assert(initialized, "Must be initialized");
9611819Sjulian    return (count_offset > 0);
9711819Sjulian  }
9811819Sjulian
9911819Sjulian  static bool has_hash_field()  {
10011819Sjulian    assert(initialized, "Must be initialized");
10111819Sjulian    return (hash_offset > 0);
10211819Sjulian  }
103
104  static int value_offset_in_bytes()  {
105    assert(initialized && (value_offset > 0), "Must be initialized");
106    return value_offset;
107  }
108  static int count_offset_in_bytes()  {
109    assert(initialized && (count_offset > 0), "Must be initialized");
110    return count_offset;
111  }
112  static int offset_offset_in_bytes() {
113    assert(initialized && (offset_offset > 0), "Must be initialized");
114    return offset_offset;
115  }
116  static int hash_offset_in_bytes()   {
117    assert(initialized && (hash_offset > 0), "Must be initialized");
118    return hash_offset;
119  }
120
121  static void set_value_raw(oop string, typeArrayOop buffer) {
122    assert(initialized, "Must be initialized");
123    string->obj_field_put_raw(value_offset, buffer);
124  }
125  static void set_value(oop string, typeArrayOop buffer) {
126    assert(initialized && (value_offset > 0), "Must be initialized");
127    string->obj_field_put(value_offset, (oop)buffer);
128  }
129  static void set_hash(oop string, unsigned int hash) {
130    assert(initialized && (hash_offset > 0), "Must be initialized");
131    string->int_field_put(hash_offset, hash);
132  }
133
134  // Accessors
135  static typeArrayOop value(oop java_string) {
136    assert(initialized && (value_offset > 0), "Must be initialized");
137    assert(is_instance(java_string), "must be java_string");
138    return (typeArrayOop) java_string->obj_field(value_offset);
139  }
140  static unsigned int hash(oop java_string) {
141    assert(initialized && (hash_offset > 0), "Must be initialized");
142    assert(is_instance(java_string), "must be java_string");
143    return java_string->int_field(hash_offset);
144  }
145  static int offset(oop java_string) {
146    assert(initialized, "Must be initialized");
147    assert(is_instance(java_string), "must be java_string");
148    if (offset_offset > 0) {
149      return java_string->int_field(offset_offset);
150    } else {
151      return 0;
152    }
153  }
154  static int length(oop java_string) {
155    assert(initialized, "Must be initialized");
156    assert(is_instance(java_string), "must be java_string");
157    if (count_offset > 0) {
158      return java_string->int_field(count_offset);
159    } else {
160      typeArrayOop value_array = ((typeArrayOop)java_string->obj_field(value_offset));
161      if (value_array == NULL) {
162        return 0;
163      } else {
164        return value_array->length();
165      }
166    }
167  }
168  static int utf8_length(oop java_string);
169
170  // String converters
171  static char*  as_utf8_string(oop java_string);
172  static char*  as_utf8_string(oop java_string, char* buf, int buflen);
173  static char*  as_utf8_string(oop java_string, int start, int len);
174  static char*  as_utf8_string(oop java_string, int start, int len, char* buf, int buflen);
175  static char*  as_platform_dependent_str(Handle java_string, TRAPS);
176  static jchar* as_unicode_string(oop java_string, int& length, TRAPS);
177  // produce an ascii string with all other values quoted using \u####
178  static char*  as_quoted_ascii(oop java_string);
179
180  // Compute the hash value for a java.lang.String object which would
181  // contain the characters passed in.
182  //
183  // As the hash value used by the String object itself, in
184  // String.hashCode().  This value is normally calculated in Java code
185  // in the String.hashCode method(), but is precomputed for String
186  // objects in the shared archive file.
187  // hash P(31) from Kernighan & Ritchie
188  //
189  // For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
190  template <typename T> static unsigned int hash_code(T* s, int len) {
191    unsigned int h = 0;
192    while (len-- > 0) {
193      h = 31*h + (unsigned int) *s;
194      s++;
195    }
196    return h;
197  }
198  static unsigned int hash_code(oop java_string);
199
200  // This is the string hash code used by the StringTable, which may be
201  // the same as String.hashCode or an alternate hash code.
202  static unsigned int hash_string(oop java_string);
203
204  static bool equals(oop java_string, jchar* chars, int len);
205  static bool equals(oop str1, oop str2);
206
207  // Conversion between '.' and '/' formats
208  static Handle externalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '/', '.', THREAD); }
209  static Handle internalize_classname(Handle java_string, TRAPS) { return char_converter(java_string, '.', '/', THREAD); }
210
211  // Conversion
212  static Symbol* as_symbol(Handle java_string, TRAPS);
213  static Symbol* as_symbol_or_null(oop java_string);
214
215  // Testers
216  static bool is_instance(oop obj);
217  static bool is_instance_inlined(oop obj);
218
219  // Debugging
220  static void print(oop java_string, outputStream* st);
221  friend class JavaClasses;
222  friend class StringTable;
223};
224
225
226// Interface to java.lang.Class objects
227
228#define CLASS_INJECTED_FIELDS(macro)                                       \
229  macro(java_lang_Class, klass,                  intptr_signature,  false) \
230  macro(java_lang_Class, array_klass,            intptr_signature,  false) \
231  macro(java_lang_Class, oop_size,               int_signature,     false) \
232  macro(java_lang_Class, static_oop_field_count, int_signature,     false) \
233  macro(java_lang_Class, protection_domain,      object_signature,  false) \
234  macro(java_lang_Class, signers,                object_signature,  false)
235
236class java_lang_Class : AllStatic {
237  friend class VMStructs;
238
239 private:
240  // The fake offsets are added by the class loader when java.lang.Class is loaded
241
242  static int _klass_offset;
243  static int _array_klass_offset;
244
245  static int _oop_size_offset;
246  static int _static_oop_field_count_offset;
247
248  static int _protection_domain_offset;
249  static int _init_lock_offset;
250  static int _signers_offset;
251  static int _class_loader_offset;
252  static int _component_mirror_offset;
253
254  static bool offsets_computed;
255  static int classRedefinedCount_offset;
256
257  static GrowableArray<Klass*>* _fixup_mirror_list;
258
259  static void set_init_lock(oop java_class, oop init_lock);
260  static void set_protection_domain(oop java_class, oop protection_domain);
261  static void set_class_loader(oop java_class, oop class_loader);
262  static void set_component_mirror(oop java_class, oop comp_mirror);
263  static void initialize_mirror_fields(KlassHandle k, Handle mirror, Handle protection_domain, TRAPS);
264 public:
265  static void compute_offsets();
266
267  // Instance creation
268  static void create_mirror(KlassHandle k, Handle class_loader,
269                            Handle protection_domain, TRAPS);
270  static void fixup_mirror(KlassHandle k, TRAPS);
271  static oop  create_basic_type_mirror(const char* basic_type_name, BasicType type, TRAPS);
272  // Conversion
273  static Klass* as_Klass(oop java_class);
274  static void set_klass(oop java_class, Klass* klass);
275  static BasicType as_BasicType(oop java_class, Klass** reference_klass = NULL);
276  static BasicType as_BasicType(oop java_class, KlassHandle* reference_klass) {
277    Klass* refk_oop = NULL;
278    BasicType result = as_BasicType(java_class, &refk_oop);
279    (*reference_klass) = KlassHandle(refk_oop);
280    return result;
281  }
282  static Symbol* as_signature(oop java_class, bool intern_if_not_found, TRAPS);
283  static void print_signature(oop java_class, outputStream *st);
284  static const char* as_external_name(oop java_class);
285  // Testing
286  static bool is_instance(oop obj);
287
288  static bool is_primitive(oop java_class);
289  static BasicType primitive_type(oop java_class);
290  static oop primitive_mirror(BasicType t);
291  // JVM_NewArray support
292  static Klass* array_klass(oop java_class);
293  static void set_array_klass(oop java_class, Klass* klass);
294  // compiler support for class operations
295  static int klass_offset_in_bytes()                { return _klass_offset; }
296  static int array_klass_offset_in_bytes()          { return _array_klass_offset; }
297  // Support for classRedefinedCount field
298  static int classRedefinedCount(oop the_class_mirror);
299  static void set_classRedefinedCount(oop the_class_mirror, int value);
300
301  // Support for embedded per-class oops
302  static oop  protection_domain(oop java_class);
303  static oop  init_lock(oop java_class);
304  static oop  component_mirror(oop java_class);
305  static objArrayOop  signers(oop java_class);
306  static void set_signers(oop java_class, objArrayOop signers);
307
308  static oop class_loader(oop java_class);
309
310  static int oop_size(oop java_class);
311  static void set_oop_size(oop java_class, int size);
312  static int static_oop_field_count(oop java_class);
313  static void set_static_oop_field_count(oop java_class, int size);
314
315  static GrowableArray<Klass*>* fixup_mirror_list() {
316    return _fixup_mirror_list;
317  }
318  static void set_fixup_mirror_list(GrowableArray<Klass*>* v) {
319    _fixup_mirror_list = v;
320  }
321  // Debugging
322  friend class JavaClasses;
323  friend class InstanceKlass;   // verification code accesses offsets
324  friend class ClassFileParser; // access to number_of_fake_fields
325};
326
327// Interface to java.lang.Thread objects
328
329class java_lang_Thread : AllStatic {
330 private:
331  // Note that for this class the layout changed between JDK1.2 and JDK1.3,
332  // so we compute the offsets at startup rather than hard-wiring them.
333  static int _name_offset;
334  static int _group_offset;
335  static int _contextClassLoader_offset;
336  static int _inheritedAccessControlContext_offset;
337  static int _priority_offset;
338  static int _eetop_offset;
339  static int _daemon_offset;
340  static int _stillborn_offset;
341  static int _stackSize_offset;
342  static int _tid_offset;
343  static int _thread_status_offset;
344  static int _park_blocker_offset;
345  static int _park_event_offset ;
346
347  static void compute_offsets();
348
349 public:
350  // Instance creation
351  static oop create();
352  // Returns the JavaThread associated with the thread obj
353  static JavaThread* thread(oop java_thread);
354  // Set JavaThread for instance
355  static void set_thread(oop java_thread, JavaThread* thread);
356  // Name
357  static oop name(oop java_thread);
358  static void set_name(oop java_thread, oop name);
359  // Priority
360  static ThreadPriority priority(oop java_thread);
361  static void set_priority(oop java_thread, ThreadPriority priority);
362  // Thread group
363  static oop  threadGroup(oop java_thread);
364  // Stillborn
365  static bool is_stillborn(oop java_thread);
366  static void set_stillborn(oop java_thread);
367  // Alive (NOTE: this is not really a field, but provides the correct
368  // definition without doing a Java call)
369  static bool is_alive(oop java_thread);
370  // Daemon
371  static bool is_daemon(oop java_thread);
372  static void set_daemon(oop java_thread);
373  // Context ClassLoader
374  static oop context_class_loader(oop java_thread);
375  // Control context
376  static oop inherited_access_control_context(oop java_thread);
377  // Stack size hint
378  static jlong stackSize(oop java_thread);
379  // Thread ID
380  static jlong thread_id(oop java_thread);
381
382  // Blocker object responsible for thread parking
383  static oop park_blocker(oop java_thread);
384
385  // Pointer to type-stable park handler, encoded as jlong.
386  // Should be set when apparently null
387  // For details, see unsafe.cpp Unsafe_Unpark
388  static jlong park_event(oop java_thread);
389  static bool set_park_event(oop java_thread, jlong ptr);
390
391  // Java Thread Status for JVMTI and M&M use.
392  // This thread status info is saved in threadStatus field of
393  // java.lang.Thread java class.
394  enum ThreadStatus {
395    NEW                      = 0,
396    RUNNABLE                 = JVMTI_THREAD_STATE_ALIVE +          // runnable / running
397                               JVMTI_THREAD_STATE_RUNNABLE,
398    SLEEPING                 = JVMTI_THREAD_STATE_ALIVE +          // Thread.sleep()
399                               JVMTI_THREAD_STATE_WAITING +
400                               JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
401                               JVMTI_THREAD_STATE_SLEEPING,
402    IN_OBJECT_WAIT           = JVMTI_THREAD_STATE_ALIVE +          // Object.wait()
403                               JVMTI_THREAD_STATE_WAITING +
404                               JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
405                               JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
406    IN_OBJECT_WAIT_TIMED     = JVMTI_THREAD_STATE_ALIVE +          // Object.wait(long)
407                               JVMTI_THREAD_STATE_WAITING +
408                               JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
409                               JVMTI_THREAD_STATE_IN_OBJECT_WAIT,
410    PARKED                   = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park()
411                               JVMTI_THREAD_STATE_WAITING +
412                               JVMTI_THREAD_STATE_WAITING_INDEFINITELY +
413                               JVMTI_THREAD_STATE_PARKED,
414    PARKED_TIMED             = JVMTI_THREAD_STATE_ALIVE +          // LockSupport.park(long)
415                               JVMTI_THREAD_STATE_WAITING +
416                               JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT +
417                               JVMTI_THREAD_STATE_PARKED,
418    BLOCKED_ON_MONITOR_ENTER = JVMTI_THREAD_STATE_ALIVE +          // (re-)entering a synchronization block
419                               JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER,
420    TERMINATED               = JVMTI_THREAD_STATE_TERMINATED
421  };
422  // Write thread status info to threadStatus field of java.lang.Thread.
423  static void set_thread_status(oop java_thread_oop, ThreadStatus status);
424  // Read thread status info from threadStatus field of java.lang.Thread.
425  static ThreadStatus get_thread_status(oop java_thread_oop);
426
427  static const char*  thread_status_name(oop java_thread_oop);
428
429  // Debugging
430  friend class JavaClasses;
431};
432
433// Interface to java.lang.ThreadGroup objects
434
435class java_lang_ThreadGroup : AllStatic {
436 private:
437  static int _parent_offset;
438  static int _name_offset;
439  static int _threads_offset;
440  static int _groups_offset;
441  static int _maxPriority_offset;
442  static int _destroyed_offset;
443  static int _daemon_offset;
444  static int _vmAllowSuspension_offset;
445  static int _nthreads_offset;
446  static int _ngroups_offset;
447
448  static void compute_offsets();
449
450 public:
451  // parent ThreadGroup
452  static oop  parent(oop java_thread_group);
453  // name
454  static typeArrayOop name(oop java_thread_group);
455  // ("name as oop" accessor is not necessary)
456  // Number of threads in group
457  static int nthreads(oop java_thread_group);
458  // threads
459  static objArrayOop threads(oop java_thread_group);
460  // Number of threads in group
461  static int ngroups(oop java_thread_group);
462  // groups
463  static objArrayOop groups(oop java_thread_group);
464  // maxPriority in group
465  static ThreadPriority maxPriority(oop java_thread_group);
466  // Destroyed
467  static bool is_destroyed(oop java_thread_group);
468  // Daemon
469  static bool is_daemon(oop java_thread_group);
470  // vmAllowSuspension
471  static bool is_vmAllowSuspension(oop java_thread_group);
472  // Debugging
473  friend class JavaClasses;
474};
475
476
477
478// Interface to java.lang.Throwable objects
479
480class java_lang_Throwable: AllStatic {
481  friend class BacktraceBuilder;
482
483 private:
484  // Offsets
485  enum {
486    hc_backtrace_offset     =  0,
487    hc_detailMessage_offset =  1,
488    hc_cause_offset         =  2,  // New since 1.4
489    hc_stackTrace_offset    =  3   // New since 1.4
490  };
491  enum {
492      hc_static_unassigned_stacktrace_offset = 0  // New since 1.7
493  };
494  // Trace constants
495  enum {
496    trace_methods_offset = 0,
497    trace_bcis_offset    = 1,
498    trace_mirrors_offset = 2,
499    trace_cprefs_offset  = 3,
500    trace_next_offset    = 4,
501    trace_size           = 5,
502    trace_chunk_size     = 32
503  };
504
505  static int backtrace_offset;
506  static int detailMessage_offset;
507  static int cause_offset;
508  static int stackTrace_offset;
509  static int static_unassigned_stacktrace_offset;
510
511  // Printing
512  static char* print_stack_element_to_buffer(Handle mirror, int method, int version, int bci, int cpref);
513  // StackTrace (programmatic access, new since 1.4)
514  static void clear_stacktrace(oop throwable);
515  // No stack trace available
516  static const char* no_stack_trace_message();
517  // Stacktrace (post JDK 1.7.0 to allow immutability protocol to be followed)
518  static void set_stacktrace(oop throwable, oop st_element_array);
519  static oop unassigned_stacktrace();
520
521 public:
522  // Backtrace
523  static oop backtrace(oop throwable);
524  static void set_backtrace(oop throwable, oop value);
525  // Needed by JVMTI to filter out this internal field.
526  static int get_backtrace_offset() { return backtrace_offset;}
527  static int get_detailMessage_offset() { return detailMessage_offset;}
528  // Message
529  static oop message(oop throwable);
530  static oop message(Handle throwable);
531  static void set_message(oop throwable, oop value);
532  static Symbol* detail_message(oop throwable);
533  static void print_stack_element(outputStream *st, Handle mirror, int method,
534                                  int version, int bci, int cpref);
535  static void print_stack_element(outputStream *st, const methodHandle& method, int bci);
536  static void print_stack_usage(Handle stream);
537
538  // Allocate space for backtrace (created but stack trace not filled in)
539  static void allocate_backtrace(Handle throwable, TRAPS);
540  // Fill in current stack trace for throwable with preallocated backtrace (no GC)
541  static void fill_in_stack_trace_of_preallocated_backtrace(Handle throwable);
542  // Fill in current stack trace, can cause GC
543  static void fill_in_stack_trace(Handle throwable, const methodHandle& method, TRAPS);
544  static void fill_in_stack_trace(Handle throwable, const methodHandle& method = methodHandle());
545  // Programmatic access to stack trace
546  static oop  get_stack_trace_element(oop throwable, int index, TRAPS);
547  static int  get_stack_trace_depth(oop throwable, TRAPS);
548  // Printing
549  static void print(oop throwable, outputStream* st);
550  static void print(Handle throwable, outputStream* st);
551  static void print_stack_trace(oop throwable, outputStream* st);
552  // Debugging
553  friend class JavaClasses;
554};
555
556
557// Interface to java.lang.reflect.AccessibleObject objects
558
559class java_lang_reflect_AccessibleObject: AllStatic {
560 private:
561  // Note that to reduce dependencies on the JDK we compute these
562  // offsets at run-time.
563  static int override_offset;
564
565  static void compute_offsets();
566
567 public:
568  // Accessors
569  static jboolean override(oop reflect);
570  static void set_override(oop reflect, jboolean value);
571
572  // Debugging
573  friend class JavaClasses;
574};
575
576
577// Interface to java.lang.reflect.Method objects
578
579class java_lang_reflect_Method : public java_lang_reflect_AccessibleObject {
580 private:
581  // Note that to reduce dependencies on the JDK we compute these
582  // offsets at run-time.
583  static int clazz_offset;
584  static int name_offset;
585  static int returnType_offset;
586  static int parameterTypes_offset;
587  static int exceptionTypes_offset;
588  static int slot_offset;
589  static int modifiers_offset;
590  static int signature_offset;
591  static int annotations_offset;
592  static int parameter_annotations_offset;
593  static int annotation_default_offset;
594  static int type_annotations_offset;
595
596  static void compute_offsets();
597
598 public:
599  // Allocation
600  static Handle create(TRAPS);
601
602  // Accessors
603  static oop clazz(oop reflect);
604  static void set_clazz(oop reflect, oop value);
605
606  static oop name(oop method);
607  static void set_name(oop method, oop value);
608
609  static oop return_type(oop method);
610  static void set_return_type(oop method, oop value);
611
612  static oop parameter_types(oop method);
613  static void set_parameter_types(oop method, oop value);
614
615  static oop exception_types(oop method);
616  static void set_exception_types(oop method, oop value);
617
618  static int slot(oop reflect);
619  static void set_slot(oop reflect, int value);
620
621  static int modifiers(oop method);
622  static void set_modifiers(oop method, int value);
623
624  static bool has_signature_field();
625  static oop signature(oop method);
626  static void set_signature(oop method, oop value);
627
628  static bool has_annotations_field();
629  static oop annotations(oop method);
630  static void set_annotations(oop method, oop value);
631
632  static bool has_parameter_annotations_field();
633  static oop parameter_annotations(oop method);
634  static void set_parameter_annotations(oop method, oop value);
635
636  static bool has_annotation_default_field();
637  static oop annotation_default(oop method);
638  static void set_annotation_default(oop method, oop value);
639
640  static bool has_type_annotations_field();
641  static oop type_annotations(oop method);
642  static void set_type_annotations(oop method, oop value);
643
644  // Debugging
645  friend class JavaClasses;
646};
647
648
649// Interface to java.lang.reflect.Constructor objects
650
651class java_lang_reflect_Constructor : public java_lang_reflect_AccessibleObject {
652 private:
653  // Note that to reduce dependencies on the JDK we compute these
654  // offsets at run-time.
655  static int clazz_offset;
656  static int parameterTypes_offset;
657  static int exceptionTypes_offset;
658  static int slot_offset;
659  static int modifiers_offset;
660  static int signature_offset;
661  static int annotations_offset;
662  static int parameter_annotations_offset;
663  static int type_annotations_offset;
664
665  static void compute_offsets();
666
667 public:
668  // Allocation
669  static Handle create(TRAPS);
670
671  // Accessors
672  static oop clazz(oop reflect);
673  static void set_clazz(oop reflect, oop value);
674
675  static oop parameter_types(oop constructor);
676  static void set_parameter_types(oop constructor, oop value);
677
678  static oop exception_types(oop constructor);
679  static void set_exception_types(oop constructor, oop value);
680
681  static int slot(oop reflect);
682  static void set_slot(oop reflect, int value);
683
684  static int modifiers(oop constructor);
685  static void set_modifiers(oop constructor, int value);
686
687  static bool has_signature_field();
688  static oop signature(oop constructor);
689  static void set_signature(oop constructor, oop value);
690
691  static bool has_annotations_field();
692  static oop annotations(oop constructor);
693  static void set_annotations(oop constructor, oop value);
694
695  static bool has_parameter_annotations_field();
696  static oop parameter_annotations(oop method);
697  static void set_parameter_annotations(oop method, oop value);
698
699  static bool has_type_annotations_field();
700  static oop type_annotations(oop constructor);
701  static void set_type_annotations(oop constructor, oop value);
702
703  // Debugging
704  friend class JavaClasses;
705};
706
707
708// Interface to java.lang.reflect.Field objects
709
710class java_lang_reflect_Field : public java_lang_reflect_AccessibleObject {
711 private:
712  // Note that to reduce dependencies on the JDK we compute these
713  // offsets at run-time.
714  static int clazz_offset;
715  static int name_offset;
716  static int type_offset;
717  static int slot_offset;
718  static int modifiers_offset;
719  static int signature_offset;
720  static int annotations_offset;
721  static int type_annotations_offset;
722
723  static void compute_offsets();
724
725 public:
726  // Allocation
727  static Handle create(TRAPS);
728
729  // Accessors
730  static oop clazz(oop reflect);
731  static void set_clazz(oop reflect, oop value);
732
733  static oop name(oop field);
734  static void set_name(oop field, oop value);
735
736  static oop type(oop field);
737  static void set_type(oop field, oop value);
738
739  static int slot(oop reflect);
740  static void set_slot(oop reflect, int value);
741
742  static int modifiers(oop field);
743  static void set_modifiers(oop field, int value);
744
745  static bool has_signature_field();
746  static oop signature(oop constructor);
747  static void set_signature(oop constructor, oop value);
748
749  static bool has_annotations_field();
750  static oop annotations(oop constructor);
751  static void set_annotations(oop constructor, oop value);
752
753  static bool has_parameter_annotations_field();
754  static oop parameter_annotations(oop method);
755  static void set_parameter_annotations(oop method, oop value);
756
757  static bool has_annotation_default_field();
758  static oop annotation_default(oop method);
759  static void set_annotation_default(oop method, oop value);
760
761  static bool has_type_annotations_field();
762  static oop type_annotations(oop field);
763  static void set_type_annotations(oop field, oop value);
764
765  // Debugging
766  friend class JavaClasses;
767};
768
769class java_lang_reflect_Parameter {
770 private:
771  // Note that to reduce dependencies on the JDK we compute these
772  // offsets at run-time.
773  static int name_offset;
774  static int modifiers_offset;
775  static int index_offset;
776  static int executable_offset;
777
778  static void compute_offsets();
779
780 public:
781  // Allocation
782  static Handle create(TRAPS);
783
784  // Accessors
785  static oop name(oop field);
786  static void set_name(oop field, oop value);
787
788  static int index(oop reflect);
789  static void set_index(oop reflect, int value);
790
791  static int modifiers(oop reflect);
792  static void set_modifiers(oop reflect, int value);
793
794  static oop executable(oop constructor);
795  static void set_executable(oop constructor, oop value);
796
797  friend class JavaClasses;
798};
799
800// Interface to sun.reflect.ConstantPool objects
801class sun_reflect_ConstantPool {
802 private:
803  // Note that to reduce dependencies on the JDK we compute these
804  // offsets at run-time.
805  static int _oop_offset;
806
807  static void compute_offsets();
808
809 public:
810  // Allocation
811  static Handle create(TRAPS);
812
813  // Accessors
814  static void set_cp(oop reflect, ConstantPool* value);
815  static int oop_offset() {
816    return _oop_offset;
817  }
818
819  static ConstantPool* get_cp(oop reflect);
820
821  // Debugging
822  friend class JavaClasses;
823};
824
825// Interface to sun.reflect.UnsafeStaticFieldAccessorImpl objects
826class sun_reflect_UnsafeStaticFieldAccessorImpl {
827 private:
828  static int _base_offset;
829  static void compute_offsets();
830
831 public:
832  static int base_offset() {
833    return _base_offset;
834  }
835
836  // Debugging
837  friend class JavaClasses;
838};
839
840// Interface to java.lang primitive type boxing objects:
841//  - java.lang.Boolean
842//  - java.lang.Character
843//  - java.lang.Float
844//  - java.lang.Double
845//  - java.lang.Byte
846//  - java.lang.Short
847//  - java.lang.Integer
848//  - java.lang.Long
849
850// This could be separated out into 8 individual classes.
851
852class java_lang_boxing_object: AllStatic {
853 private:
854  enum {
855   hc_value_offset = 0
856  };
857  static int value_offset;
858  static int long_value_offset;
859
860  static oop initialize_and_allocate(BasicType type, TRAPS);
861 public:
862  // Allocation. Returns a boxed value, or NULL for invalid type.
863  static oop create(BasicType type, jvalue* value, TRAPS);
864  // Accessors. Returns the basic type being boxed, or T_ILLEGAL for invalid oop.
865  static BasicType get_value(oop box, jvalue* value);
866  static BasicType set_value(oop box, jvalue* value);
867  static BasicType basic_type(oop box);
868  static bool is_instance(oop box)                 { return basic_type(box) != T_ILLEGAL; }
869  static bool is_instance(oop box, BasicType type) { return basic_type(box) == type; }
870  static void print(oop box, outputStream* st)     { jvalue value;  print(get_value(box, &value), &value, st); }
871  static void print(BasicType type, jvalue* value, outputStream* st);
872
873  static int value_offset_in_bytes(BasicType type) {
874    return ( type == T_LONG || type == T_DOUBLE ) ? long_value_offset :
875                                                    value_offset;
876  }
877
878  // Debugging
879  friend class JavaClasses;
880};
881
882
883
884// Interface to java.lang.ref.Reference objects
885
886class java_lang_ref_Reference: AllStatic {
887 public:
888  enum {
889   hc_referent_offset   = 0,
890   hc_queue_offset      = 1,
891   hc_next_offset       = 2,
892   hc_discovered_offset = 3  // Is not last, see SoftRefs.
893  };
894  enum {
895   hc_static_lock_offset    = 0,
896   hc_static_pending_offset = 1
897  };
898
899  static int referent_offset;
900  static int queue_offset;
901  static int next_offset;
902  static int discovered_offset;
903  static int static_lock_offset;
904  static int static_pending_offset;
905  static int number_of_fake_oop_fields;
906
907  // Accessors
908  static oop referent(oop ref) {
909    return ref->obj_field(referent_offset);
910  }
911  static void set_referent(oop ref, oop value) {
912    ref->obj_field_put(referent_offset, value);
913  }
914  static void set_referent_raw(oop ref, oop value) {
915    ref->obj_field_put_raw(referent_offset, value);
916  }
917  static HeapWord* referent_addr(oop ref) {
918    return ref->obj_field_addr<HeapWord>(referent_offset);
919  }
920  static oop next(oop ref) {
921    return ref->obj_field(next_offset);
922  }
923  static void set_next(oop ref, oop value) {
924    ref->obj_field_put(next_offset, value);
925  }
926  static void set_next_raw(oop ref, oop value) {
927    ref->obj_field_put_raw(next_offset, value);
928  }
929  static HeapWord* next_addr(oop ref) {
930    return ref->obj_field_addr<HeapWord>(next_offset);
931  }
932  static oop discovered(oop ref) {
933    return ref->obj_field(discovered_offset);
934  }
935  static void set_discovered(oop ref, oop value) {
936    ref->obj_field_put(discovered_offset, value);
937  }
938  static void set_discovered_raw(oop ref, oop value) {
939    ref->obj_field_put_raw(discovered_offset, value);
940  }
941  static HeapWord* discovered_addr(oop ref) {
942    return ref->obj_field_addr<HeapWord>(discovered_offset);
943  }
944  // Accessors for statics
945  static oop  pending_list_lock();
946  static oop  pending_list();
947
948  static HeapWord*  pending_list_lock_addr();
949  static HeapWord*  pending_list_addr();
950};
951
952
953// Interface to java.lang.ref.SoftReference objects
954
955class java_lang_ref_SoftReference: public java_lang_ref_Reference {
956 public:
957  enum {
958   // The timestamp is a long field and may need to be adjusted for alignment.
959   hc_timestamp_offset  = hc_discovered_offset + 1
960  };
961  enum {
962   hc_static_clock_offset = 0
963  };
964
965  static int timestamp_offset;
966  static int static_clock_offset;
967
968  // Accessors
969  static jlong timestamp(oop ref);
970
971  // Accessors for statics
972  static jlong clock();
973  static void set_clock(jlong value);
974};
975
976// Interface to java.lang.invoke.MethodHandle objects
977
978class MethodHandleEntry;
979
980class java_lang_invoke_MethodHandle: AllStatic {
981  friend class JavaClasses;
982
983 private:
984  static int _type_offset;               // the MethodType of this MH
985  static int _form_offset;               // the LambdaForm of this MH
986
987  static void compute_offsets();
988
989 public:
990  // Accessors
991  static oop            type(oop mh);
992  static void       set_type(oop mh, oop mtype);
993
994  static oop            form(oop mh);
995  static void       set_form(oop mh, oop lform);
996
997  // Testers
998  static bool is_subclass(Klass* klass) {
999    return klass->is_subclass_of(SystemDictionary::MethodHandle_klass());
1000  }
1001  static bool is_instance(oop obj);
1002
1003  // Accessors for code generation:
1004  static int type_offset_in_bytes()             { return _type_offset; }
1005  static int form_offset_in_bytes()             { return _form_offset; }
1006};
1007
1008// Interface to java.lang.invoke.DirectMethodHandle objects
1009
1010class java_lang_invoke_DirectMethodHandle: AllStatic {
1011  friend class JavaClasses;
1012
1013 private:
1014  static int _member_offset;               // the MemberName of this DMH
1015
1016  static void compute_offsets();
1017
1018 public:
1019  // Accessors
1020  static oop  member(oop mh);
1021
1022  // Testers
1023  static bool is_subclass(Klass* klass) {
1024    return klass->is_subclass_of(SystemDictionary::DirectMethodHandle_klass());
1025  }
1026  static bool is_instance(oop obj);
1027
1028  // Accessors for code generation:
1029  static int member_offset_in_bytes()           { return _member_offset; }
1030};
1031
1032// Interface to java.lang.invoke.LambdaForm objects
1033// (These are a private interface for managing adapter code generation.)
1034
1035class java_lang_invoke_LambdaForm: AllStatic {
1036  friend class JavaClasses;
1037
1038 private:
1039  static int _vmentry_offset;  // type is MemberName
1040
1041  static void compute_offsets();
1042
1043 public:
1044  // Accessors
1045  static oop            vmentry(oop lform);
1046  static void       set_vmentry(oop lform, oop invoker);
1047
1048  // Testers
1049  static bool is_subclass(Klass* klass) {
1050    return SystemDictionary::LambdaForm_klass() != NULL &&
1051      klass->is_subclass_of(SystemDictionary::LambdaForm_klass());
1052  }
1053  static bool is_instance(oop obj);
1054
1055  // Accessors for code generation:
1056  static int vmentry_offset_in_bytes()          { return _vmentry_offset; }
1057};
1058
1059
1060// Interface to java.lang.invoke.MemberName objects
1061// (These are a private interface for Java code to query the class hierarchy.)
1062
1063#define MEMBERNAME_INJECTED_FIELDS(macro)                               \
1064  macro(java_lang_invoke_MemberName, vmloader, object_signature, false) \
1065  macro(java_lang_invoke_MemberName, vmindex,  intptr_signature, false) \
1066  macro(java_lang_invoke_MemberName, vmtarget, intptr_signature, false)
1067
1068class java_lang_invoke_MemberName: AllStatic {
1069  friend class JavaClasses;
1070
1071 private:
1072  // From java.lang.invoke.MemberName:
1073  //    private Class<?>   clazz;       // class in which the method is defined
1074  //    private String     name;        // may be null if not yet materialized
1075  //    private Object     type;        // may be null if not yet materialized
1076  //    private int        flags;       // modifier bits; see reflect.Modifier
1077  //    private intptr     vmtarget;    // VM-specific target value
1078  //    private intptr_t   vmindex;     // member index within class or interface
1079  static int _clazz_offset;
1080  static int _name_offset;
1081  static int _type_offset;
1082  static int _flags_offset;
1083  static int _vmtarget_offset;
1084  static int _vmloader_offset;
1085  static int _vmindex_offset;
1086
1087  static void compute_offsets();
1088
1089 public:
1090  // Accessors
1091  static oop            clazz(oop mname);
1092  static void       set_clazz(oop mname, oop clazz);
1093
1094  static oop            type(oop mname);
1095  static void       set_type(oop mname, oop type);
1096
1097  static oop            name(oop mname);
1098  static void       set_name(oop mname, oop name);
1099
1100  static int            flags(oop mname);
1101  static void       set_flags(oop mname, int flags);
1102
1103  static Metadata*      vmtarget(oop mname);
1104  static void       set_vmtarget(oop mname, Metadata* target);
1105
1106  static intptr_t       vmindex(oop mname);
1107  static void       set_vmindex(oop mname, intptr_t index);
1108
1109  // Testers
1110  static bool is_subclass(Klass* klass) {
1111    return klass->is_subclass_of(SystemDictionary::MemberName_klass());
1112  }
1113  static bool is_instance(oop obj);
1114
1115  static bool is_method(oop obj);
1116
1117  // Relevant integer codes (keep these in synch. with MethodHandleNatives.Constants):
1118  enum {
1119    MN_IS_METHOD            = 0x00010000, // method (not constructor)
1120    MN_IS_CONSTRUCTOR       = 0x00020000, // constructor
1121    MN_IS_FIELD             = 0x00040000, // field
1122    MN_IS_TYPE              = 0x00080000, // nested type
1123    MN_CALLER_SENSITIVE     = 0x00100000, // @CallerSensitive annotation detected
1124    MN_REFERENCE_KIND_SHIFT = 24, // refKind
1125    MN_REFERENCE_KIND_MASK  = 0x0F000000 >> MN_REFERENCE_KIND_SHIFT,
1126    // The SEARCH_* bits are not for MN.flags but for the matchFlags argument of MHN.getMembers:
1127    MN_SEARCH_SUPERCLASSES  = 0x00100000, // walk super classes
1128    MN_SEARCH_INTERFACES    = 0x00200000  // walk implemented interfaces
1129  };
1130
1131  // Accessors for code generation:
1132  static int clazz_offset_in_bytes()            { return _clazz_offset; }
1133  static int type_offset_in_bytes()             { return _type_offset; }
1134  static int name_offset_in_bytes()             { return _name_offset; }
1135  static int flags_offset_in_bytes()            { return _flags_offset; }
1136  static int vmtarget_offset_in_bytes()         { return _vmtarget_offset; }
1137  static int vmindex_offset_in_bytes()          { return _vmindex_offset; }
1138};
1139
1140
1141// Interface to java.lang.invoke.MethodType objects
1142
1143class java_lang_invoke_MethodType: AllStatic {
1144  friend class JavaClasses;
1145
1146 private:
1147  static int _rtype_offset;
1148  static int _ptypes_offset;
1149
1150  static void compute_offsets();
1151
1152 public:
1153  // Accessors
1154  static oop            rtype(oop mt);
1155  static objArrayOop    ptypes(oop mt);
1156
1157  static oop            ptype(oop mt, int index);
1158  static int            ptype_count(oop mt);
1159
1160  static int            ptype_slot_count(oop mt);  // extra counts for long/double
1161  static int            rtype_slot_count(oop mt);  // extra counts for long/double
1162
1163  static Symbol*        as_signature(oop mt, bool intern_if_not_found, TRAPS);
1164  static void           print_signature(oop mt, outputStream* st);
1165
1166  static bool is_instance(oop obj);
1167
1168  static bool equals(oop mt1, oop mt2);
1169
1170  // Accessors for code generation:
1171  static int rtype_offset_in_bytes()            { return _rtype_offset; }
1172  static int ptypes_offset_in_bytes()           { return _ptypes_offset; }
1173};
1174
1175
1176// Interface to java.lang.invoke.CallSite objects
1177
1178class java_lang_invoke_CallSite: AllStatic {
1179  friend class JavaClasses;
1180
1181private:
1182  static int _target_offset;
1183  static int _context_offset;
1184
1185  static void compute_offsets();
1186
1187public:
1188  // Accessors
1189  static oop              target(          oop site);
1190  static void         set_target(          oop site, oop target);
1191  static void         set_target_volatile( oop site, oop target);
1192
1193  static oop              context(oop site);
1194
1195  // Testers
1196  static bool is_subclass(Klass* klass) {
1197    return klass->is_subclass_of(SystemDictionary::CallSite_klass());
1198  }
1199  static bool is_instance(oop obj);
1200
1201  // Accessors for code generation:
1202  static int target_offset_in_bytes()           { return _target_offset; }
1203};
1204
1205// Interface to java.lang.invoke.MethodHandleNatives$CallSiteContext objects
1206
1207#define CALLSITECONTEXT_INJECTED_FIELDS(macro) \
1208  macro(java_lang_invoke_MethodHandleNatives_CallSiteContext, vmdependencies, intptr_signature, false)
1209
1210class java_lang_invoke_MethodHandleNatives_CallSiteContext : AllStatic {
1211  friend class JavaClasses;
1212
1213private:
1214  static int _vmdependencies_offset;
1215
1216  static void compute_offsets();
1217
1218public:
1219  // Accessors
1220  static nmethodBucket* vmdependencies(oop context);
1221  static void       set_vmdependencies(oop context, nmethodBucket* bucket);
1222
1223  // Testers
1224  static bool is_subclass(Klass* klass) {
1225    return klass->is_subclass_of(SystemDictionary::Context_klass());
1226  }
1227  static bool is_instance(oop obj);
1228};
1229
1230// Interface to java.security.AccessControlContext objects
1231
1232class java_security_AccessControlContext: AllStatic {
1233 private:
1234  // Note that for this class the layout changed between JDK1.2 and JDK1.3,
1235  // so we compute the offsets at startup rather than hard-wiring them.
1236  static int _context_offset;
1237  static int _privilegedContext_offset;
1238  static int _isPrivileged_offset;
1239  static int _isAuthorized_offset;
1240
1241  static void compute_offsets();
1242 public:
1243  static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS);
1244
1245  static bool is_authorized(Handle context);
1246
1247  // Debugging/initialization
1248  friend class JavaClasses;
1249};
1250
1251
1252// Interface to java.lang.ClassLoader objects
1253
1254#define CLASSLOADER_INJECTED_FIELDS(macro)                            \
1255  macro(java_lang_ClassLoader, loader_data,  intptr_signature, false)
1256
1257class java_lang_ClassLoader : AllStatic {
1258 private:
1259  // The fake offsets are added by the class loader when java.lang.Class is loaded
1260  enum {
1261   hc_parent_offset = 0
1262  };
1263  static int _loader_data_offset;
1264  static bool offsets_computed;
1265  static int parent_offset;
1266  static int parallelCapable_offset;
1267
1268 public:
1269  static void compute_offsets();
1270
1271  static ClassLoaderData** loader_data_addr(oop loader);
1272  static ClassLoaderData* loader_data(oop loader);
1273
1274  static oop parent(oop loader);
1275  static bool isAncestor(oop loader, oop cl);
1276
1277  // Support for parallelCapable field
1278  static bool parallelCapable(oop the_class_mirror);
1279
1280  static bool is_trusted_loader(oop loader);
1281
1282  // Fix for 4474172
1283  static oop  non_reflection_class_loader(oop loader);
1284
1285  // Testers
1286  static bool is_subclass(Klass* klass) {
1287    return klass->is_subclass_of(SystemDictionary::ClassLoader_klass());
1288  }
1289  static bool is_instance(oop obj);
1290
1291  // Debugging
1292  friend class JavaClasses;
1293  friend class ClassFileParser; // access to number_of_fake_fields
1294};
1295
1296
1297// Interface to java.lang.System objects
1298
1299class java_lang_System : AllStatic {
1300 private:
1301  enum {
1302   hc_static_in_offset  = 0,
1303   hc_static_out_offset = 1,
1304   hc_static_err_offset = 2,
1305   hc_static_security_offset = 3
1306  };
1307
1308  static int  static_in_offset;
1309  static int static_out_offset;
1310  static int static_err_offset;
1311  static int static_security_offset;
1312
1313 public:
1314  static int  in_offset_in_bytes();
1315  static int out_offset_in_bytes();
1316  static int err_offset_in_bytes();
1317
1318  static bool has_security_manager();
1319
1320  // Debugging
1321  friend class JavaClasses;
1322};
1323
1324
1325// Interface to java.lang.StackTraceElement objects
1326
1327class java_lang_StackTraceElement: AllStatic {
1328 private:
1329  enum {
1330    hc_declaringClass_offset  = 0,
1331    hc_methodName_offset = 1,
1332    hc_fileName_offset   = 2,
1333    hc_lineNumber_offset = 3
1334  };
1335
1336  static int declaringClass_offset;
1337  static int methodName_offset;
1338  static int fileName_offset;
1339  static int lineNumber_offset;
1340
1341 public:
1342  // Setters
1343  static void set_declaringClass(oop element, oop value);
1344  static void set_methodName(oop element, oop value);
1345  static void set_fileName(oop element, oop value);
1346  static void set_lineNumber(oop element, int value);
1347
1348  // Create an instance of StackTraceElement
1349  static oop create(Handle mirror, int method, int version, int bci, int cpref, TRAPS);
1350  static oop create(const methodHandle& method, int bci, TRAPS);
1351
1352  // Debugging
1353  friend class JavaClasses;
1354};
1355
1356
1357// Interface to java.lang.AssertionStatusDirectives objects
1358
1359class java_lang_AssertionStatusDirectives: AllStatic {
1360 private:
1361  enum {
1362    hc_classes_offset,
1363    hc_classEnabled_offset,
1364    hc_packages_offset,
1365    hc_packageEnabled_offset,
1366    hc_deflt_offset
1367  };
1368
1369  static int classes_offset;
1370  static int classEnabled_offset;
1371  static int packages_offset;
1372  static int packageEnabled_offset;
1373  static int deflt_offset;
1374
1375 public:
1376  // Setters
1377  static void set_classes(oop obj, oop val);
1378  static void set_classEnabled(oop obj, oop val);
1379  static void set_packages(oop obj, oop val);
1380  static void set_packageEnabled(oop obj, oop val);
1381  static void set_deflt(oop obj, bool val);
1382  // Debugging
1383  friend class JavaClasses;
1384};
1385
1386
1387class java_nio_Buffer: AllStatic {
1388 private:
1389  static int _limit_offset;
1390
1391 public:
1392  static int  limit_offset();
1393  static void compute_offsets();
1394};
1395
1396class java_util_concurrent_locks_AbstractOwnableSynchronizer : AllStatic {
1397 private:
1398  static int  _owner_offset;
1399 public:
1400  static void initialize(TRAPS);
1401  static oop  get_owner_threadObj(oop obj);
1402};
1403
1404// Use to declare fields that need to be injected into Java classes
1405// for the JVM to use.  The name_index and signature_index are
1406// declared in vmSymbols.  The may_be_java flag is used to declare
1407// fields that might already exist in Java but should be injected if
1408// they don't.  Otherwise the field is unconditionally injected and
1409// the JVM uses the injected one.  This is to ensure that name
1410// collisions don't occur.  In general may_be_java should be false
1411// unless there's a good reason.
1412
1413class InjectedField {
1414 public:
1415  const SystemDictionary::WKID klass_id;
1416  const vmSymbols::SID name_index;
1417  const vmSymbols::SID signature_index;
1418  const bool           may_be_java;
1419
1420
1421  Klass* klass() const    { return SystemDictionary::well_known_klass(klass_id); }
1422  Symbol* name() const      { return lookup_symbol(name_index); }
1423  Symbol* signature() const { return lookup_symbol(signature_index); }
1424
1425  int compute_offset();
1426
1427  // Find the Symbol for this index
1428  static Symbol* lookup_symbol(int symbol_index) {
1429    return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
1430  }
1431};
1432
1433#define DECLARE_INJECTED_FIELD_ENUM(klass, name, signature, may_be_java) \
1434  klass##_##name##_enum,
1435
1436#define ALL_INJECTED_FIELDS(macro)          \
1437  CLASS_INJECTED_FIELDS(macro)              \
1438  CLASSLOADER_INJECTED_FIELDS(macro)        \
1439  MEMBERNAME_INJECTED_FIELDS(macro)         \
1440  CALLSITECONTEXT_INJECTED_FIELDS(macro)
1441
1442// Interface to hard-coded offset checking
1443
1444class JavaClasses : AllStatic {
1445 private:
1446
1447  static InjectedField _injected_fields[];
1448
1449  static bool check_offset(const char *klass_name, int offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1450  static bool check_static_offset(const char *klass_name, int hardcoded_offset, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1451  static bool check_constant(const char *klass_name, int constant, const char *field_name, const char* field_sig) PRODUCT_RETURN0;
1452
1453 public:
1454  enum InjectedFieldID {
1455    ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD_ENUM)
1456    MAX_enum
1457  };
1458
1459  static int compute_injected_offset(InjectedFieldID id);
1460
1461  static void compute_hard_coded_offsets();
1462  static void compute_offsets();
1463  static void check_offsets() PRODUCT_RETURN;
1464
1465  static InjectedField* get_injected(Symbol* class_name, int* field_count);
1466};
1467
1468#undef DECLARE_INJECTED_FIELD_ENUM
1469
1470#endif // SHARE_VM_CLASSFILE_JAVACLASSES_HPP
1471