Skip to content

Commit 4aa1e64

Browse files
authored
Merge pull request #19741 from tajila/jfr
JFR Writer part 2
2 parents 69c0709 + 4be3c05 commit 4aa1e64

12 files changed

+3573
-38
lines changed

runtime/oti/vm_api.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,29 @@ internalExceptionDescribe(J9VMThread *vmThread);
847847
UDATA
848848
iterateStackTrace(J9VMThread * vmThread, j9object_t* exception, UDATA (*callback) (J9VMThread * vmThread, void * userData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass), void * userData, UDATA pruneConstructors, UDATA skipHiddenFrames);
849849

850+
/**
851+
* @brief
852+
* @param vmThread
853+
* @param exception
854+
* @param vmThread
855+
* @param userData
856+
* @param bytecodeOffset
857+
* @param romClass
858+
* @param romMethod
859+
* @param fileName
860+
* @param lineNumber
861+
* @param classLoader
862+
* @param ramClass)
863+
* @param userData
864+
* @param pruneConstructors
865+
* @param skipHiddenFrames
866+
* @param sizeOfWalkstateCache
867+
* @param exceptionIsJavaObject
868+
* @return UDATA
869+
*/
870+
UDATA
871+
iterateStackTraceImpl(J9VMThread * vmThread, j9object_t* exception, UDATA (*callback) (J9VMThread * vmThread, void * userData, UDATA bytecodeOffset, J9ROMClass * romClass, J9ROMMethod * romMethod, J9UTF8 * fileName, UDATA lineNumber, J9ClassLoader* classLoader, J9Class* ramClass), void * userData, UDATA pruneConstructors, UDATA skipHiddenFrames, UDATA sizeOfWalkstateCache, BOOLEAN exceptionIsJavaObject);
872+
850873

851874
/* ---------------- exceptionsupport.c ---------------- */
852875

runtime/vm/BufferWriter.hpp

