comparison src/share/vm/utilities/exceptions.cpp @ 4834:74d14a44c398

Added tag jdk7u60-b01 for changeset 8fd0e931efa5
author asaha
date Wed, 27 Nov 2013 14:57:31 -0800
parents aa3d708d67c4
children de5e8c8a9b87
comparison
equal deleted inserted replaced
12:be0002438c13 13:a6b189db5b90
162 // vm log 162 // vm log
163 Events::log_exception(thread, "Threw " INTPTR_FORMAT " at %s:%d", (address)h_exception(), file, line); 163 Events::log_exception(thread, "Threw " INTPTR_FORMAT " at %s:%d", (address)h_exception(), file, line);
164 } 164 }
165 165
166 166
167 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 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* name, const char* message,
168 Handle h_loader, Handle h_protection_domain) {
168 // Check for special boot-strapping/vm-thread handling 169 // Check for special boot-strapping/vm-thread handling
169 if (special_exception(thread, file, line, h_name, message)) return; 170 if (special_exception(thread, file, line, name, message)) return;
170 // Create and throw exception 171 // Create and throw exception
171 Handle h_cause(thread, NULL); 172 Handle h_cause(thread, NULL);
172 Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); 173 Handle h_exception = new_exception(thread, name, message, h_cause, h_loader, h_protection_domain);
173 _throw(thread, file, line, h_exception, message); 174 _throw(thread, file, line, h_exception, message);
174 } 175 }
175 176
176 // Throw an exception with a message and a cause 177 void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, Symbol* name, const char* message, Handle h_cause,
177 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) { 178 Handle h_loader, Handle h_protection_domain) {
178 // Check for special boot-strapping/vm-thread handling 179 // Check for special boot-strapping/vm-thread handling
179 if (special_exception(thread, file, line, h_name, message)) return; 180 if (special_exception(thread, file, line, name, message)) return;
180 // Create and throw exception and init cause 181 // Create and throw exception and init cause
181 Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); 182 Handle h_exception = new_exception(thread, name, message, h_cause, h_loader, h_protection_domain);
182 _throw(thread, file, line, h_exception, message); 183 _throw(thread, file, line, h_exception, message);
183 } 184 }
184 185
185 // This version already has a handle for name 186 void Exceptions::_throw_cause(Thread* thread, const char* file, int line, Symbol* name, Handle h_cause,
186 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, 187 Handle h_loader, Handle h_protection_domain) {
187 Symbol* name, const char* message) {
188 Handle h_loader(thread, NULL);
189 Handle h_protection_domain(thread, NULL);
190 Exceptions::_throw_msg(thread, file, line, name, message, h_loader, h_protection_domain);
191 }
192
193 // This version already has a handle for name
194 void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line,
195 Symbol* name, const char* message, Handle cause) {
196 Handle h_loader(thread, NULL);
197 Handle h_protection_domain(thread, NULL);
198 Exceptions::_throw_msg_cause(thread, file, line, name, message, cause, h_loader, h_protection_domain);
199 }
200
201 void Exceptions::_throw_args(Thread* thread, const char* file, int line, Symbol* h_name, Symbol* h_signature, JavaCallArguments *args) {
202 // Check for special boot-strapping/vm-thread handling 188 // Check for special boot-strapping/vm-thread handling
203 if (special_exception(thread, file, line, h_name, NULL)) return; 189 if (special_exception(thread, file, line, h_cause)) return;
190 // Create and throw exception
191 Handle h_exception = new_exception(thread, name, h_cause, h_loader, h_protection_domain);
192 _throw(thread, file, line, h_exception, NULL);
193 }
194
195 void Exceptions::_throw_args(Thread* thread, const char* file, int line, Symbol* name, Symbol* signature, JavaCallArguments *args) {
196 // Check for special boot-strapping/vm-thread handling
197 if (special_exception(thread, file, line, name, NULL)) return;
204 // Create and throw exception 198 // Create and throw exception
205 Handle h_loader(thread, NULL); 199 Handle h_loader(thread, NULL);
206 Handle h_prot(thread, NULL); 200 Handle h_prot(thread, NULL);
207 Handle h_cause(thread, NULL); 201 Handle exception = new_exception(thread, name, signature, args, h_loader, h_prot);
208 Handle exception = new_exception(thread, h_name, h_signature, args, h_cause, h_loader, h_prot);
209 _throw(thread, file, line, exception); 202 _throw(thread, file, line, exception);
203 }
204
205
206 // Methods for default parameters.
207 // NOTE: These must be here (and not in the header file) because of include circularities.
208 void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, Symbol* name, const char* message, Handle h_cause) {
209 _throw_msg_cause(thread, file, line, name, message, h_cause, Handle(thread, NULL), Handle(thread, NULL));
210 }
211 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* name, const char* message) {
212 _throw_msg(thread, file, line, name, message, Handle(thread, NULL), Handle(thread, NULL));
213 }
214 void Exceptions::_throw_cause(Thread* thread, const char* file, int line, Symbol* name, Handle h_cause) {
215 _throw_cause(thread, file, line, name, h_cause, Handle(thread, NULL), Handle(thread, NULL));
210 } 216 }
211 217
212 218
213 void Exceptions::throw_stack_overflow_exception(Thread* THREAD, const char* file, int line, methodHandle method) { 219 void Exceptions::throw_stack_overflow_exception(Thread* THREAD, const char* file, int line, methodHandle method) {
214 Handle exception; 220 Handle exception;
238 _throw_msg(thread, file, line, h_name, msg); 244 _throw_msg(thread, file, line, h_name, msg);
239 } 245 }
240 246
241 // Creates an exception oop, calls the <init> method with the given signature. 247 // Creates an exception oop, calls the <init> method with the given signature.
242 // and returns a Handle 248 // and returns a Handle
243 // Initializes the cause if cause non-null 249 Handle Exceptions::new_exception(Thread *thread, Symbol* name,
244 Handle Exceptions::new_exception(Thread *thread, Symbol* h_name, 250 Symbol* signature, JavaCallArguments *args,
245 Symbol* signature, 251 Handle h_loader, Handle h_protection_domain) {
246 JavaCallArguments *args,
247 Handle h_cause, Handle h_loader,
248 Handle h_protection_domain) {
249 assert(Universe::is_fully_initialized(), 252 assert(Universe::is_fully_initialized(),
250 "cannot be called during initialization"); 253 "cannot be called during initialization");
251 assert(thread->is_Java_thread(), "can only be called by a Java thread"); 254 assert(thread->is_Java_thread(), "can only be called by a Java thread");
252 assert(!thread->has_pending_exception(), "already has exception"); 255 assert(!thread->has_pending_exception(), "already has exception");
253 256
254 Handle h_exception; 257 Handle h_exception;
255 258
256 // Resolve exception klass 259 // Resolve exception klass
257 klassOop ik = SystemDictionary::resolve_or_fail(h_name, h_loader, h_protection_domain, true, thread); 260 klassOop ik = SystemDictionary::resolve_or_fail(name, h_loader, h_protection_domain, true, thread);
258 instanceKlassHandle klass (thread, ik); 261 instanceKlassHandle klass(thread, ik);
259 262
260 if (!thread->has_pending_exception()) { 263 if (!thread->has_pending_exception()) {
261 assert(klass.not_null(), "klass must exist"); 264 assert(klass.not_null(), "klass must exist");
262 // We are about to create an instance - so make sure that klass is initialized 265 // We are about to create an instance - so make sure that klass is initialized
263 klass->initialize(thread); 266 klass->initialize(thread);
271 JavaCalls::call_special(&result, klass, 274 JavaCalls::call_special(&result, klass,
272 vmSymbols::object_initializer_name(), 275 vmSymbols::object_initializer_name(),
273 signature, 276 signature,
274 args, 277 args,
275 thread); 278 thread);
276
277 } 279 }
278 }
279
280 // Future: object initializer should take a cause argument
281 if (h_cause() != NULL) {
282 assert(h_cause->is_a(SystemDictionary::Throwable_klass()),
283 "exception cause is not a subclass of java/lang/Throwable");
284 JavaValue result1(T_OBJECT);
285 JavaCallArguments args1;
286 args1.set_receiver(h_exception);
287 args1.push_oop(h_cause);
288 JavaCalls::call_virtual(&result1, klass,
289 vmSymbols::initCause_name(),
290 vmSymbols::throwable_throwable_signature(),
291 &args1,
292 thread);
293 } 280 }
294 } 281 }
295 282
296 // Check if another exception was thrown in the process, if so rethrow that one 283 // Check if another exception was thrown in the process, if so rethrow that one
297 if (thread->has_pending_exception()) { 284 if (thread->has_pending_exception()) {
299 thread->clear_pending_exception(); 286 thread->clear_pending_exception();
300 } 287 }
301 return h_exception; 288 return h_exception;
302 } 289 }
303 290
291 // Creates an exception oop, calls the <init> method with the given signature.
292 // and returns a Handle
293 // Initializes the cause if cause non-null
294 Handle Exceptions::new_exception(Thread *thread, Symbol* name,
295 Symbol* signature, JavaCallArguments *args,
296 Handle h_cause,
297 Handle h_loader, Handle h_protection_domain) {
298 Handle h_exception = new_exception(thread, name, signature, args, h_loader, h_protection_domain);
299
300 // Future: object initializer should take a cause argument
301 if (h_cause.not_null()) {
302 assert(h_cause->is_a(SystemDictionary::Throwable_klass()),
303 "exception cause is not a subclass of java/lang/Throwable");
304 JavaValue result1(T_OBJECT);
305 JavaCallArguments args1;
306 args1.set_receiver(h_exception);
307 args1.push_oop(h_cause);
308 JavaCalls::call_virtual(&result1, h_exception->klass(),
309 vmSymbols::initCause_name(),
310 vmSymbols::throwable_throwable_signature(),
311 &args1,
312 thread);
313 }
314
315 // Check if another exception was thrown in the process, if so rethrow that one
316 if (thread->has_pending_exception()) {
317 h_exception = Handle(thread, thread->pending_exception());
318 thread->clear_pending_exception();
319 }
320 return h_exception;
321 }
322
323 // Convenience method. Calls either the <init>() or <init>(Throwable) method when
324 // creating a new exception
325 Handle Exceptions::new_exception(Thread* thread, Symbol* name,
326 Handle h_cause,
327 Handle h_loader, Handle h_protection_domain,
328 ExceptionMsgToUtf8Mode to_utf8_safe) {
329 JavaCallArguments args;
330 Symbol* signature = NULL;
331 if (h_cause.is_null()) {
332 signature = vmSymbols::void_method_signature();
333 } else {
334 signature = vmSymbols::throwable_void_signature();
335 args.push_oop(h_cause);
336 }
337 return new_exception(thread, name, signature, &args, h_loader, h_protection_domain);
338 }
339
304 // Convenience method. Calls either the <init>() or <init>(String) method when 340 // Convenience method. Calls either the <init>() or <init>(String) method when
305 // creating a new exception 341 // creating a new exception
306 Handle Exceptions::new_exception(Thread* thread, Symbol* h_name, 342 Handle Exceptions::new_exception(Thread* thread, Symbol* name,
307 const char* message, Handle h_cause, 343 const char* message, Handle h_cause,
308 Handle h_loader, 344 Handle h_loader, Handle h_protection_domain,
309 Handle h_protection_domain,
310 ExceptionMsgToUtf8Mode to_utf8_safe) { 345 ExceptionMsgToUtf8Mode to_utf8_safe) {
311 JavaCallArguments args; 346 JavaCallArguments args;
312 Symbol* signature = NULL; 347 Symbol* signature = NULL;
313 if (message == NULL) { 348 if (message == NULL) {
314 signature = vmSymbols::void_method_signature(); 349 signature = vmSymbols::void_method_signature();
318 // around the allocation. 353 // around the allocation.
319 // If we get an exception from the allocation, prefer that to 354 // If we get an exception from the allocation, prefer that to
320 // the exception we are trying to build, or the pending exception. 355 // the exception we are trying to build, or the pending exception.
321 // This is sort of like what PRESERVE_EXCEPTION_MARK does, except 356 // This is sort of like what PRESERVE_EXCEPTION_MARK does, except
322 // for the preferencing and the early returns. 357 // for the preferencing and the early returns.
323 Handle incoming_exception (thread, NULL); 358 Handle incoming_exception(thread, NULL);
324 if (thread->has_pending_exception()) { 359 if (thread->has_pending_exception()) {
325 incoming_exception = Handle(thread, thread->pending_exception()); 360 incoming_exception = Handle(thread, thread->pending_exception());
326 thread->clear_pending_exception(); 361 thread->clear_pending_exception();
327 } 362 }
328 Handle msg; 363 Handle msg;
342 return incoming_exception; 377 return incoming_exception;
343 } 378 }
344 args.push_oop(msg); 379 args.push_oop(msg);
345 signature = vmSymbols::string_void_signature(); 380 signature = vmSymbols::string_void_signature();
346 } 381 }
347 return new_exception(thread, h_name, signature, &args, h_cause, h_loader, h_protection_domain); 382 return new_exception(thread, name, signature, &args, h_cause, h_loader, h_protection_domain);
348 } 383 }
349 384
350 // Another convenience method that creates handles for null class loaders and 385 // Another convenience method that creates handles for null class loaders and
351 // protection domains and null causes. 386 // protection domains and null causes.
352 // If the last parameter 'to_utf8_mode' is safe_to_utf8, 387 // If the last parameter 'to_utf8_mode' is safe_to_utf8,
353 // it means we can safely ignore the encoding scheme of the message string and 388 // it means we can safely ignore the encoding scheme of the message string and
354 // convert it directly to a java UTF8 string. Otherwise, we need to take the 389 // convert it directly to a java UTF8 string. Otherwise, we need to take the
355 // encoding scheme of the string into account. One thing we should do at some 390 // encoding scheme of the string into account. One thing we should do at some
356 // point is to push this flag down to class java_lang_String since other 391 // point is to push this flag down to class java_lang_String since other
357 // classes may need similar functionalities. 392 // classes may need similar functionalities.
358 Handle Exceptions::new_exception(Thread* thread, 393 Handle Exceptions::new_exception(Thread* thread, Symbol* name,
359 Symbol* name,
360 const char* message, 394 const char* message,
361 ExceptionMsgToUtf8Mode to_utf8_safe) { 395 ExceptionMsgToUtf8Mode to_utf8_safe) {
362 396
363 Handle h_loader(thread, NULL); 397 Handle h_loader(thread, NULL);
364 Handle h_prot(thread, NULL); 398 Handle h_prot(thread, NULL);