src/share/vm/oops/symbolOop.hpp

Wed, 17 Mar 2010 11:01:05 +0100

author
fparain
date
Wed, 17 Mar 2010 11:01:05 +0100
changeset 1759
e392695de029
parent 1573
dd57230ba8fe
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6935224: Adding new DTrace probes to work with Palantir
Summary: Adding probes related to thread scheduling and class initialization
Reviewed-by: kamg, never

     1 /*
     2  * Copyright 1997-2009 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     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
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // A symbolOop is a canonicalized string.
    26 // All symbolOops reside in global symbolTable.
    27 // See oopFactory::new_symbol for how to allocate a symbolOop
    29 class symbolOopDesc : public oopDesc {
    30   friend class VMStructs;
    31  private:
    32   unsigned short _length; // number of UTF8 characters in the symbol
    33   jbyte _body[1];
    35   enum {
    36     // max_symbol_length is constrained by type of _length
    37     max_symbol_length = (1 << 16) -1
    38   };
    39  public:
    41   // Low-level access (used with care, since not GC-safe)
    42   jbyte* base() { return &_body[0]; }
    45   // Returns the largest size symbol we can safely hold.
    46   static int max_length() {
    47     return max_symbol_length;
    48   }
    50   static int object_size(int length) {
    51     int size = header_size() + (sizeof(unsigned short) + length + HeapWordSize - 1) / HeapWordSize;
    52     return align_object_size(size);
    53   }
    55   int object_size() { return object_size(utf8_length()); }
    57   int byte_at(int index) const {
    58     assert(index >=0 && index < _length, "symbol index overflow");
    59     return ((symbolOopDesc*)this)->base()[index];
    60   }
    62   void byte_at_put(int index, int value) {
    63     assert(index >=0 && index < _length, "symbol index overflow");
    64     ((symbolOopDesc*)this)->base()[index] = value;
    65   }
    67   jbyte* bytes() { return base(); }
    69   int utf8_length() const { return _length; }
    71   void set_utf8_length(int len) { _length = len; }
    73   // Compares the symbol with a string.
    74   bool equals(const char* str, int len) const;
    75   bool equals(const char* str) const { return equals(str, (int) strlen(str)); }
    77   // Tests if the symbol starts with the given prefix.
    78   bool starts_with(const char* prefix, int len) const;
    79   bool starts_with(const char* prefix) const {
    80     return starts_with(prefix, (int) strlen(prefix));
    81   }
    83   // Tests if the symbol starts with the given prefix.
    84   int index_of_at(int i, const char* str, int len) const;
    85   int index_of_at(int i, const char* str) const {
    86     return index_of_at(i, str, (int) strlen(str));
    87   }
    89   // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
    90   // note that the ordering is not alfabetical
    91   inline int fast_compare(symbolOop other) const;
    93   // Returns receiver converted to null-terminated UTF-8 string; string is
    94   // allocated in resource area, or in the char buffer provided by caller.
    95   char* as_C_string() const;
    96   char* as_C_string(char* buf, int size) const;
    97   // Use buf if needed buffer length is <= size.
    98   char* as_C_string_flexible_buffer(Thread* t, char* buf, int size) const;
   101   // Returns a null terminated utf8 string in a resource array
   102   char* as_utf8() const { return as_C_string(); }
   103   char* as_utf8_flexible_buffer(Thread* t, char* buf, int size) const {
   104     return as_C_string_flexible_buffer(t, buf, size);
   105   }
   107   jchar* as_unicode(int& length) const;
   109   // Treating this symbol as a class name, returns the Java name for the class.
   110   // String is allocated in resource area if buffer is not provided.
   111   // See Klass::external_name()
   112   const char* as_klass_external_name() const;
   113   const char* as_klass_external_name(char* buf, int size) const;
   115   bool object_is_parsable() const {
   116     return (utf8_length() > 0 || (oop)this == Universe::emptySymbol());
   117   }
   119   // Printing
   120   void print_symbol_on(outputStream* st = NULL);
   121 };
   124 // Note: this comparison is used for vtable sorting only; it doesn't matter
   125 // what order it defines, as long as it is a total, time-invariant order
   126 // Since symbolOops are in permSpace, their relative order in memory never changes,
   127 // so use address comparison for speed
   128 int symbolOopDesc::fast_compare(symbolOop other) const {
   129  return (((uintptr_t)this < (uintptr_t)other) ? -1
   130    : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1);
   131 }

mercurial