Lines changed: 344 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,344 @@
1+
/*******************************************************************************
2+
* Copyright IBM Corp. and others 2024
3+
*
4+
* This program and the accompanying materials are made available under
5+
* the terms of the Eclipse Public License 2.0 which accompanies this
6+
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7+
* or the Apache License, Version 2.0 which accompanies this distribution and
8+
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
*
10+
* This Source Code may also be made available under the following
11+
* Secondary Licenses when the conditions for such availability set
12+
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13+
* General Public License, version 2 with the GNU Classpath
14+
* Exception [1] and GNU General Public License, version 2 with the
15+
* OpenJDK Assembly Exception [2].
16+
*
17+
* [1] https://www.gnu.org/software/classpath/license.html
18+
* [2] https://openjdk.org/legal/assembly-exception.html
19+
*
20+
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
21+
*******************************************************************************/
22+
23+
#if !defined(BUFFERWRITER_HPP_)
24+
#define BUFFERWRITER_HPP_
25+
26+
#include "j9cfg.h"
27+
#include "j9.h"
28+
29+
class VM_BufferWriter {
30+
/*
31+
* Data members
32+
*/
33+
private:
34+
U_8* _buffer;
35+
U_8* _cursor;
36+
UDATA _size;
37+
38+
U_8* _maxCursor;
39+
40+
#if defined(J9VM_ENV_LITTLE_ENDIAN)
41+
static const bool _isLE = true;
42+
#else
43+
static const bool _isLE = false;
44+
#endif
45+
46+
protected:
47+
48+
public:
49+
50+
/*
51+
* Function members
52+
*/
53+
private:
54+
static VMINLINE U_16
55+
byteSwap(U_16 val)
56+
{
57+
U_16 swapped = ((val & 0xFF00) >> 8);
58+
swapped |= ((val & 0x00FF) << 8);
59+
60+
return swapped;
61+
}
62+
63+
static VMINLINE U_32
64+
byteSwap(U_32 val)
65+
{
66+
U_32 swapped = ((val & 0xFF000000) >> 24);
67+
swapped |= ((val & 0x00FF0000) >> 8);
68+
swapped |= ((val & 0x0000FF00) << 8);
69+
swapped |= ((val & 0x000000FF) << 24);
70+
71+
return swapped;
72+
}
73+
74+
static VMINLINE U_64
75+
byteSwap(U_64 val)
76+
{
77+
U_64 swapped = ((val & 0xFF00000000000000) >> 56);
78+
swapped |= ((val & 0x00FF000000000000) >> 40);
79+
swapped |= ((val & 0x0000FF0000000000) >> 24);
80+
swapped |= ((val & 0x000000FF00000000) >> 8);
81+
swapped |= ((val & 0x00000000FF000000) << 8);
82+
swapped |= ((val & 0x0000000000FF0000) << 24);
83+
swapped |= ((val & 0x000000000000FF00) << 40);
84+
swapped |= ((val & 0x00000000000000FF) << 56);
85+
86+
return swapped;
87+
}
88+
89+
protected:
90+
91+
public:
92+
93+
VM_BufferWriter(U_8 *buffer, UDATA size)
94+
: _buffer(buffer)
95+
, _cursor(buffer)
96+
, _size(size)
97+
{
98+
_maxCursor = NULL;
99+
}
100+
101+
U_64
102+
getFileOffset(U_8* bufferOffset, U_8* from)
103+
{
104+
return (U_64)((UDATA)bufferOffset - (UDATA)from);
105+
}
106+
107+
U_64
108+
getFileOffsetFromStart(U_8* bufferOffset)
109+
{
110+
return getFileOffset(bufferOffset, _buffer);
111+
}
112+
113+
U_8*
114+
getBufferStart()
115+
{
116+
return _buffer;
117+
}
118+
119+
UDATA
120+
getSize()
121+
{
122+
return getMaxCursor() - _buffer;
123+
}
124+
125+
void
126+
writeU8(U_8 val)
127+
{
128+
*_cursor = val;
129+
_cursor += sizeof(U_8);
130+
}
131+
132+
void
133+
writeU16(U_16 val)
134+
{
135+
U_16 newVal = val;
136+
if (_isLE) {
137+
newVal = byteSwap(val);
138+
}
139+
*(U_16*)_cursor = newVal;
140+
_cursor += sizeof(U_16);
141+
}
142+
143+
void
144+
writeU32(U_32 val)
145+
{
146+
U_32 newVal = val;
147+
if (_isLE) {
148+
newVal = byteSwap(val);
149+
}
150+
*(U_32*)_cursor = newVal;
151+
_cursor += sizeof(U_32);
152+
}
153+
154+
void
155+
writeU64(U_64 val)
156+
{
157+
U_64 newVal = val;
158+
if (_isLE) {
159+
newVal = byteSwap(val);
160+
}
161+
*(U_64*)_cursor = newVal;
162+
_cursor += sizeof(U_64);
163+
}
164+
165+
void
166+
writeData(U_8 *data, UDATA size)
167+
{
168+
memcpy(_cursor, data, size);
169+
_cursor += size;
170+
}
171+
172+
U_8*
173+
getAndIncCursor(UDATA size)
174+
{
175+
U_8 *old = _cursor;
176+
_cursor += size;
177+
178+
return old;
179+
}
180+
181+
U_8*
182+
getCursor()
183+
{
184+
return _cursor;
185+
}
186+
U_8*
187+
getMaxCursor()
188+
{
189+
if ((UDATA)_cursor > (UDATA)_maxCursor) {
190+
_maxCursor = _cursor;
191+
}
192+
return _maxCursor;
193+
}
194+
195+
void
196+
setCursor(U_8* cursor)
197+
{
198+
getMaxCursor();
199+
_cursor = cursor;
200+
}
201+
202+
void
203+
writeLEB128(U_64 val)
204+
{
205+
U_64 newVal = val;
206+
if (!_isLE) {
207+
newVal = byteSwap(val);
208+
}
209+
do {
210+
U_8 byte = newVal & 0x7F;
211+
newVal >>= 7;
212+
213+
if (newVal > 0) {
214+
byte |= 0x80;
215+
}
216+
writeU8(byte);
217+
} while(newVal > 0);
218+
}
219+
220+
void
221+
writeLEB128PaddedU64(U_8* cursor, U_64 val)
222+
{
223+
U_8* old = _cursor;
224+
_cursor = cursor;
225+
writeLEB128PaddedU64(val);
226+
_cursor = old;
227+
}
228+
229+
void
230+
writeLEB128PaddedU64(U_64 val)
231+
{
232+
U_64 newVal = val;
233+
if (!_isLE) {
234+
newVal = byteSwap(val);
235+
}
236+
writeU8((newVal & 0x7F) | 0x80);
237+
writeU8(((newVal >> 7) & 0x7F) | 0x80);
238+
writeU8(((newVal >> 14) & 0x7F) | 0x80);
239+
writeU8(((newVal >> 21) & 0x7F) | 0x80);
240+
writeU8(((newVal >> 28) & 0x7F) | 0x80);
241+
writeU8(((newVal >> 35) & 0x7F) | 0x80);
242+
writeU8(((newVal >> 42) & 0x7F) | 0x80);
243+
writeU8(((newVal >> 49) & 0x7F));
244+
}
245+
246+
void
247+
writeLEB128PaddedU32(U_8* cursor, U_32 val)
248+
{
249+
U_8* old = _cursor;
250+
_cursor = cursor;
251+
writeLEB128PaddedU32(val);
252+
_cursor = old;
253+
}
254+
255+
void
256+
writeLEB128PaddedU32(U_32 val)
257+
{
258+
U_64 newVal = val;
259+
if (!_isLE) {
260+
newVal = byteSwap(val);
261+
}
262+
writeU8((newVal & 0x7F) | 0x80);
263+
writeU8(((newVal >> 7) & 0x7F) | 0x80);
264+
writeU8(((newVal >> 14) & 0x7F) | 0x80);
265+
writeU8(((newVal >> 21) & 0x7F));
266+
}
267+
268+
static U_32
269+
convertFromLEB128ToU32(U_8* start)
270+
{
271+
U_32 val = 0;
272+
273+
val = *start & 0x7F;
274+
275+
if (J9_ARE_ALL_BITS_SET(*start, 0x80)) {
276+
start++;
277+
val |= (*start & 0X7F) << 7;
278+
}
279+
280+
if (J9_ARE_ALL_BITS_SET(*start, 0x80)) {
281+
start++;
282+
val |= (*start & 0X7F) << 14;
283+
}
284+
285+
if (J9_ARE_ALL_BITS_SET(*start, 0x80)) {
286+
start++;
287+
val |= (*start & 0X7F) << 21;
288+
}
289+
if (!_isLE) {
290+
val = byteSwap(val);
291+
}
292+
return val;
293+
}
294+
295+
static U_64
296+
convertFromLEB128ToU64(U_8* start)
297+
{
298+
U_64 val = 0;
299+
300+
val = *start & 0x7F;
301+
302+
if (J9_ARE_ALL_BITS_SET(*start, 0x80)) {
303+
start++;
304+
val |= (U_64)(*start & 0X7F) << 7;
305+
}
306+
307+
if (J9_ARE_ALL_BITS_SET(*start, 0x80)) {
308+
start++;
309+
val |= (U_64)(*start & 0X7F) << 14;
310+
}
311+
312+
if (J9_ARE_ALL_BITS_SET(*start, 0x80)) {
313+
start++;
314+
val |= (U_64)(*start & 0X7F) << 21;
315+
}
316+
317+
if (J9_ARE_ALL_BITS_SET(*start, 0x80)) {
318+
start++;
319+
val |= (U_64)(*start & 0X7F) << 28;
320+
}
321+
322+
if (J9_ARE_ALL_BITS_SET(*start, 0x80)) {
323+
start++;
324+
val |= (U_64)(*start & 0X7F) << 35;
325+
}
326+
327+
if (J9_ARE_ALL_BITS_SET(*start, 0x80)) {
328+
start++;
329+
val |= (U_64)(*start & 0X7F) << 42;
330+
}
331+
332+
if (J9_ARE_ALL_BITS_SET(*start, 0x80)) {
333+
start++;
334+
val |= (U_64)(*start & 0X7F) << 59;
335+
}
336+
if (!_isLE) {
337+
val = byteSwap(val);
338+
}
339+
return val;
340+
}
341+
342+
};
343+
344+
#endif /* BUFFERWRITER_HPP_ */

runtime/vm/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ endif()
198198
if(J9VM_OPT_JFR)
199199
list(APPEND main_sources
200200
jfr.cpp
201+
JFRConstantPoolTypes.cpp
202+
JFRChunkWriter.cpp
201203
)
202204
endif()
203205

0 commit comments

Comments
 (0)