Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/net/Message.cpp
6000 views
1
/*******************************************************************************
2
/*******************************************************************************
3
* Copyright (c) 2020, 2022 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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
22
*******************************************************************************/
23
24
#include "net/Message.hpp"
25
#include "infra/Assert.hpp"
26
#include "env/VerboseLog.hpp"
27
28
namespace JITServer
29
{
30
const char* const Message::DataDescriptor::_descriptorNames[] = {
31
"INT32",
32
"INT64",
33
"UINT32",
34
"UINT64",
35
"BOOL",
36
"STRING",
37
"OBJECT",
38
"ENUM",
39
"VECTOR",
40
"SIMPLE_VECTOR",
41
"EMPTY_VECTOR",
42
"TUPLE",
43
"INVALID"
44
};
45
46
uint32_t
47
Message::addData(const DataDescriptor &desc, const void *dataStart, bool needs64BitAlignment)
48
{
49
// Write the descriptor itself
50
uint32_t descOffset = _buffer.writeValue(desc);
51
52
// If the data following the descriptor needs to be 64-bit aligned,
53
// add some initial padding in the outgoing buffer and write the
54
// offset to the real payload into the descriptor
55
uint8_t initialPadding = 0;
56
if (needs64BitAlignment && !_buffer.is64BitAligned())
57
{
58
initialPadding = _buffer.alignCurrentPositionOn64Bit();
59
TR_ASSERT(initialPadding != 0, "Initial padding must be non zero because we checked alignment");
60
DataDescriptor *serializedDescriptor = _buffer.getValueAtOffset<DataDescriptor>(descOffset);
61
serializedDescriptor->addInitialPadding(initialPadding);
62
}
63
64
// Write the real data and possibly some padding at the end
65
_buffer.writeData(dataStart, desc.getPayloadSize(), desc.getPaddingSize());
66
_descriptorOffsets.push_back(descOffset);
67
return desc.getTotalSize() + initialPadding;
68
}
69
70
void
71
Message::deserialize()
72
{
73
// Assume that buffer is populated with data that defines a valid message
74
// Reconstruct the message by setting metadata and pointers to descriptors
75
// Note that the size of the entire message buffer has already been stripped
76
//
77
_buffer.readValue<MetaData>(); // This only advances curPtr in the MessageBuffer
78
79
uint32_t numDataPoints = getMetaData()->_numDataPoints;
80
81
_descriptorOffsets.reserve(numDataPoints);
82
// TODO: do I need to clear the vector of _descriptorOffsets just in case?
83
for (uint32_t i = 0; i < numDataPoints; ++i)
84
{
85
uint32_t descOffset = _buffer.readValue<DataDescriptor>(); // Read the descriptor itself
86
_descriptorOffsets.push_back(descOffset);
87
88
// skip the data segment, which is processed in getArgs
89
_buffer.readData(getLastDescriptor()->getTotalSize());
90
}
91
}
92
93
uint32_t
94
Message::DataDescriptor::print(uint32_t nestingLevel)
95
{
96
uint32_t numDescriptorsPrinted = 1;
97
TR_VerboseLog::write(TR_Vlog_JITServer, "");
98
for (uint32_t i = 0; i < nestingLevel; ++i)
99
TR_VerboseLog::write("\t");
100
TR_VerboseLog::writeLine("DataDescriptor[%p]: type=%d(%6s) payload_size=%u dataOffset=%u, padding=%u",
101
this, getDataType(), _descriptorNames[getDataType()], getPayloadSize(), getDataOffset(), getPaddingSize());
102
if (!isPrimitive())
103
{
104
TR_VerboseLog::writeLine(TR_Vlog_JITServer, "DataDescriptor[%p]: nested data begin", this);
105
DataDescriptor *curDesc = static_cast<DataDescriptor *>(getDataStart());
106
while ((char *) curDesc->getDataStart() + curDesc->getTotalSize() - (char *) getDataStart() <= getTotalSize())
107
{
108
numDescriptorsPrinted += curDesc->print(nestingLevel + 1);
109
curDesc = curDesc->getNextDescriptor();
110
}
111
TR_VerboseLog::writeLine(TR_Vlog_JITServer, "DataDescriptor[%p] nested data end", this);
112
}
113
114
return numDescriptorsPrinted;
115
}
116
117
void
118
Message::print()
119
{
120
const MetaData *metaData = getMetaData();
121
TR_VerboseLog::CriticalSection vlogLock;
122
TR_VerboseLog::writeLine(TR_Vlog_JITServer, "Message: type=%d numDataPoints=%u version=%lu numDescriptors=%lu\n",
123
metaData->_type, metaData->_numDataPoints, metaData->_version, _descriptorOffsets.size());
124
uint32_t numDescriptorsPrinted = 0;
125
for (uint32_t i = 0; i < _descriptorOffsets.size(); i += numDescriptorsPrinted)
126
{
127
DataDescriptor* desc = getDescriptor(i);
128
numDescriptorsPrinted = desc->print(0);
129
}
130
}
131
};
132
133