Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/bcutil/WritingCursor.cpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2014 IBM Corp. and others
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] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
/*
23
* WritingCursor.cpp
24
*/
25
26
#include "ROMClassStringInternManager.hpp"
27
#include "WritingCursor.hpp"
28
#include <stdlib.h>
29
#include "ut_j9bcu.h"
30
#include "j9.h"
31
32
void
33
WritingCursor::writeU8(U_8 u8Value, DataType dataType)
34
{
35
U_8 *u8Addr = (U_8 *)(_baseAddress + _count);
36
*u8Addr = u8Value;
37
_count += sizeof(U_8);
38
}
39
40
void
41
WritingCursor::writeU16(U_16 u16Value, DataType dataType)
42
{
43
U_16 *u16Addr = (U_16 *)(_baseAddress + _count);
44
*u16Addr = u16Value;
45
_count += sizeof(U_16);
46
}
47
48
void
49
WritingCursor::writeU32(U_32 u32Value, DataType dataType)
50
{
51
U_32 *u32Addr = (U_32 *)(_baseAddress + _count);
52
*u32Addr = u32Value;
53
_count += sizeof(U_32);
54
}
55
56
void
57
WritingCursor::writeU64(U_32 u32ValueHigh, U_32 u32ValueLow, DataType dataType)
58
{
59
U_64 *u64Addr = (U_64 *)(_baseAddress + _count);
60
61
#ifdef J9VM_ENV_LITTLE_ENDIAN
62
*u64Addr = (U_64(u32ValueLow) << 32) + u32ValueHigh;
63
#else
64
*u64Addr = (U_64(u32ValueHigh) << 32) + u32ValueLow;
65
#endif
66
67
_count += sizeof(U_64);
68
}
69
70
void
71
WritingCursor::writeUTF8(U_8* UTF8Data, U_16 UTF8Length, DataType dataType)
72
{
73
/* intern this string */
74
J9UTF8 *utf8Ptr = (J9UTF8 *)(_baseAddress + _count);
75
Cursor::writeUTF8(UTF8Data, UTF8Length, dataType);
76
_internManager->internString(utf8Ptr);
77
}
78
79
void
80
WritingCursor::writeSRP(UDATA srpKey, DataType dataType)
81
{
82
J9SRP *srpAddr = (J9SRP *)(_baseAddress + _count);
83
*srpAddr = computeSRP(srpKey, srpAddr);
84
_count += sizeof(J9SRP);
85
}
86
87
void
88
WritingCursor::writeWSRP(UDATA srpKey, DataType dataType)
89
{
90
J9WSRP *wsrpAddr = (J9WSRP *)(_baseAddress + _count);
91
*wsrpAddr = computeWSRP(srpKey, wsrpAddr);
92
_count += sizeof(J9WSRP);
93
}
94
95
void
96
WritingCursor::writeData(U_8* bytes, UDATA length, DataType dataType)
97
{
98
U_8 *u8Addr = (U_8 *)(_baseAddress + _count);
99
memcpy(u8Addr, bytes, length);
100
_count += length;
101
}
102
103
void
104
WritingCursor::padToAlignment(UDATA byteAlignment, DataType dataType)
105
{
106
U_8 *startAddr = (U_8 *)(_baseAddress + _count);
107
Cursor::padToAlignment(byteAlignment, dataType);
108
U_8 *endAddr = (U_8 *)(_baseAddress + _count);
109
memset(startAddr, 0, endAddr - startAddr);
110
}
111
112
void
113
WritingCursor::mark(UDATA srpKey)
114
{
115
Trc_BCU_Assert_Equals(_count, getOffsetForSRPKey(srpKey));
116
}
117
118