comparison src/share/vm/utilities/exceptions.cpp @ 2181:d25d4ca69222

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