Mercurial > hg > truffle
annotate src/share/vm/utilities/exceptions.cpp @ 4142:bc8527f3071c
Adjust code base to new level of warnings.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 18 Dec 2011 05:24:06 +0100 |
parents | 716a2c5c0656 |
children | 33df1aeaebbf |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2177
diff
changeset
|
2 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | |
27 #include "classfile/vmSymbols.hpp" | |
28 #include "compiler/compileBroker.hpp" | |
29 #include "oops/oop.inline.hpp" | |
30 #include "runtime/init.hpp" | |
31 #include "runtime/java.hpp" | |
32 #include "runtime/javaCalls.hpp" | |
33 #include "runtime/threadCritical.hpp" | |
34 #include "utilities/events.hpp" | |
35 #include "utilities/exceptions.hpp" | |
36 #ifdef TARGET_OS_FAMILY_linux | |
37 # include "thread_linux.inline.hpp" | |
38 #endif | |
39 #ifdef TARGET_OS_FAMILY_solaris | |
40 # include "thread_solaris.inline.hpp" | |
41 #endif | |
42 #ifdef TARGET_OS_FAMILY_windows | |
43 # include "thread_windows.inline.hpp" | |
44 #endif | |
3960 | 45 #ifdef TARGET_OS_FAMILY_bsd |
46 # include "thread_bsd.inline.hpp" | |
47 #endif | |
0 | 48 |
49 | |
50 // Implementation of ThreadShadow | |
51 void check_ThreadShadow() { | |
52 const ByteSize offset1 = byte_offset_of(ThreadShadow, _pending_exception); | |
53 const ByteSize offset2 = Thread::pending_exception_offset(); | |
54 if (offset1 != offset2) fatal("ThreadShadow::_pending_exception is not positioned correctly"); | |
55 } | |
56 | |
57 | |
58 void ThreadShadow::set_pending_exception(oop exception, const char* file, int line) { | |
59 assert(exception != NULL && exception->is_oop(), "invalid exception oop"); | |
60 _pending_exception = exception; | |
61 _exception_file = file; | |
62 _exception_line = line; | |
63 } | |
64 | |
65 void ThreadShadow::clear_pending_exception() { | |
66 if (TraceClearedExceptions) { | |
67 if (_pending_exception != NULL) { | |
68 tty->print_cr("Thread::clear_pending_exception: cleared exception:"); | |
69 _pending_exception->print(); | |
70 } | |
71 } | |
72 _pending_exception = NULL; | |
73 _exception_file = NULL; | |
74 _exception_line = 0; | |
75 } | |
76 // Implementation of Exceptions | |
77 | |
78 bool Exceptions::special_exception(Thread* thread, const char* file, int line, Handle h_exception) { | |
79 // bootstrapping check | |
80 if (!Universe::is_fully_initialized()) { | |
81 vm_exit_during_initialization(h_exception); | |
82 ShouldNotReachHere(); | |
83 } | |
84 | |
1867
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
85 #ifdef ASSERT |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
86 // Check for trying to throw stack overflow before initialization is complete |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
87 // to prevent infinite recursion trying to initialize stack overflow without |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
88 // adequate stack space. |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
89 // This can happen with stress testing a large value of StackShadowPages |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
90 if (h_exception()->klass() == SystemDictionary::StackOverflowError_klass()) { |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
91 instanceKlass* ik = instanceKlass::cast(h_exception->klass()); |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
92 assert(ik->is_initialized(), |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
93 "need to increase min_stack_allowed calculation"); |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
94 } |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
95 #endif // ASSERT |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
96 |
0 | 97 if (thread->is_VM_thread() |
4140
716a2c5c0656
Further reduce diff to HotSpot.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4137
diff
changeset
|
98 // TODO(tw): May we do this? |
1410
b30a2cd5e3a2
Added methods to c1x_VMExits.cpp
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1142
diff
changeset
|
99 /*|| thread->is_Compiler_thread()*/ ) { |
0 | 100 // We do not care what kind of exception we get for the vm-thread or a thread which |
101 // is compiling. We just install a dummy exception object | |
102 thread->set_pending_exception(Universe::vm_exception(), file, line); | |
103 return true; | |
104 } | |
105 | |
106 return false; | |
107 } | |
108 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
109 bool Exceptions::special_exception(Thread* thread, const char* file, int line, Symbol* h_name, const char* message) { |
0 | 110 // bootstrapping check |
111 if (!Universe::is_fully_initialized()) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
112 if (h_name == NULL) { |
0 | 113 // atleast an informative message. |
114 vm_exit_during_initialization("Exception", message); | |
115 } else { | |
116 vm_exit_during_initialization(h_name, message); | |
117 } | |
118 ShouldNotReachHere(); | |
119 } | |
120 | |
121 if (thread->is_VM_thread() | |
4140
716a2c5c0656
Further reduce diff to HotSpot.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4137
diff
changeset
|
122 // TODO(tw): May we do this? |
1410
b30a2cd5e3a2
Added methods to c1x_VMExits.cpp
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1142
diff
changeset
|
123 /* || thread->is_Compiler_thread()*/ ) { |
0 | 124 // We do not care what kind of exception we get for the vm-thread or a thread which |
125 // is compiling. We just install a dummy exception object | |
126 thread->set_pending_exception(Universe::vm_exception(), file, line); | |
127 return true; | |
128 } | |
129 return false; | |
130 } | |
131 | |
132 // This method should only be called from generated code, | |
133 // therefore the exception oop should be in the oopmap. | |
134 void Exceptions::_throw_oop(Thread* thread, const char* file, int line, oop exception) { | |
135 assert(exception != NULL, "exception should not be NULL"); | |
136 Handle h_exception = Handle(thread, exception); | |
137 _throw(thread, file, line, h_exception); | |
138 } | |
139 | |
1011
fcb148c6b605
6889302: TraceExceptions output should include detail message
never
parents:
0
diff
changeset
|
140 void Exceptions::_throw(Thread* thread, const char* file, int line, Handle h_exception, const char* message) { |
0 | 141 assert(h_exception() != NULL, "exception should not be NULL"); |
142 | |
143 // tracing (do this up front - so it works during boot strapping) | |
144 if (TraceExceptions) { | |
145 ttyLocker ttyl; | |
146 ResourceMark rm; | |
1011
fcb148c6b605
6889302: TraceExceptions output should include detail message
never
parents:
0
diff
changeset
|
147 tty->print_cr("Exception <%s>%s%s (" INTPTR_FORMAT " ) \n" |
fcb148c6b605
6889302: TraceExceptions output should include detail message
never
parents:
0
diff
changeset
|
148 "thrown [%s, line %d]\nfor thread " INTPTR_FORMAT, |
fcb148c6b605
6889302: TraceExceptions output should include detail message
never
parents:
0
diff
changeset
|
149 h_exception->print_value_string(), |
fcb148c6b605
6889302: TraceExceptions output should include detail message
never
parents:
0
diff
changeset
|
150 message ? ": " : "", message ? message : "", |
fcb148c6b605
6889302: TraceExceptions output should include detail message
never
parents:
0
diff
changeset
|
151 (address)h_exception(), file, line, thread); |
0 | 152 } |
153 // for AbortVMOnException flag | |
1684
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
154 NOT_PRODUCT(Exceptions::debug_check_abort(h_exception, message)); |
0 | 155 |
156 // Check for special boot-strapping/vm-thread handling | |
157 if (special_exception(thread, file, line, h_exception)) return; | |
158 | |
1142 | 159 assert(h_exception->is_a(SystemDictionary::Throwable_klass()), "exception is not a subclass of java/lang/Throwable"); |
0 | 160 |
161 // set the pending exception | |
162 thread->set_pending_exception(h_exception(), file, line); | |
163 | |
164 // vm log | |
165 Events::log("throw_exception " INTPTR_FORMAT, (address)h_exception()); | |
166 } | |
167 | |
168 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
169 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* h_name, const char* message, Handle h_loader, Handle h_protection_domain) { |
0 | 170 // Check for special boot-strapping/vm-thread handling |
171 if (special_exception(thread, file, line, h_name, message)) return; | |
172 // Create and throw exception | |
173 Handle h_cause(thread, NULL); | |
174 Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); | |
1011
fcb148c6b605
6889302: TraceExceptions output should include detail message
never
parents:
0
diff
changeset
|
175 _throw(thread, file, line, h_exception, message); |
0 | 176 } |
177 | |
178 // Throw an exception with a message and a cause | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
179 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) { |
0 | 180 // Check for special boot-strapping/vm-thread handling |
181 if (special_exception(thread, file, line, h_name, message)) return; | |
182 // Create and throw exception and init cause | |
183 Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); | |
1011
fcb148c6b605
6889302: TraceExceptions output should include detail message
never
parents:
0
diff
changeset
|
184 _throw(thread, file, line, h_exception, message); |
0 | 185 } |
186 | |
187 // This version already has a handle for name | |
188 void Exceptions::_throw_msg(Thread* thread, const char* file, int line, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
189 Symbol* name, const char* message) { |
0 | 190 Handle h_loader(thread, NULL); |
191 Handle h_protection_domain(thread, NULL); | |
192 Exceptions::_throw_msg(thread, file, line, name, message, h_loader, h_protection_domain); | |
193 } | |
194 | |
195 // This version already has a handle for name | |
196 void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
197 Symbol* name, const char* message, Handle cause) { |
0 | 198 Handle h_loader(thread, NULL); |
199 Handle h_protection_domain(thread, NULL); | |
200 Exceptions::_throw_msg_cause(thread, file, line, name, message, cause, h_loader, h_protection_domain); | |
201 } | |
202 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
203 void Exceptions::_throw_args(Thread* thread, const char* file, int line, Symbol* h_name, Symbol* h_signature, JavaCallArguments *args) { |
0 | 204 // Check for special boot-strapping/vm-thread handling |
205 if (special_exception(thread, file, line, h_name, NULL)) return; | |
206 // Create and throw exception | |
207 Handle h_loader(thread, NULL); | |
208 Handle h_prot(thread, NULL); | |
209 Handle h_cause(thread, NULL); | |
210 Handle exception = new_exception(thread, h_name, h_signature, args, h_cause, h_loader, h_prot); | |
211 _throw(thread, file, line, exception); | |
212 } | |
213 | |
214 | |
3272
01147d8aac1d
7009923: JSR 292: VM crash in JavaThread::last_frame
coleenp
parents:
2426
diff
changeset
|
215 void Exceptions::throw_stack_overflow_exception(Thread* THREAD, const char* file, int line, methodHandle method) { |
0 | 216 Handle exception; |
217 if (!THREAD->has_pending_exception()) { | |
218 klassOop k = SystemDictionary::StackOverflowError_klass(); | |
219 oop e = instanceKlass::cast(k)->allocate_instance(CHECK); | |
220 exception = Handle(THREAD, e); // fill_in_stack trace does gc | |
1867
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1684
diff
changeset
|
221 assert(instanceKlass::cast(k)->is_initialized(), "need to increase min_stack_allowed calculation"); |
0 | 222 if (StackTraceInThrowable) { |
3272
01147d8aac1d
7009923: JSR 292: VM crash in JavaThread::last_frame
coleenp
parents:
2426
diff
changeset
|
223 java_lang_Throwable::fill_in_stack_trace(exception, method()); |
0 | 224 } |
225 } else { | |
226 // if prior exception, throw that one instead | |
227 exception = Handle(THREAD, THREAD->pending_exception()); | |
228 } | |
3272
01147d8aac1d
7009923: JSR 292: VM crash in JavaThread::last_frame
coleenp
parents:
2426
diff
changeset
|
229 _throw(THREAD, file, line, exception); |
0 | 230 } |
231 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
232 void Exceptions::fthrow(Thread* thread, const char* file, int line, Symbol* h_name, const char* format, ...) { |
0 | 233 const int max_msg_size = 1024; |
234 va_list ap; | |
235 va_start(ap, format); | |
236 char msg[max_msg_size]; | |
237 vsnprintf(msg, max_msg_size, format, ap); | |
238 msg[max_msg_size-1] = '\0'; | |
239 va_end(ap); | |
240 _throw_msg(thread, file, line, h_name, msg); | |
241 } | |
242 | |
243 // Creates an exception oop, calls the <init> method with the given signature. | |
244 // and returns a Handle | |
245 // Initializes the cause if cause non-null | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
246 Handle Exceptions::new_exception(Thread *thread, Symbol* h_name, |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
247 Symbol* signature, |
0 | 248 JavaCallArguments *args, |
249 Handle h_cause, Handle h_loader, | |
250 Handle h_protection_domain) { | |
251 assert(Universe::is_fully_initialized(), | |
252 "cannot be called during initialization"); | |
253 assert(thread->is_Java_thread(), "can only be called by a Java thread"); | |
254 assert(!thread->has_pending_exception(), "already has exception"); | |
255 | |
256 Handle h_exception; | |
257 | |
258 // Resolve exception klass | |
259 klassOop ik = SystemDictionary::resolve_or_fail(h_name, h_loader, h_protection_domain, true, thread); | |
260 instanceKlassHandle klass (thread, ik); | |
261 | |
262 if (!thread->has_pending_exception()) { | |
263 assert(klass.not_null(), "klass must exist"); | |
264 // We are about to create an instance - so make sure that klass is initialized | |
265 klass->initialize(thread); | |
266 if (!thread->has_pending_exception()) { | |
267 // Allocate new exception | |
268 h_exception = klass->allocate_instance_handle(thread); | |
269 if (!thread->has_pending_exception()) { | |
270 JavaValue result(T_VOID); | |
271 args->set_receiver(h_exception); | |
272 // Call constructor | |
273 JavaCalls::call_special(&result, klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
274 vmSymbols::object_initializer_name(), |
0 | 275 signature, |
276 args, | |
277 thread); | |
278 | |
279 } | |
280 } | |
281 | |
282 // Future: object initializer should take a cause argument | |
283 if (h_cause() != NULL) { | |
1142 | 284 assert(h_cause->is_a(SystemDictionary::Throwable_klass()), |
0 | 285 "exception cause is not a subclass of java/lang/Throwable"); |
286 JavaValue result1(T_OBJECT); | |
287 JavaCallArguments args1; | |
288 args1.set_receiver(h_exception); | |
289 args1.push_oop(h_cause); | |
290 JavaCalls::call_virtual(&result1, klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
291 vmSymbols::initCause_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
292 vmSymbols::throwable_throwable_signature(), |
0 | 293 &args1, |
294 thread); | |
295 } | |
296 } | |
297 | |
298 // Check if another exception was thrown in the process, if so rethrow that one | |
299 if (thread->has_pending_exception()) { | |
300 h_exception = Handle(thread, thread->pending_exception()); | |
301 thread->clear_pending_exception(); | |
302 } | |
303 return h_exception; | |
304 } | |
305 | |
306 // Convenience method. Calls either the <init>() or <init>(String) method when | |
307 // creating a new exception | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
308 Handle Exceptions::new_exception(Thread* thread, Symbol* h_name, |
0 | 309 const char* message, Handle h_cause, |
310 Handle h_loader, | |
311 Handle h_protection_domain, | |
312 ExceptionMsgToUtf8Mode to_utf8_safe) { | |
313 JavaCallArguments args; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
314 Symbol* signature = NULL; |
0 | 315 if (message == NULL) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
316 signature = vmSymbols::void_method_signature(); |
0 | 317 } else { |
318 // We want to allocate storage, but we can't do that if there's | |
319 // a pending exception, so we preserve any pending exception | |
320 // around the allocation. | |
321 // If we get an exception from the allocation, prefer that to | |
322 // the exception we are trying to build, or the pending exception. | |
323 // This is sort of like what PRESERVE_EXCEPTION_MARK does, except | |
324 // for the preferencing and the early returns. | |
325 Handle incoming_exception (thread, NULL); | |
326 if (thread->has_pending_exception()) { | |
327 incoming_exception = Handle(thread, thread->pending_exception()); | |
328 thread->clear_pending_exception(); | |
329 } | |
330 Handle msg; | |
331 if (to_utf8_safe == safe_to_utf8) { | |
332 // Make a java UTF8 string. | |
333 msg = java_lang_String::create_from_str(message, thread); | |
334 } else { | |
335 // Make a java string keeping the encoding scheme of the original string. | |
336 msg = java_lang_String::create_from_platform_dependent_str(message, thread); | |
337 } | |
338 if (thread->has_pending_exception()) { | |
339 Handle exception(thread, thread->pending_exception()); | |
340 thread->clear_pending_exception(); | |
341 return exception; | |
342 } | |
343 if (incoming_exception.not_null()) { | |
344 return incoming_exception; | |
345 } | |
346 args.push_oop(msg); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
347 signature = vmSymbols::string_void_signature(); |
0 | 348 } |
349 return new_exception(thread, h_name, signature, &args, h_cause, h_loader, h_protection_domain); | |
350 } | |
351 | |
352 // Another convenience method that creates handles for null class loaders and | |
353 // protection domains and null causes. | |
354 // If the last parameter 'to_utf8_mode' is safe_to_utf8, | |
355 // it means we can safely ignore the encoding scheme of the message string and | |
356 // convert it directly to a java UTF8 string. Otherwise, we need to take the | |
357 // encoding scheme of the string into account. One thing we should do at some | |
358 // point is to push this flag down to class java_lang_String since other | |
359 // classes may need similar functionalities. | |
360 Handle Exceptions::new_exception(Thread* thread, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
361 Symbol* name, |
0 | 362 const char* message, |
363 ExceptionMsgToUtf8Mode to_utf8_safe) { | |
364 | |
365 Handle h_loader(thread, NULL); | |
366 Handle h_prot(thread, NULL); | |
367 Handle h_cause(thread, NULL); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
368 return Exceptions::new_exception(thread, name, message, h_cause, h_loader, |
0 | 369 h_prot, to_utf8_safe); |
370 } | |
371 | |
372 // Implementation of ExceptionMark | |
373 | |
374 ExceptionMark::ExceptionMark(Thread*& thread) { | |
375 thread = Thread::current(); | |
376 _thread = thread; | |
377 if (_thread->has_pending_exception()) { | |
378 oop exception = _thread->pending_exception(); | |
379 _thread->clear_pending_exception(); // Needed to avoid infinite recursion | |
380 exception->print(); | |
381 fatal("ExceptionMark constructor expects no pending exceptions"); | |
382 } | |
383 } | |
384 | |
385 | |
386 ExceptionMark::~ExceptionMark() { | |
387 if (_thread->has_pending_exception()) { | |
388 Handle exception(_thread, _thread->pending_exception()); | |
389 _thread->clear_pending_exception(); // Needed to avoid infinite recursion | |
390 if (is_init_completed()) { | |
391 exception->print(); | |
392 fatal("ExceptionMark destructor expects no pending exceptions"); | |
393 } else { | |
394 vm_exit_during_initialization(exception); | |
395 } | |
396 } | |
397 } | |
398 | |
399 // ---------------------------------------------------------------------------------------- | |
400 | |
401 #ifndef PRODUCT | |
402 // caller frees value_string if necessary | |
1684
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
403 void Exceptions::debug_check_abort(const char *value_string, const char* message) { |
0 | 404 if (AbortVMOnException != NULL && value_string != NULL && |
405 strstr(value_string, AbortVMOnException)) { | |
1684
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
406 if (AbortVMOnExceptionMessage == NULL || message == NULL || |
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
407 strcmp(message, AbortVMOnExceptionMessage) == 0) { |
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
408 fatal(err_msg("Saw %s, aborting", value_string)); |
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
409 } |
0 | 410 } |
411 } | |
412 | |
1684
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
413 void Exceptions::debug_check_abort(Handle exception, const char* message) { |
0 | 414 if (AbortVMOnException != NULL) { |
415 ResourceMark rm; | |
1684
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
416 if (message == NULL && exception->is_a(SystemDictionary::Throwable_klass())) { |
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
417 oop msg = java_lang_Throwable::message(exception); |
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
418 if (msg != NULL) { |
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
419 message = java_lang_String::as_utf8_string(msg); |
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
420 } |
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
421 } |
66c5dadb4d61
6973308: Missing zero length check before repne scas in check_klass_subtype_slow_path()
kvn
parents:
1552
diff
changeset
|
422 debug_check_abort(instanceKlass::cast(exception()->klass())->external_name(), message); |
0 | 423 } |
424 } | |
425 #endif |