src/share/vm/oops/symbolOop.cpp

Fri, 20 Mar 2009 23:19:36 -0700

author
jrose
date
Fri, 20 Mar 2009 23:19:36 -0700
changeset 1100
c89f86385056
parent 657
2a1a77d3458f
child 1573
dd57230ba8fe
permissions
-rw-r--r--

6814659: separable cleanups and subroutines for 6655638
Summary: preparatory but separable changes for method handles
Reviewed-by: kvn, never

     1 /*
     2  * Copyright 1997-2005 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 # include "incls/_precompiled.incl"
    26 # include "incls/_symbolOop.cpp.incl"
    28 bool symbolOopDesc::equals(const char* str, int len) const {
    29   int l = utf8_length();
    30   if (l != len) return false;
    31   while (l-- > 0) {
    32     if (str[l] != (char) byte_at(l))
    33       return false;
    34   }
    35   assert(l == -1, "we should be at the beginning");
    36   return true;
    37 }
    39 char* symbolOopDesc::as_C_string(char* buf, int size) const {
    40   if (size > 0) {
    41     int len = MIN2(size - 1, utf8_length());
    42     for (int i = 0; i < len; i++) {
    43       buf[i] = byte_at(i);
    44     }
    45     buf[len] = '\0';
    46   }
    47   return buf;
    48 }
    50 char* symbolOopDesc::as_C_string() const {
    51   int len = utf8_length();
    52   char* str = NEW_RESOURCE_ARRAY(char, len + 1);
    53   return as_C_string(str, len + 1);
    54 }
    56 char* symbolOopDesc::as_C_string_flexible_buffer(Thread* t,
    57                                                  char* buf, int size) const {
    58   char* str;
    59   int len = utf8_length();
    60   int buf_len = len + 1;
    61   if (size < buf_len) {
    62     str = NEW_RESOURCE_ARRAY(char, buf_len);
    63   } else {
    64     str = buf;
    65   }
    66   return as_C_string(str, buf_len);
    67 }
    69 void symbolOopDesc::print_symbol_on(outputStream* st) {
    70   st = st ? st : tty;
    71   int length = UTF8::unicode_length((const char*)bytes(), utf8_length());
    72   const char *ptr = (const char *)bytes();
    73   jchar value;
    74   for (int index = 0; index < length; index++) {
    75     ptr = UTF8::next(ptr, &value);
    76     if (value >= 32 && value < 127 || value == '\'' || value == '\\') {
    77       st->put(value);
    78     } else {
    79       st->print("\\u%04x", value);
    80     }
    81   }
    82 }
    84 jchar* symbolOopDesc::as_unicode(int& length) const {
    85   symbolOopDesc* this_ptr = (symbolOopDesc*)this;
    86   length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length());
    87   jchar* result = NEW_RESOURCE_ARRAY(jchar, length);
    88   if (length > 0) {
    89     UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length);
    90   }
    91   return result;
    92 }
    94 const char* symbolOopDesc::as_klass_external_name(char* buf, int size) const {
    95   if (size > 0) {
    96     char* str    = as_C_string(buf, size);
    97     int   length = (int)strlen(str);
    98     // Turn all '/'s into '.'s (also for array klasses)
    99     for (int index = 0; index < length; index++) {
   100       if (str[index] == '/') {
   101         str[index] = '.';
   102       }
   103     }
   104     return str;
   105   } else {
   106     return buf;
   107   }
   108 }
   110 const char* symbolOopDesc::as_klass_external_name() const {
   111   char* str    = as_C_string();
   112   int   length = (int)strlen(str);
   113   // Turn all '/'s into '.'s (also for array klasses)
   114   for (int index = 0; index < length; index++) {
   115     if (str[index] == '/') {
   116       str[index] = '.';
   117     }
   118   }
   119   return str;
   120 }

mercurial