Thu, 20 Nov 2008 16:56:09 -0800
6684579: SoftReference processing can be made more efficient
Summary: For current soft-ref clearing policies, we can decide at marking time if a soft-reference will definitely not be cleared, postponing the decision of whether it will definitely be cleared to the final reference processing phase. This can be especially beneficial in the case of concurrent collectors where the marking is usually concurrent but reference processing is usually not.
Reviewed-by: jmasa
1 /*
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 // assertions
26 #ifdef ASSERT
27 // Turn this off by default:
28 //#define USE_REPEATED_ASSERTS
29 #ifdef USE_REPEATED_ASSERTS
30 #define assert(p,msg) \
31 { for (int __i = 0; __i < AssertRepeat; __i++) { \
32 if (!(p)) { \
33 report_assertion_failure(__FILE__, __LINE__, \
34 "assert(" XSTR(p) ",\"" msg "\")");\
35 BREAKPOINT; \
36 } \
37 } \
38 }
39 #else
40 #define assert(p,msg) \
41 if (!(p)) { \
42 report_assertion_failure(__FILE__, __LINE__, \
43 "assert(" XSTR(p) ",\"" msg "\")");\
44 BREAKPOINT; \
45 }
46 #endif
48 // This version of assert is for use with checking return status from
49 // library calls that return actual error values eg. EINVAL,
50 // ENOMEM etc, rather than returning -1 and setting errno.
51 // When the status is not what is expected it is very useful to know
52 // what status was actually returned, so we pass the status variable as
53 // an extra arg and use strerror to convert it to a meaningful string
54 // like "Invalid argument", "out of memory" etc
55 #define assert_status(p, status, msg) \
56 do { \
57 if (!(p)) { \
58 char buf[128]; \
59 snprintf(buf, 127, \
60 "assert_status(" XSTR(p) ", error: %s(%d), \"" msg "\")" , \
61 strerror((status)), (status)); \
62 report_assertion_failure(__FILE__, __LINE__, buf); \
63 BREAKPOINT; \
64 } \
65 } while (0)
67 // Another version of assert where the message is not a string literal
68 // The boolean condition is not printed out because cpp doesn't like it.
69 #define assert_msg(p, msg) \
70 if (!(p)) { \
71 report_assertion_failure(__FILE__, __LINE__, msg); \
72 BREAKPOINT; \
73 }
75 // Do not assert this condition if there's already another error reported.
76 #define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)
77 #else
78 #define assert(p,msg)
79 #define assert_status(p,status,msg)
80 #define assert_if_no_error(cond,msg)
81 #define assert_msg(cond,msg)
82 #endif
85 // fatals
86 #define fatal(m) { report_fatal(__FILE__, __LINE__, m ); BREAKPOINT; }
87 #define fatal1(m,x1) { report_fatal_vararg(__FILE__, __LINE__, m, x1 ); BREAKPOINT; }
88 #define fatal2(m,x1,x2) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2 ); BREAKPOINT; }
89 #define fatal3(m,x1,x2,x3) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2, x3 ); BREAKPOINT; }
90 #define fatal4(m,x1,x2,x3,x4) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2, x3, x4 ); BREAKPOINT; }
92 // out of memory
93 #define vm_exit_out_of_memory(s,m) { report_vm_out_of_memory(__FILE__, __LINE__, s, m ); BREAKPOINT; }
94 #define vm_exit_out_of_memory1(s,m,x1) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1 ); BREAKPOINT; }
95 #define vm_exit_out_of_memory2(s,m,x1,x2) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2 ); BREAKPOINT; }
96 #define vm_exit_out_of_memory3(s,m,x1,x2,x3) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2, x3 ); BREAKPOINT; }
97 #define vm_exit_out_of_memory4(s,m,x1,x2,x3,x4) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2, x3, x4); BREAKPOINT; }
99 // guarantee is like assert except it's always executed -- use it for
100 // cheap tests that catch errors that would otherwise be hard to find
101 // guarantee is also used for Verify options.
102 #define guarantee(b,msg) { if (!(b)) fatal("guarantee(" XSTR(b) ",\"" msg "\")"); }
104 #define ShouldNotCallThis() { report_should_not_call (__FILE__, __LINE__); BREAKPOINT; }
105 #define ShouldNotReachHere() { report_should_not_reach_here (__FILE__, __LINE__); BREAKPOINT; }
106 #define Unimplemented() { report_unimplemented (__FILE__, __LINE__); BREAKPOINT; }
107 #define Untested(msg) { report_untested (__FILE__, __LINE__, msg); BREAKPOINT; }
109 // error reporting helper functions
110 void report_assertion_failure(const char* file_name, int line_no, const char* message);
111 void report_fatal_vararg(const char* file_name, int line_no, const char* format, ...);
112 void report_fatal(const char* file_name, int line_no, const char* message);
113 void report_vm_out_of_memory_vararg(const char* file_name, int line_no, size_t size, const char* format, ...);
114 void report_vm_out_of_memory(const char* file_name, int line_no, size_t size, const char* message);
115 void report_should_not_call(const char* file_name, int line_no);
116 void report_should_not_reach_here(const char* file_name, int line_no);
117 void report_unimplemented(const char* file_name, int line_no);
118 void report_untested(const char* file_name, int line_no, const char* msg);
119 void warning(const char* format, ...);
121 // out of memory reporting
122 void report_java_out_of_memory(const char* message);
124 // Support for self-destruct
125 bool is_error_reported();
126 void set_error_reported();
128 void pd_ps(frame f);
129 void pd_obfuscate_location(char *buf, size_t buflen);