< prev index next >

src/share/vm/oops/symbol.cpp

Print this page
rev 10169 : 8149557: Resource mark breaks printing to string stream


 141 }
 142 
 143 char* Symbol::as_C_string_flexible_buffer(Thread* t,
 144                                                  char* buf, int size) const {
 145   char* str;
 146   int len = utf8_length();
 147   int buf_len = len + 1;
 148   if (size < buf_len) {
 149     str = NEW_RESOURCE_ARRAY(char, buf_len);
 150   } else {
 151     str = buf;
 152   }
 153   return as_C_string(str, buf_len);
 154 }
 155 
 156 void Symbol::print_utf8_on(outputStream* st) const {
 157   st->print("%s", as_C_string());
 158 }
 159 
 160 void Symbol::print_symbol_on(outputStream* st) const {
 161   ResourceMark rm;
 162   st = st ? st : tty;
 163   st->print("%s", as_quoted_ascii());








 164 }
 165 
 166 char* Symbol::as_quoted_ascii() const {
 167   const char *ptr = (const char *)&_body[0];
 168   int quoted_length = UTF8::quoted_ascii_length(ptr, utf8_length());
 169   char* result = NEW_RESOURCE_ARRAY(char, quoted_length + 1);
 170   UTF8::as_quoted_ascii(ptr, utf8_length(), result, quoted_length + 1);
 171   return result;
 172 }
 173 
 174 jchar* Symbol::as_unicode(int& length) const {
 175   Symbol* this_ptr = (Symbol*)this;
 176   length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length());
 177   jchar* result = NEW_RESOURCE_ARRAY(jchar, length);
 178   if (length > 0) {
 179     UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length);
 180   }
 181   return result;
 182 }
 183 




 141 }
 142 
 143 char* Symbol::as_C_string_flexible_buffer(Thread* t,
 144                                                  char* buf, int size) const {
 145   char* str;
 146   int len = utf8_length();
 147   int buf_len = len + 1;
 148   if (size < buf_len) {
 149     str = NEW_RESOURCE_ARRAY(char, buf_len);
 150   } else {
 151     str = buf;
 152   }
 153   return as_C_string(str, buf_len);
 154 }
 155 
 156 void Symbol::print_utf8_on(outputStream* st) const {
 157   st->print("%s", as_C_string());
 158 }
 159 
 160 void Symbol::print_symbol_on(outputStream* st) const {
 161   char *s;
 162   st = st ? st : tty;
 163   {
 164     // ResourceMark may not affect st->print(). If st is a string
 165     // stream it could resize, using the same resource arena.
 166     ResourceMark rm;
 167     s = as_quoted_ascii();
 168     s = os::strdup(s);
 169   }
 170   st->print("%s", s);
 171   os::free(s);
 172 }
 173 
 174 char* Symbol::as_quoted_ascii() const {
 175   const char *ptr = (const char *)&_body[0];
 176   int quoted_length = UTF8::quoted_ascii_length(ptr, utf8_length());
 177   char* result = NEW_RESOURCE_ARRAY(char, quoted_length + 1);
 178   UTF8::as_quoted_ascii(ptr, utf8_length(), result, quoted_length + 1);
 179   return result;
 180 }
 181 
 182 jchar* Symbol::as_unicode(int& length) const {
 183   Symbol* this_ptr = (Symbol*)this;
 184   length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length());
 185   jchar* result = NEW_RESOURCE_ARRAY(jchar, length);
 186   if (length > 0) {
 187     UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length);
 188   }
 189   return result;
 190 }
 191 


< prev index next >