Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/bridge/AccessBridgeDebug.cpp
32287 views
1
/*
2
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
24
*/
25
26
/*
27
* A class to manage AccessBridge debugging
28
*/
29
30
#include "AccessBridgeDebug.h"
31
#include <stdarg.h>
32
#include <stdio.h>
33
#include <windows.h>
34
#include <cstdlib>
35
#include <cstring>
36
37
#ifdef __cplusplus
38
extern "C" {
39
#endif
40
41
static FILE* logFP = nullptr;
42
43
void initializeFileLogger(char * fileName) {
44
auto var = "JAVA_ACCESSBRIDGE_LOGDIR";
45
const auto envfilePath = getenv(var);
46
if (envfilePath != nullptr && fileName != nullptr) {
47
auto envFilePathLength = strlen(envfilePath);
48
auto fileNameLength = strlen(fileName);
49
auto filePathSize = envFilePathLength + 1 + fileNameLength + 5; //1 for "/", 5 for ".log" and 0;
50
auto filePath = new char[filePathSize];
51
memset(filePath, 0, filePathSize*sizeof(char));
52
memcpy(filePath, envfilePath, envFilePathLength*sizeof(char));
53
filePath[envFilePathLength] = '/';
54
memcpy(filePath + envFilePathLength + 1, fileName, fileNameLength*sizeof(char));
55
memcpy(filePath + envFilePathLength + 1 + fileNameLength, ".log", 4*sizeof(char));
56
57
logFP = fopen(filePath, "w");
58
if (logFP == nullptr) {
59
printf("\n%s\n", filePath);
60
PrintDebugString("Could not open file %s", filePath);
61
}
62
63
delete [] filePath;
64
}
65
}
66
67
void finalizeFileLogger() {
68
if (logFP) {
69
fclose(logFP);
70
logFP = nullptr;
71
}
72
}
73
74
auto getTimeStamp() -> long long {
75
LARGE_INTEGER freqLarge;
76
::QueryPerformanceFrequency(&freqLarge);
77
long long freq = freqLarge.QuadPart;
78
LARGE_INTEGER counterLarge;
79
::QueryPerformanceCounter(&counterLarge);
80
long long counter = counterLarge.QuadPart;
81
long long milliDen = 1000;
82
// prevent possible overflow
83
long long whole = (counter / freq) * milliDen;
84
long long part = (counter % freq) * milliDen / freq;
85
return whole + part;
86
}
87
88
/**
89
* Send debugging info to the appropriate place
90
*/
91
void PrintDebugString(char *msg, ...) {
92
#ifdef DEBUGGING_ON
93
char buf[1024] = {0};
94
va_list argprt;
95
96
va_start(argprt, msg); // set up argptr
97
vsprintf(buf, msg, argprt);
98
#ifdef SEND_TO_OUTPUT_DEBUG_STRING
99
OutputDebugString(buf);
100
#endif
101
#ifdef SEND_TO_CONSOLE
102
printf(buf);
103
printf("\r\n");
104
#endif
105
#endif
106
if (logFP) {
107
fprintf(logFP, "[%llu] ", getTimeStamp());
108
va_list args;
109
va_start(args, msg);
110
vfprintf(logFP, msg, args);
111
va_end(args);
112
fprintf(logFP, "\r\n");
113
}
114
}
115
116
/**
117
* Send Java debugging info to the appropriate place
118
*/
119
void PrintJavaDebugString2(char *msg, ...) {
120
#ifdef JAVA_DEBUGGING_ON
121
char buf[1024] = {0};
122
va_list argprt;
123
124
va_start(argprt, msg); // set up argptr
125
vsprintf(buf, msg, argprt);
126
#ifdef SEND_TO_OUTPUT_DEBUG_STRING
127
OutputDebugString(buf);
128
#endif
129
#ifdef SEND_TO_CONSOLE
130
printf(buf);
131
printf("\r\n");
132
#endif
133
#endif
134
if (logFP) {
135
fprintf(logFP, "[%llu] ", getTimeStamp());
136
va_list args;
137
va_start(args, msg);
138
vfprintf(logFP, msg, args);
139
va_end(args);
140
fprintf(logFP, "\r\n");
141
}
142
}
143
/**
144
* Wide version of the method to send debugging info to the appropriate place
145
*/
146
void wPrintDebugString(wchar_t *msg, ...) {
147
#ifdef DEBUGGING_ON
148
char buf[1024] = {0};
149
char charmsg[256];
150
va_list argprt;
151
152
va_start(argprt, msg); // set up argptr
153
sprintf(charmsg, "%ls", msg); // convert format string to multi-byte
154
vsprintf(buf, charmsg, argprt);
155
#ifdef SEND_TO_OUTPUT_DEBUG_STRING
156
OutputDebugString(buf);
157
#endif
158
#ifdef SEND_TO_CONSOLE
159
printf(buf);
160
printf("\r\n");
161
#endif
162
#endif
163
if (logFP) {
164
fprintf(logFP, "[%llu] ", getTimeStamp());
165
va_list args;
166
va_start(args, msg);
167
vfwprintf(logFP, msg, args);
168
va_end(args);
169
fprintf(logFP, "\r\n");
170
}
171
}
172
173
/**
174
* Wide version of the method to send Java debugging info to the appropriate place
175
*/
176
void wPrintJavaDebugString(wchar_t *msg, ...) {
177
#ifdef JAVA_DEBUGGING_ON
178
char buf[1024] = {0};
179
char charmsg[256] = {0};
180
va_list argprt;
181
182
va_start(argprt, msg); // set up argptr
183
sprintf(charmsg, "%ls", msg); // convert format string to multi-byte
184
vsprintf(buf, charmsg, argprt);
185
#ifdef SEND_TO_OUTPUT_DEBUG_STRING
186
OutputDebugString(buf);
187
#endif
188
#ifdef SEND_TO_CONSOLE
189
printf(buf);
190
printf("\r\n");
191
#endif
192
#endif
193
if (logFP) {
194
fprintf(logFP, "[%llu] ", getTimeStamp());
195
va_list args;
196
va_start(args, msg);
197
vfwprintf(logFP, msg, args);
198
va_end(args);
199
fprintf(logFP, "\r\n");
200
}
201
}
202
#ifdef __cplusplus
203
}
204
#endif
205
206