author | serb |
Thu, 31 May 2018 09:24:27 -0700 | |
changeset 50357 | 2e0c4b2d567b |
parent 47216 | 71c04702a3d5 |
child 52744 | 8b066aaff367 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
50357
2e0c4b2d567b
8202051: Address compilation warnings in libawt with VS2017
serb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
#include "awt.h" |
|
26 |
#include "awt_Toolkit.h" |
|
27 |
#include "debug_mem.h" |
|
28 |
||
29 |
extern void DumpJavaStack(); |
|
30 |
||
31 |
#if defined(DEBUG) |
|
32 |
||
33 |
//////////////////////////////////////////////////////////////////////////////////// |
|
34 |
// avoid pulling in our redefinition of 'new' |
|
35 |
// since we actually need to implement it here |
|
36 |
#if defined(new) |
|
37 |
#undef new |
|
38 |
#endif |
|
39 |
// |
|
40 |
||
41 |
void * operator new(size_t size, const char * filename, int linenumber) { |
|
42 |
void * ptr = DMem_AllocateBlock(size, filename, linenumber); |
|
43 |
if (ptr == NULL) { |
|
44 |
throw std::bad_alloc(); |
|
45 |
} |
|
46 |
||
47 |
return ptr; |
|
48 |
} |
|
49 |
||
7772
bf119e738928
6999766: Changes to correct c/c++ language issues for use of parfait
dav
parents:
5506
diff
changeset
|
50 |
void * operator new[](size_t size, const char * filename, int linenumber) { |
bf119e738928
6999766: Changes to correct c/c++ language issues for use of parfait
dav
parents:
5506
diff
changeset
|
51 |
void * ptr = DMem_AllocateBlock(size, filename, linenumber); |
bf119e738928
6999766: Changes to correct c/c++ language issues for use of parfait
dav
parents:
5506
diff
changeset
|
52 |
if (ptr == NULL) { |
bf119e738928
6999766: Changes to correct c/c++ language issues for use of parfait
dav
parents:
5506
diff
changeset
|
53 |
throw std::bad_alloc(); |
bf119e738928
6999766: Changes to correct c/c++ language issues for use of parfait
dav
parents:
5506
diff
changeset
|
54 |
} |
bf119e738928
6999766: Changes to correct c/c++ language issues for use of parfait
dav
parents:
5506
diff
changeset
|
55 |
|
bf119e738928
6999766: Changes to correct c/c++ language issues for use of parfait
dav
parents:
5506
diff
changeset
|
56 |
return ptr; |
bf119e738928
6999766: Changes to correct c/c++ language issues for use of parfait
dav
parents:
5506
diff
changeset
|
57 |
} |
bf119e738928
6999766: Changes to correct c/c++ language issues for use of parfait
dav
parents:
5506
diff
changeset
|
58 |
|
2 | 59 |
void operator delete(void *ptr, const char*, int) { |
60 |
DASSERTMSG(FALSE, "This version of 'delete' should never get called!!!"); |
|
61 |
} |
|
50357
2e0c4b2d567b
8202051: Address compilation warnings in libawt with VS2017
serb
parents:
47216
diff
changeset
|
62 |
|
2e0c4b2d567b
8202051: Address compilation warnings in libawt with VS2017
serb
parents:
47216
diff
changeset
|
63 |
void operator delete[](void *ptr, const char*, int) { |
2e0c4b2d567b
8202051: Address compilation warnings in libawt with VS2017
serb
parents:
47216
diff
changeset
|
64 |
DASSERTMSG(FALSE, "This version of 'delete' should never get called!!!"); |
2e0c4b2d567b
8202051: Address compilation warnings in libawt with VS2017
serb
parents:
47216
diff
changeset
|
65 |
} |
2e0c4b2d567b
8202051: Address compilation warnings in libawt with VS2017
serb
parents:
47216
diff
changeset
|
66 |
|
7772
bf119e738928
6999766: Changes to correct c/c++ language issues for use of parfait
dav
parents:
5506
diff
changeset
|
67 |
void operator delete(void *ptr) throw() { |
2 | 68 |
DMem_FreeBlock(ptr); |
69 |
} |
|
70 |
||
71 |
//////////////////////////////////////////////////////////////////////////////////// |
|
72 |
||
73 |
static void DumpRegion(HRGN rgn) { |
|
74 |
DWORD size = ::GetRegionData(rgn, 0, NULL); |
|
75 |
char* buffer = (char *)safe_Malloc(size); |
|
76 |
memset(buffer, 0, size); |
|
77 |
LPRGNDATA rgndata = (LPRGNDATA)buffer; |
|
78 |
rgndata->rdh.dwSize = sizeof(RGNDATAHEADER); |
|
79 |
rgndata->rdh.iType = RDH_RECTANGLES; |
|
80 |
VERIFY(::GetRegionData(rgn, size, rgndata)); |
|
81 |
||
82 |
RECT* r = (RECT*)(buffer + rgndata->rdh.dwSize); |
|
83 |
for (DWORD i=0; i<rgndata->rdh.nCount; i++) { |
|
84 |
if ( !::IsRectEmpty(r) ) { |
|
85 |
DTrace_PrintImpl("\trect %d %d %d %d\n", r->left, r->top, r->right, r->bottom); |
|
86 |
} |
|
87 |
r++; |
|
88 |
} |
|
89 |
||
90 |
free(buffer); |
|
91 |
} |
|
92 |
||
93 |
/* |
|
94 |
* DTRACE print callback to dump HDC clip region bounding rectangle |
|
95 |
*/ |
|
96 |
void DumpClipRectangle(const char * file, int line, int argc, const char * fmt, va_list arglist) { |
|
97 |
const char *msg = va_arg(arglist, const char *); |
|
98 |
HDC hdc = va_arg(arglist, HDC); |
|
99 |
RECT r; |
|
100 |
||
101 |
DASSERT(argc == 2 && hdc != NULL); |
|
102 |
DASSERT(msg != NULL); |
|
103 |
||
104 |
::GetClipBox(hdc, &r); |
|
105 |
DTrace_PrintImpl("%s: hdc=%x, %d %d %d %d\n", msg, hdc, r.left, r.top, r.right, r.bottom); |
|
106 |
} |
|
107 |
||
108 |
/* |
|
109 |
* DTRACE print callback to dump window's update region bounding rectangle |
|
110 |
*/ |
|
111 |
void DumpUpdateRectangle(const char * file, int line, int argc, const char * fmt, va_list arglist) { |
|
112 |
const char *msg = va_arg(arglist, const char *); |
|
113 |
HWND hwnd = va_arg(arglist, HWND); |
|
114 |
RECT r; |
|
115 |
||
116 |
DASSERT(argc == 2 && ::IsWindow(hwnd)); |
|
117 |
DASSERT(msg != NULL); |
|
118 |
||
119 |
::GetUpdateRect(hwnd, &r, FALSE); |
|
120 |
HRGN rgn = ::CreateRectRgn(0,0,1,1); |
|
121 |
int updated = ::GetUpdateRgn(hwnd, rgn, FALSE); |
|
122 |
DTrace_PrintImpl("%s: hwnd=%x, %d %d %d %d\n", msg, hwnd, r.left, r.top, r.right, r.bottom); |
|
123 |
DumpRegion(rgn); |
|
124 |
DeleteObject(rgn); |
|
125 |
} |
|
126 |
||
127 |
// |
|
128 |
// Declare a static object to init/fini the debug code |
|
129 |
// |
|
130 |
// specify that this static object will get constructed before |
|
131 |
// any other static objects (except CRT objects) so the debug |
|
132 |
// code can be used anywhere during the lifetime of the AWT dll |
|
133 |
#pragma warning( disable:4073 ) // disable warning about using init_seg(lib) in non-3rd party library code |
|
134 |
#pragma init_seg( lib ) |
|
135 |
||
136 |
static volatile AwtDebugSupport DebugSupport; |
|
137 |
static int report_leaks = 0; |
|
138 |
||
139 |
AwtDebugSupport::AwtDebugSupport() { |
|
140 |
DMem_Initialize(); |
|
141 |
DTrace_Initialize(); |
|
142 |
DAssert_SetCallback(AssertCallback); |
|
143 |
} |
|
144 |
||
145 |
AwtDebugSupport::~AwtDebugSupport() { |
|
146 |
if (report_leaks) { |
|
147 |
DMem_ReportLeaks(); |
|
148 |
} |
|
149 |
DMem_Shutdown(); |
|
150 |
DTrace_Shutdown(); |
|
151 |
} |
|
152 |
||
14883
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
153 |
static jboolean isHeadless() { |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
154 |
jmethodID headlessFn; |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
155 |
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
156 |
jclass graphicsEnvClass = env->FindClass( |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
157 |
"java/awt/GraphicsEnvironment"); |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
158 |
|
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
159 |
if (graphicsEnvClass != NULL) { |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
160 |
headlessFn = env->GetStaticMethodID( |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
161 |
graphicsEnvClass, "isHeadless", "()Z"); |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
162 |
if (headlessFn != NULL) { |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
163 |
return env->CallStaticBooleanMethod(graphicsEnvClass, |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
164 |
headlessFn); |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
165 |
} |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
166 |
} |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
167 |
return true; |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
168 |
} |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
169 |
|
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
170 |
|
2 | 171 |
void AwtDebugSupport::AssertCallback(const char * expr, const char * file, int line) { |
172 |
static const int ASSERT_MSG_SIZE = 1024; |
|
173 |
static const char * AssertFmt = |
|
174 |
"%s\r\n" |
|
175 |
"File '%s', at line %d\r\n" |
|
176 |
"GetLastError() is %x : %s\r\n" |
|
177 |
"Do you want to break into the debugger?"; |
|
178 |
||
179 |
static char assertMsg[ASSERT_MSG_SIZE+1]; |
|
180 |
DWORD lastError = GetLastError(); |
|
181 |
LPSTR msgBuffer = NULL; |
|
14883
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
182 |
int ret = IDNO; |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
183 |
static jboolean headless = isHeadless(); |
2 | 184 |
|
185 |
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
|
186 |
FORMAT_MESSAGE_FROM_SYSTEM | |
|
187 |
FORMAT_MESSAGE_IGNORE_INSERTS, |
|
188 |
NULL, |
|
189 |
lastError, |
|
190 |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
|
191 |
(LPSTR)&msgBuffer, // it's an output parameter when allocate buffer is used |
|
192 |
0, |
|
193 |
NULL); |
|
194 |
||
195 |
if (msgBuffer == NULL) { |
|
196 |
msgBuffer = "<Could not get GetLastError() message text>"; |
|
197 |
} |
|
198 |
// format the assertion message |
|
199 |
_snprintf(assertMsg, ASSERT_MSG_SIZE, AssertFmt, expr, file, line, lastError, msgBuffer); |
|
200 |
LocalFree(msgBuffer); |
|
201 |
||
202 |
// tell the user the bad news |
|
203 |
fprintf(stderr, "*********************\n"); |
|
204 |
fprintf(stderr, "AWT Assertion Failure\n"); |
|
205 |
fprintf(stderr, "*********************\n"); |
|
206 |
fprintf(stderr, "%s\n", assertMsg); |
|
207 |
fprintf(stderr, "*********************\n"); |
|
14883
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
208 |
|
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
209 |
if (!headless) { |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
210 |
ret = MessageBoxA(NULL, assertMsg, "AWT Assertion Failure", |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
211 |
MB_YESNO|MB_ICONSTOP|MB_TASKMODAL); |
524cf4063ab3
7180359: Assertion in awt_Win32GraphicsDevice.cpp when running specjbb in jprt
jgodinez
parents:
9035
diff
changeset
|
212 |
} |
2 | 213 |
|
214 |
// if clicked Yes, break into the debugger |
|
215 |
if ( ret == IDYES ) { |
|
216 |
# if defined(_M_IX86) |
|
217 |
_asm { int 3 }; |
|
218 |
# else |
|
219 |
DebugBreak(); |
|
220 |
# endif |
|
221 |
} |
|
222 |
// otherwise, try to continue execution |
|
223 |
} |
|
224 |
||
225 |
void AwtDebugSupport::GenerateLeaksReport() { |
|
226 |
report_leaks = 1; |
|
227 |
} |
|
228 |
||
229 |
#endif // DEBUG |