comparison src/share/vm/ci/ciSymbol.cpp @ 2177:3582bf76420e

6990754: Use native memory and reference counting to implement SymbolTable Summary: move symbols from permgen into C heap and reference count them Reviewed-by: never, acorn, jmasa, stefank
author coleenp
date Thu, 27 Jan 2011 16:11:27 -0800
parents f95d63e2154a
children 1d1603768966
comparison
equal deleted inserted replaced
2176:27e4ea99855d 2177:3582bf76420e
28 #include "memory/oopFactory.hpp" 28 #include "memory/oopFactory.hpp"
29 29
30 // ------------------------------------------------------------------ 30 // ------------------------------------------------------------------
31 // ciSymbol::ciSymbol 31 // ciSymbol::ciSymbol
32 // 32 //
33 // Preallocated handle variant. Used with handles from vmSymboHandles. 33 // Preallocated symbol variant. Used with symbols from vmSymbols.
34 ciSymbol::ciSymbol(symbolHandle h_s, vmSymbols::SID sid) 34 ciSymbol::ciSymbol(Symbol* s, vmSymbols::SID sid)
35 : ciObject(h_s), _sid(sid) 35 : _symbol(s), _sid(sid)
36 { 36 {
37 assert(_symbol != NULL, "adding null symbol");
38 _symbol->increment_refcount(); // increment ref count
37 assert(sid_ok(), "must be in vmSymbols"); 39 assert(sid_ok(), "must be in vmSymbols");
38 } 40 }
39 41
40 // Normal case for non-famous symbols. 42 // Normal case for non-famous symbols.
41 ciSymbol::ciSymbol(symbolOop s) 43 ciSymbol::ciSymbol(Symbol* s)
42 : ciObject(s), _sid(vmSymbols::NO_SID) 44 : _symbol(s), _sid(vmSymbols::NO_SID)
43 { 45 {
46 assert(_symbol != NULL, "adding null symbol");
47 _symbol->increment_refcount(); // increment ref count
44 assert(sid_ok(), "must not be in vmSymbols"); 48 assert(sid_ok(), "must not be in vmSymbols");
45 } 49 }
46 50
47 // ciSymbol 51 // ciSymbol
48 // 52 //
49 // This class represents a symbolOop in the HotSpot virtual 53 // This class represents a Symbol* in the HotSpot virtual
50 // machine. 54 // machine.
51 55
52 // ------------------------------------------------------------------ 56 // ------------------------------------------------------------------
53 // ciSymbol::as_utf8 57 // ciSymbol::as_utf8
54 // 58 //
55 // The text of the symbol as a null-terminated C string. 59 // The text of the symbol as a null-terminated C string.
56 const char* ciSymbol::as_utf8() { 60 const char* ciSymbol::as_utf8() {
57 VM_QUICK_ENTRY_MARK; 61 VM_QUICK_ENTRY_MARK;
58 symbolOop s = get_symbolOop(); 62 Symbol* s = get_symbol();
59 return s->as_utf8(); 63 return s->as_utf8();
60 } 64 }
61 65
62 // ------------------------------------------------------------------ 66 // ------------------------------------------------------------------
63 // ciSymbol::base 67 // ciSymbol::base
64 jbyte* ciSymbol::base() { 68 const jbyte* ciSymbol::base() {
65 GUARDED_VM_ENTRY(return get_symbolOop()->base();) 69 GUARDED_VM_ENTRY(return get_symbol()->base();)
66 } 70 }
67 71
68 // ------------------------------------------------------------------ 72 // ------------------------------------------------------------------
69 // ciSymbol::byte_at 73 // ciSymbol::byte_at
70 int ciSymbol::byte_at(int i) { 74 int ciSymbol::byte_at(int i) {
71 GUARDED_VM_ENTRY(return get_symbolOop()->byte_at(i);) 75 GUARDED_VM_ENTRY(return get_symbol()->byte_at(i);)
72 } 76 }
73 77
74 // ------------------------------------------------------------------ 78 // ------------------------------------------------------------------
75 // ciSymbol::starts_with 79 // ciSymbol::starts_with
76 // 80 //
77 // Tests if the symbol starts with the given prefix. 81 // Tests if the symbol starts with the given prefix.
78 bool ciSymbol::starts_with(const char* prefix, int len) const { 82 bool ciSymbol::starts_with(const char* prefix, int len) const {
79 GUARDED_VM_ENTRY(return get_symbolOop()->starts_with(prefix, len);) 83 GUARDED_VM_ENTRY(return get_symbol()->starts_with(prefix, len);)
80 } 84 }
81 85
82 // ------------------------------------------------------------------ 86 // ------------------------------------------------------------------
83 // ciSymbol::index_of 87 // ciSymbol::index_of
84 // 88 //
85 // Determines where the symbol contains the given substring. 89 // Determines where the symbol contains the given substring.
86 int ciSymbol::index_of_at(int i, const char* str, int len) const { 90 int ciSymbol::index_of_at(int i, const char* str, int len) const {
87 GUARDED_VM_ENTRY(return get_symbolOop()->index_of_at(i, str, len);) 91 GUARDED_VM_ENTRY(return get_symbol()->index_of_at(i, str, len);)
88 } 92 }
89 93
90 // ------------------------------------------------------------------ 94 // ------------------------------------------------------------------
91 // ciSymbol::utf8_length 95 // ciSymbol::utf8_length
92 int ciSymbol::utf8_length() { 96 int ciSymbol::utf8_length() {
93 GUARDED_VM_ENTRY(return get_symbolOop()->utf8_length();) 97 GUARDED_VM_ENTRY(return get_symbol()->utf8_length();)
94 } 98 }
95 99
96 // ------------------------------------------------------------------ 100 // ------------------------------------------------------------------
97 // ciSymbol::print_impl 101 // ciSymbol::print_impl
98 // 102 //
105 // ------------------------------------------------------------------ 109 // ------------------------------------------------------------------
106 // ciSymbol::print_symbol_on 110 // ciSymbol::print_symbol_on
107 // 111 //
108 // Print the value of this symbol on an outputStream 112 // Print the value of this symbol on an outputStream
109 void ciSymbol::print_symbol_on(outputStream *st) { 113 void ciSymbol::print_symbol_on(outputStream *st) {
110 GUARDED_VM_ENTRY(get_symbolOop()->print_symbol_on(st);) 114 GUARDED_VM_ENTRY(get_symbol()->print_symbol_on(st);)
111 } 115 }
112 116
113 // ------------------------------------------------------------------ 117 // ------------------------------------------------------------------
114 // ciSymbol::make_impl 118 // ciSymbol::make_impl
115 // 119 //
116 // Make a ciSymbol from a C string (implementation). 120 // Make a ciSymbol from a C string (implementation).
117 ciSymbol* ciSymbol::make_impl(const char* s) { 121 ciSymbol* ciSymbol::make_impl(const char* s) {
118 EXCEPTION_CONTEXT; 122 EXCEPTION_CONTEXT;
119 // For some reason, oopFactory::new_symbol doesn't declare its 123 TempNewSymbol sym = SymbolTable::new_symbol(s, THREAD);
120 // char* argument as const.
121 symbolOop sym = oopFactory::new_symbol((char*)s, (int)strlen(s), THREAD);
122 if (HAS_PENDING_EXCEPTION) { 124 if (HAS_PENDING_EXCEPTION) {
123 CLEAR_PENDING_EXCEPTION; 125 CLEAR_PENDING_EXCEPTION;
124 CURRENT_THREAD_ENV->record_out_of_memory_failure(); 126 CURRENT_THREAD_ENV->record_out_of_memory_failure();
125 return ciEnv::_unloaded_cisymbol; 127 return ciEnv::_unloaded_cisymbol;
126 } 128 }
127 return CURRENT_THREAD_ENV->get_object(sym)->as_symbol(); 129 return CURRENT_THREAD_ENV->get_symbol(sym);
128 } 130 }
129 131
130 // ------------------------------------------------------------------ 132 // ------------------------------------------------------------------
131 // ciSymbol::make 133 // ciSymbol::make
132 // 134 //