Mercurial > hg > truffle
comparison src/share/vm/utilities/exceptions.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 | d25d4ca69222 1d1603768966 |
comparison
equal
deleted
inserted
replaced
2176:27e4ea99855d | 2177:3582bf76420e |
---|---|
100 } | 100 } |
101 | 101 |
102 return false; | 102 return false; |
103 } | 103 } |
104 | 104 |
105 bool Exceptions::special_exception(Thread* thread, const char* file, int line, symbolHandle h_name, const char* message) { | 105 bool Exceptions::special_exception(Thread* thread, const char* file, int line, Symbol* h_name, const char* message) { |
106 // bootstrapping check | 106 // bootstrapping check |
107 if (!Universe::is_fully_initialized()) { | 107 if (!Universe::is_fully_initialized()) { |
108 if (h_name.is_null()) { | 108 if (h_name == NULL) { |
109 // atleast an informative message. | 109 // atleast an informative message. |
110 vm_exit_during_initialization("Exception", message); | 110 vm_exit_during_initialization("Exception", message); |
111 } else { | 111 } else { |
112 vm_exit_during_initialization(h_name, message); | 112 vm_exit_during_initialization(h_name, message); |
113 } | 113 } |
159 // vm log | 159 // vm log |
160 Events::log("throw_exception " INTPTR_FORMAT, (address)h_exception()); | 160 Events::log("throw_exception " INTPTR_FORMAT, (address)h_exception()); |
161 } | 161 } |
162 | 162 |
163 | 163 |
164 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, symbolHandle h_name, const char* message, Handle h_loader, Handle h_protection_domain) { | 164 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* h_name, const char* message, Handle h_loader, Handle h_protection_domain) { |
165 // Check for special boot-strapping/vm-thread handling | 165 // Check for special boot-strapping/vm-thread handling |
166 if (special_exception(thread, file, line, h_name, message)) return; | 166 if (special_exception(thread, file, line, h_name, message)) return; |
167 // Create and throw exception | 167 // Create and throw exception |
168 Handle h_cause(thread, NULL); | 168 Handle h_cause(thread, NULL); |
169 Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); | 169 Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); |
170 _throw(thread, file, line, h_exception, message); | 170 _throw(thread, file, line, h_exception, message); |
171 } | 171 } |
172 | 172 |
173 // Throw an exception with a message and a cause | 173 // Throw an exception with a message and a cause |
174 void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, symbolHandle h_name, const char* message, Handle h_cause, Handle h_loader, Handle h_protection_domain) { | 174 void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, Symbol* h_name, const char* message, Handle h_cause, Handle h_loader, Handle h_protection_domain) { |
175 // Check for special boot-strapping/vm-thread handling | 175 // Check for special boot-strapping/vm-thread handling |
176 if (special_exception(thread, file, line, h_name, message)) return; | 176 if (special_exception(thread, file, line, h_name, message)) return; |
177 // Create and throw exception and init cause | 177 // Create and throw exception and init cause |
178 Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); | 178 Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); |
179 _throw(thread, file, line, h_exception, message); | 179 _throw(thread, file, line, h_exception, message); |
180 } | 180 } |
181 | 181 |
182 // This version creates handles and calls the other version | |
183 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, | |
184 symbolOop name, const char* message) { | |
185 symbolHandle h_name(thread, name); | |
186 Handle h_loader(thread, NULL); | |
187 Handle h_protection_domain(thread, NULL); | |
188 Exceptions::_throw_msg(thread, file, line, h_name, message, h_loader, h_protection_domain); | |
189 } | |
190 | |
191 // This version already has a handle for name | 182 // This version already has a handle for name |
192 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, | 183 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, |
193 symbolHandle name, const char* message) { | 184 Symbol* name, const char* message) { |
194 Handle h_loader(thread, NULL); | 185 Handle h_loader(thread, NULL); |
195 Handle h_protection_domain(thread, NULL); | 186 Handle h_protection_domain(thread, NULL); |
196 Exceptions::_throw_msg(thread, file, line, name, message, h_loader, h_protection_domain); | 187 Exceptions::_throw_msg(thread, file, line, name, message, h_loader, h_protection_domain); |
197 } | 188 } |
198 | 189 |
199 // This version already has a handle for name | 190 // This version already has a handle for name |
200 void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, | 191 void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, |
201 symbolHandle name, const char* message, Handle cause) { | 192 Symbol* name, const char* message, Handle cause) { |
202 Handle h_loader(thread, NULL); | 193 Handle h_loader(thread, NULL); |
203 Handle h_protection_domain(thread, NULL); | 194 Handle h_protection_domain(thread, NULL); |
204 Exceptions::_throw_msg_cause(thread, file, line, name, message, cause, h_loader, h_protection_domain); | 195 Exceptions::_throw_msg_cause(thread, file, line, name, message, cause, h_loader, h_protection_domain); |
205 } | 196 } |
206 | 197 |
207 void Exceptions::_throw_args(Thread* thread, const char* file, int line, symbolHandle h_name, symbolHandle h_signature, JavaCallArguments *args) { | 198 void Exceptions::_throw_args(Thread* thread, const char* file, int line, Symbol* h_name, Symbol* h_signature, JavaCallArguments *args) { |
208 // Check for special boot-strapping/vm-thread handling | 199 // Check for special boot-strapping/vm-thread handling |
209 if (special_exception(thread, file, line, h_name, NULL)) return; | 200 if (special_exception(thread, file, line, h_name, NULL)) return; |
210 // Create and throw exception | 201 // Create and throw exception |
211 Handle h_loader(thread, NULL); | 202 Handle h_loader(thread, NULL); |
212 Handle h_prot(thread, NULL); | 203 Handle h_prot(thread, NULL); |
231 exception = Handle(THREAD, THREAD->pending_exception()); | 222 exception = Handle(THREAD, THREAD->pending_exception()); |
232 } | 223 } |
233 _throw_oop(THREAD, file, line, exception()); | 224 _throw_oop(THREAD, file, line, exception()); |
234 } | 225 } |
235 | 226 |
236 void Exceptions::fthrow(Thread* thread, const char* file, int line, symbolHandle h_name, const char* format, ...) { | 227 void Exceptions::fthrow(Thread* thread, const char* file, int line, Symbol* h_name, const char* format, ...) { |
237 const int max_msg_size = 1024; | 228 const int max_msg_size = 1024; |
238 va_list ap; | 229 va_list ap; |
239 va_start(ap, format); | 230 va_start(ap, format); |
240 char msg[max_msg_size]; | 231 char msg[max_msg_size]; |
241 vsnprintf(msg, max_msg_size, format, ap); | 232 vsnprintf(msg, max_msg_size, format, ap); |
245 } | 236 } |
246 | 237 |
247 // Creates an exception oop, calls the <init> method with the given signature. | 238 // Creates an exception oop, calls the <init> method with the given signature. |
248 // and returns a Handle | 239 // and returns a Handle |
249 // Initializes the cause if cause non-null | 240 // Initializes the cause if cause non-null |
250 Handle Exceptions::new_exception(Thread *thread, symbolHandle h_name, | 241 Handle Exceptions::new_exception(Thread *thread, Symbol* h_name, |
251 symbolHandle signature, | 242 Symbol* signature, |
252 JavaCallArguments *args, | 243 JavaCallArguments *args, |
253 Handle h_cause, Handle h_loader, | 244 Handle h_cause, Handle h_loader, |
254 Handle h_protection_domain) { | 245 Handle h_protection_domain) { |
255 assert(Universe::is_fully_initialized(), | 246 assert(Universe::is_fully_initialized(), |
256 "cannot be called during initialization"); | 247 "cannot be called during initialization"); |
273 if (!thread->has_pending_exception()) { | 264 if (!thread->has_pending_exception()) { |
274 JavaValue result(T_VOID); | 265 JavaValue result(T_VOID); |
275 args->set_receiver(h_exception); | 266 args->set_receiver(h_exception); |
276 // Call constructor | 267 // Call constructor |
277 JavaCalls::call_special(&result, klass, | 268 JavaCalls::call_special(&result, klass, |
278 vmSymbolHandles::object_initializer_name(), | 269 vmSymbols::object_initializer_name(), |
279 signature, | 270 signature, |
280 args, | 271 args, |
281 thread); | 272 thread); |
282 | 273 |
283 } | 274 } |
290 JavaValue result1(T_OBJECT); | 281 JavaValue result1(T_OBJECT); |
291 JavaCallArguments args1; | 282 JavaCallArguments args1; |
292 args1.set_receiver(h_exception); | 283 args1.set_receiver(h_exception); |
293 args1.push_oop(h_cause); | 284 args1.push_oop(h_cause); |
294 JavaCalls::call_virtual(&result1, klass, | 285 JavaCalls::call_virtual(&result1, klass, |
295 vmSymbolHandles::initCause_name(), | 286 vmSymbols::initCause_name(), |
296 vmSymbolHandles::throwable_throwable_signature(), | 287 vmSymbols::throwable_throwable_signature(), |
297 &args1, | 288 &args1, |
298 thread); | 289 thread); |
299 } | 290 } |
300 } | 291 } |
301 | 292 |
307 return h_exception; | 298 return h_exception; |
308 } | 299 } |
309 | 300 |
310 // Convenience method. Calls either the <init>() or <init>(String) method when | 301 // Convenience method. Calls either the <init>() or <init>(String) method when |
311 // creating a new exception | 302 // creating a new exception |
312 Handle Exceptions::new_exception(Thread* thread, symbolHandle h_name, | 303 Handle Exceptions::new_exception(Thread* thread, Symbol* h_name, |
313 const char* message, Handle h_cause, | 304 const char* message, Handle h_cause, |
314 Handle h_loader, | 305 Handle h_loader, |
315 Handle h_protection_domain, | 306 Handle h_protection_domain, |
316 ExceptionMsgToUtf8Mode to_utf8_safe) { | 307 ExceptionMsgToUtf8Mode to_utf8_safe) { |
317 JavaCallArguments args; | 308 JavaCallArguments args; |
318 symbolHandle signature; | 309 Symbol* signature = NULL; |
319 if (message == NULL) { | 310 if (message == NULL) { |
320 signature = vmSymbolHandles::void_method_signature(); | 311 signature = vmSymbols::void_method_signature(); |
321 } else { | 312 } else { |
322 // We want to allocate storage, but we can't do that if there's | 313 // We want to allocate storage, but we can't do that if there's |
323 // a pending exception, so we preserve any pending exception | 314 // a pending exception, so we preserve any pending exception |
324 // around the allocation. | 315 // around the allocation. |
325 // If we get an exception from the allocation, prefer that to | 316 // If we get an exception from the allocation, prefer that to |
346 } | 337 } |
347 if (incoming_exception.not_null()) { | 338 if (incoming_exception.not_null()) { |
348 return incoming_exception; | 339 return incoming_exception; |
349 } | 340 } |
350 args.push_oop(msg); | 341 args.push_oop(msg); |
351 signature = vmSymbolHandles::string_void_signature(); | 342 signature = vmSymbols::string_void_signature(); |
352 } | 343 } |
353 return new_exception(thread, h_name, signature, &args, h_cause, h_loader, h_protection_domain); | 344 return new_exception(thread, h_name, signature, &args, h_cause, h_loader, h_protection_domain); |
354 } | 345 } |
355 | 346 |
356 // Another convenience method that creates handles for null class loaders and | 347 // Another convenience method that creates handles for null class loaders and |
360 // convert it directly to a java UTF8 string. Otherwise, we need to take the | 351 // convert it directly to a java UTF8 string. Otherwise, we need to take the |
361 // encoding scheme of the string into account. One thing we should do at some | 352 // encoding scheme of the string into account. One thing we should do at some |
362 // point is to push this flag down to class java_lang_String since other | 353 // point is to push this flag down to class java_lang_String since other |
363 // classes may need similar functionalities. | 354 // classes may need similar functionalities. |
364 Handle Exceptions::new_exception(Thread* thread, | 355 Handle Exceptions::new_exception(Thread* thread, |
365 symbolOop name, | 356 Symbol* name, |
366 const char* message, | 357 const char* message, |
367 ExceptionMsgToUtf8Mode to_utf8_safe) { | 358 ExceptionMsgToUtf8Mode to_utf8_safe) { |
368 | 359 |
369 symbolHandle h_name(thread, name); | |
370 Handle h_loader(thread, NULL); | 360 Handle h_loader(thread, NULL); |
371 Handle h_prot(thread, NULL); | 361 Handle h_prot(thread, NULL); |
372 Handle h_cause(thread, NULL); | 362 Handle h_cause(thread, NULL); |
373 return Exceptions::new_exception(thread, h_name, message, h_cause, h_loader, | 363 return Exceptions::new_exception(thread, name, message, h_cause, h_loader, |
374 h_prot, to_utf8_safe); | 364 h_prot, to_utf8_safe); |
375 } | 365 } |
376 | 366 |
377 // Implementation of ExceptionMark | 367 // Implementation of ExceptionMark |
378 | 368 |