hotspot/src/share/vm/classfile/javaClasses.hpp
changeset 35498 392b50de06c6
parent 34317 e93b85bf4cc2
child 35499 b79827ea1b9f
equal deleted inserted replaced
35488:bca41d0c2a15 35498:392b50de06c6
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    58 
    58 
    59   static bool initialized;
    59   static bool initialized;
    60 
    60 
    61   static Handle basic_create(int length, bool byte_arr, TRAPS);
    61   static Handle basic_create(int length, bool byte_arr, TRAPS);
    62 
    62 
    63   static void set_coder(oop string, jbyte coder) {
    63   static inline void set_coder(oop string, jbyte coder);
    64     assert(initialized, "Must be initialized");
       
    65     if (coder_offset > 0) {
       
    66       string->byte_field_put(coder_offset, coder);
       
    67     }
       
    68   }
       
    69 
    64 
    70  public:
    65  public:
    71 
    66 
    72   // Coders
    67   // Coders
    73   enum Coder {
    68   enum Coder {
   108   static int coder_offset_in_bytes()   {
   103   static int coder_offset_in_bytes()   {
   109     assert(initialized && (coder_offset > 0), "Must be initialized");
   104     assert(initialized && (coder_offset > 0), "Must be initialized");
   110     return coder_offset;
   105     return coder_offset;
   111   }
   106   }
   112 
   107 
   113   static void set_value_raw(oop string, typeArrayOop buffer) {
   108   static inline void set_value_raw(oop string, typeArrayOop buffer);
   114     assert(initialized, "Must be initialized");
   109   static inline void set_value(oop string, typeArrayOop buffer);
   115     string->obj_field_put_raw(value_offset, buffer);
   110   static inline void set_hash(oop string, unsigned int hash);
   116   }
   111 
   117   static void set_value(oop string, typeArrayOop buffer) {
   112   // Accessors
   118     assert(initialized && (value_offset > 0), "Must be initialized");
   113   static inline typeArrayOop value(oop java_string);
   119     string->obj_field_put(value_offset, (oop)buffer);
   114   static inline unsigned int hash(oop java_string);
   120   }
   115   static inline bool is_latin1(oop java_string);
   121   static void set_hash(oop string, unsigned int hash) {
   116   static inline int length(oop java_string);
   122     assert(initialized && (hash_offset > 0), "Must be initialized");
       
   123     string->int_field_put(hash_offset, hash);
       
   124   }
       
   125 
       
   126   // Accessors
       
   127   static typeArrayOop value(oop java_string) {
       
   128     assert(initialized && (value_offset > 0), "Must be initialized");
       
   129     assert(is_instance(java_string), "must be java_string");
       
   130     return (typeArrayOop) java_string->obj_field(value_offset);
       
   131   }
       
   132   static unsigned int hash(oop java_string) {
       
   133     assert(initialized && (hash_offset > 0), "Must be initialized");
       
   134     assert(is_instance(java_string), "must be java_string");
       
   135     return java_string->int_field(hash_offset);
       
   136   }
       
   137   static bool is_latin1(oop java_string) {
       
   138     assert(initialized, "Must be initialized");
       
   139     assert(is_instance(java_string), "must be java_string");
       
   140     if (coder_offset > 0) {
       
   141       jbyte coder = java_string->byte_field(coder_offset);
       
   142       assert(CompactStrings || coder == CODER_UTF16, "Must be UTF16 without CompactStrings");
       
   143       return coder == CODER_LATIN1;
       
   144     } else {
       
   145       return false;
       
   146     }
       
   147   }
       
   148   static int length(oop java_string) {
       
   149     assert(initialized, "Must be initialized");
       
   150     assert(is_instance(java_string), "must be java_string");
       
   151     typeArrayOop value_array = ((typeArrayOop)java_string->obj_field(value_offset));
       
   152     if (value_array == NULL) {
       
   153      return 0;
       
   154     }
       
   155     int arr_length = value_array->length();
       
   156     if (!is_latin1(java_string)) {
       
   157       assert((arr_length & 1) == 0, "should be even for UTF16 string");
       
   158       arr_length >>= 1; // convert number of bytes to number of elements
       
   159     }
       
   160     return arr_length;
       
   161   }
       
   162   static int utf8_length(oop java_string);
   117   static int utf8_length(oop java_string);
   163 
   118 
   164   // String converters
   119   // String converters
   165   static char*  as_utf8_string(oop java_string);
   120   static char*  as_utf8_string(oop java_string);
   166   static char*  as_utf8_string(oop java_string, char* buf, int buflen);
   121   static char*  as_utf8_string(oop java_string, char* buf, int buflen);
   217   static Symbol* as_symbol(Handle java_string, TRAPS);
   172   static Symbol* as_symbol(Handle java_string, TRAPS);
   218   static Symbol* as_symbol_or_null(oop java_string);
   173   static Symbol* as_symbol_or_null(oop java_string);
   219 
   174 
   220   // Testers
   175   // Testers
   221   static bool is_instance(oop obj);
   176   static bool is_instance(oop obj);
   222   static bool is_instance_inlined(oop obj);
   177   static inline bool is_instance_inlined(oop obj);
   223 
   178 
   224   // Debugging
   179   // Debugging
   225   static void print(oop java_string, outputStream* st);
   180   static void print(oop java_string, outputStream* st);
   226   friend class JavaClasses;
   181   friend class JavaClasses;
   227   friend class StringTable;
   182   friend class StringTable;
   908   static int static_lock_offset;
   863   static int static_lock_offset;
   909   static int static_pending_offset;
   864   static int static_pending_offset;
   910   static int number_of_fake_oop_fields;
   865   static int number_of_fake_oop_fields;
   911 
   866 
   912   // Accessors
   867   // Accessors
   913   static oop referent(oop ref) {
   868   static inline oop referent(oop ref);
   914     return ref->obj_field(referent_offset);
   869   static inline void set_referent(oop ref, oop value);
   915   }
   870   static inline void set_referent_raw(oop ref, oop value);
   916   static void set_referent(oop ref, oop value) {
   871   static inline HeapWord* referent_addr(oop ref);
   917     ref->obj_field_put(referent_offset, value);
   872   static inline oop next(oop ref);
   918   }
   873   static inline void set_next(oop ref, oop value);
   919   static void set_referent_raw(oop ref, oop value) {
   874   static inline void set_next_raw(oop ref, oop value);
   920     ref->obj_field_put_raw(referent_offset, value);
   875   static inline HeapWord* next_addr(oop ref);
   921   }
   876   static inline oop discovered(oop ref);
   922   static HeapWord* referent_addr(oop ref) {
   877   static inline void set_discovered(oop ref, oop value);
   923     return ref->obj_field_addr<HeapWord>(referent_offset);
   878   static inline void set_discovered_raw(oop ref, oop value);
   924   }
   879   static inline HeapWord* discovered_addr(oop ref);
   925   static oop next(oop ref) {
   880 
   926     return ref->obj_field(next_offset);
       
   927   }
       
   928   static void set_next(oop ref, oop value) {
       
   929     ref->obj_field_put(next_offset, value);
       
   930   }
       
   931   static void set_next_raw(oop ref, oop value) {
       
   932     ref->obj_field_put_raw(next_offset, value);
       
   933   }
       
   934   static HeapWord* next_addr(oop ref) {
       
   935     return ref->obj_field_addr<HeapWord>(next_offset);
       
   936   }
       
   937   static oop discovered(oop ref) {
       
   938     return ref->obj_field(discovered_offset);
       
   939   }
       
   940   static void set_discovered(oop ref, oop value) {
       
   941     ref->obj_field_put(discovered_offset, value);
       
   942   }
       
   943   static void set_discovered_raw(oop ref, oop value) {
       
   944     ref->obj_field_put_raw(discovered_offset, value);
       
   945   }
       
   946   static HeapWord* discovered_addr(oop ref) {
       
   947     return ref->obj_field_addr<HeapWord>(discovered_offset);
       
   948   }
       
   949   // Accessors for statics
   881   // Accessors for statics
   950   static oop  pending_list_lock();
   882   static oop  pending_list_lock();
   951   static oop  pending_list();
   883   static oop  pending_list();
   952 
   884 
   953   static HeapWord*  pending_list_lock_addr();
   885   static HeapWord*  pending_list_lock_addr();