Skip to content

Commit e64429f

Browse files
committedJun 26, 2018
Make VirtualMachineState into extensible class
In preparation for creating a JitBuilder extension for VirtualMachineState, to facilitate the client API creation, the VirtualMachineState class needs to become more like a fully extensible with an independent header. Also change references to OMR::VirtualMachineState to TR::VirtualMachineState. Signed-off-by: Mark Stoodley <mstoodle@ca.ibm.com>
1 parent d0995a3 commit e64429f

11 files changed

+190
-115
lines changed
 

‎compiler/ilgen/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ compiler_library(ilgen
2929
${CMAKE_CURRENT_LIST_DIR}/OMRIlType.cpp
3030
${CMAKE_CURRENT_LIST_DIR}/OMRTypeDictionary.cpp
3131
${CMAKE_CURRENT_LIST_DIR}/OMRThunkBuilder.cpp
32+
${CMAKE_CURRENT_LIST_DIR}/OMRVirtualMachineState.cpp
3233
${CMAKE_CURRENT_LIST_DIR}/VirtualMachineOperandStack.cpp
3334
)

‎compiler/ilgen/MethodBuilder.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace TR
3232
MethodBuilder(TR::TypeDictionary *types)
3333
: OMR::MethodBuilder(types)
3434
{ }
35-
MethodBuilder(TR::TypeDictionary *types, OMR::VirtualMachineState *vmState)
35+
MethodBuilder(TR::TypeDictionary *types, TR::VirtualMachineState *vmState)
3636
: OMR::MethodBuilder(types, vmState)
3737
{ }
3838
};

‎compiler/ilgen/OMRBytecodeBuilder.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ OMR::BytecodeBuilder::setHandlerInfo(uint32_t catchType)
195195
}
196196

197197
void
198-
OMR::BytecodeBuilder::propagateVMState(OMR::VirtualMachineState *fromVMState)
198+
OMR::BytecodeBuilder::propagateVMState(TR::VirtualMachineState *fromVMState)
199199
{
200-
_initialVMState = (OMR::VirtualMachineState *) fromVMState->MakeCopy();
201-
_vmState = (OMR::VirtualMachineState *) fromVMState->MakeCopy();
200+
_initialVMState = fromVMState->MakeCopy();
201+
_vmState = fromVMState->MakeCopy();
202202
}
203203

204204
// transferVMState needs to be called before the actual transfer operation (Goto, IfCmp,

‎compiler/ilgen/OMRBytecodeBuilder.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace TR { class BytecodeBuilder; }
2828
namespace TR { class MethodBuilder; }
29-
namespace OMR { class VirtualMachineState; }
29+
namespace TR { class VirtualMachineState; }
3030

3131
namespace OMR
3232
{
@@ -59,11 +59,11 @@ class BytecodeBuilder : public TR::IlBuilder
5959
void AddSuccessorBuilders(uint32_t numBuilders, ...);
6060
void AddSuccessorBuilder(TR::BytecodeBuilder **b) { AddSuccessorBuilders(1, b); }
6161

62-
OMR::VirtualMachineState *initialVMState() { return _initialVMState; }
63-
OMR::VirtualMachineState *vmState() { return _vmState; }
64-
void setVMState(OMR::VirtualMachineState *vmState) { _vmState = vmState; }
62+
TR::VirtualMachineState *initialVMState() { return _initialVMState; }
63+
TR::VirtualMachineState *vmState() { return _vmState; }
64+
void setVMState(TR::VirtualMachineState *vmState) { _vmState = vmState; }
6565

66-
void propagateVMState(OMR::VirtualMachineState *fromVMState);
66+
void propagateVMState(TR::VirtualMachineState *fromVMState);
6767

6868
// The following control flow services are meant to hide the similarly named services
6969
// provided by the IlBuilder class. The reason these implementations exist is to
@@ -102,8 +102,8 @@ class BytecodeBuilder : public TR::IlBuilder
102102
List<TR::BytecodeBuilder> * _successorBuilders;
103103
int32_t _bcIndex;
104104
char * _name;
105-
OMR::VirtualMachineState * _initialVMState;
106-
OMR::VirtualMachineState * _vmState;
105+
TR::VirtualMachineState * _initialVMState;
106+
TR::VirtualMachineState * _vmState;
107107

108108
virtual void appendBlock(TR::Block *block = 0, bool addEdge=true);
109109
void addAllSuccessorBuildersToWorklist();

‎compiler/ilgen/OMRMethodBuilder.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@
7070
// into the builder.
7171
//
7272

73-
namespace OMR
74-
{
75-
7673
// Note: _memoryRegion and the corresponding TR::SegmentProvider and TR::Memory instances are stored as pointers within MethodBuilder
7774
// in order to avoid increasing the number of header files needed to compile against the JitBuilder library. Because we are storing
7875
// them as pointers, we cannot rely on the default C++ destruction semantic to destruct and deallocate the memory region, but rather

‎compiler/ilgen/OMRMethodBuilder.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TR_BitVector;
3535
namespace TR { class BytecodeBuilder; }
3636
namespace TR { class ResolvedMethod; }
3737
namespace TR { class SymbolReference; }
38-
namespace OMR { class VirtualMachineState; }
38+
namespace TR { class VirtualMachineState; }
3939

4040
namespace TR { class SegmentProvider; }
4141
namespace TR { class Region; }
@@ -49,7 +49,7 @@ class MethodBuilder : public TR::IlBuilder
4949
public:
5050
TR_ALLOC(TR_Memory::IlGenerator)
5151

52-
MethodBuilder(TR::TypeDictionary *types, OMR::VirtualMachineState *vmState = NULL);
52+
MethodBuilder(TR::TypeDictionary *types, TR::VirtualMachineState *vmState = NULL);
5353
MethodBuilder(const MethodBuilder &src);
5454
virtual ~MethodBuilder();
5555

@@ -66,8 +66,8 @@ class MethodBuilder : public TR::IlBuilder
6666
void addToTreeConnectingWorklist(TR::BytecodeBuilder *builder);
6767
void addToBlockCountingWorklist(TR::BytecodeBuilder *builder);
6868

69-
OMR::VirtualMachineState *vmState() { return _vmState; }
70-
void setVMState(OMR::VirtualMachineState *vmState) { _vmState = vmState; }
69+
TR::VirtualMachineState *vmState() { return _vmState; }
70+
void setVMState(TR::VirtualMachineState *vmState) { _vmState = vmState; }
7171

7272
virtual bool isMethodBuilder() { return true; }
7373
virtual TR::MethodBuilder *asMethodBuilder();
@@ -240,7 +240,7 @@ class MethodBuilder : public TR::IlBuilder
240240
List<TR::BytecodeBuilder> * _countBlocksWorklist;
241241
List<TR::BytecodeBuilder> * _connectTreesWorklist;
242242
List<TR::BytecodeBuilder> * _allBytecodeBuilders;
243-
OMR::VirtualMachineState * _vmState;
243+
TR::VirtualMachineState * _vmState;
244244

245245
TR_BitVector * _bytecodeWorklist;
246246
TR_BitVector * _bytecodeHasBeenInWorklist;
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2016, 2018 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 http://eclipse.org/legal/epl-2.0
7+
* or the Apache License, Version 2.0 which accompanies this distribution
8+
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
*
10+
* This Source Code may also be made available under the following Secondary
11+
* Licenses when the conditions for such availability set forth in the
12+
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
13+
* version 2 with the GNU Classpath Exception [1] and GNU General Public
14+
* License, version 2 with the OpenJDK Assembly Exception [2].
15+
*
16+
* [1] https://www.gnu.org/software/classpath/license.html
17+
* [2] http://openjdk.java.net/legal/assembly-exception.html
18+
*
19+
* 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
20+
*******************************************************************************/
21+
22+
#include "ilgen/VirtualMachineState.hpp"
23+
24+
namespace TR { class IlBuilder; }
25+
class TR_Memory;
26+
27+
template <class T> class List;
28+
template <class T> class ListAppender;
29+
30+
TR::VirtualMachineState *
31+
OMR::VirtualMachineState::MakeCopy()
32+
{
33+
return static_cast<TR::VirtualMachineState *>(this);
34+
}
+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2016, 2018 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 http://eclipse.org/legal/epl-2.0
7+
* or the Apache License, Version 2.0 which accompanies this distribution
8+
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
9+
*
10+
* This Source Code may also be made available under the following Secondary
11+
* Licenses when the conditions for such availability set forth in the
12+
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
13+
* version 2 with the GNU Classpath Exception [1] and GNU General Public
14+
* License, version 2 with the OpenJDK Assembly Exception [2].
15+
*
16+
* [1] https://www.gnu.org/software/classpath/license.html
17+
* [2] http://openjdk.java.net/legal/assembly-exception.html
18+
*
19+
* 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
20+
*******************************************************************************/
21+
22+
#ifndef OMR_VIRTUALMACHINESTATE_INCL
23+
#define OMR_VIRTUALMACHINESTATE_INCL
24+
25+
26+
namespace TR { class IlBuilder; }
27+
namespace TR { class VirtualMachineState; }
28+
class TR_Memory;
29+
30+
template <class T> class List;
31+
template <class T> class ListAppender;
32+
33+
namespace OMR
34+
{
35+
36+
/**
37+
* @brief Interface for expressing virtual machine state variables to JitBuilder
38+
*
39+
* VirtualMachineState is an interface that language compilers will implement
40+
* to define all the aspects of the virtual machine state that the JIT compiler will
41+
* simulate (operand stacks, virtual registers like "pc", "sp", etc.). The interface
42+
* has four functions: 1) Commit() to cause the simulated state to be written to the
43+
* actual virtual machine state, 2) Reload() to set the simulated machine state based
44+
* on the current virtual machine state, 3) MakeCopy() to make an identical copy of
45+
* the curent virtual machine state object, and 4) MergeInto() to perform the actions
46+
* needed for the current state to be merged with a second virtual machine state.
47+
*
48+
* ##Usage
49+
*
50+
* Commit() is typically called when transitioning from compiled code to the interpreter.
51+
*
52+
* Reload() is typically called on the transition back from the interpreter to compiled
53+
* code.
54+
*
55+
* MakeCopy() is typically called when control flow edges are created: the current vm state
56+
* must also become the initial vm state at the target of the control flow edge and be
57+
* able to evolve independently from the current vm state.
58+
*
59+
* MergeInto() is typically called when one compiled code path needs to merge into a second
60+
* compiled code path (think the bottom of an if-then-else control flow diamond). At the
61+
* merge point, the locations of all aspects of the simulated machine state must be
62+
* identical so that the code below the merge point will compute correct results.
63+
* MergeInto() typically causes the current simulated machine state to be written to the
64+
* locations that were used by an existing simulated machine state. The "other" object
65+
* passed to MergeInto() must have the exact same shape (number of components and each
66+
* component must also match in its type).
67+
*
68+
* Language compilers should extend this base class, add instance variables for all
69+
* necessary virtual machine state variables (using classes like VirtualMachineRegister
70+
* and VirtualMachineOperandStack) and then implement Commit(), Reload(), MakeCopy(),
71+
* and MergeInto() to call Commit(), Reload(), MakeCopy(), and MergeInto(), respectively, on
72+
* each individual instance variable. It feels like boilerplate, but this approach makes
73+
* it easy for the compiler to reference individual virtual machine state variables and
74+
* at the same time permits complete flexibility in how the VM-wide Commit(), Reload(),
75+
* MakeCopy(), and MergeInto() operations can be implemented.
76+
*/
77+
78+
class VirtualMachineState
79+
{
80+
public:
81+
82+
/**
83+
* @brief Cause all simulated aspects of the virtual machine state to become real.
84+
* @param b builder object where the operations will be added to change the virtual machine state.
85+
*
86+
* The builder object b is assumed to be along a control flow path transitioning
87+
* from compiled code to the interpreter. Base implementation does nothing.
88+
*/
89+
virtual void Commit(TR::IlBuilder *b) { }
90+
91+
/**
92+
* @brief Load the current virtual machine state into the simulated variables used by compiled code.
93+
* @param b builder object where the operations will be added to reload the virtual machine state.
94+
*
95+
* The builder object b is assumed to be along a control flow path transitioning
96+
* from the interpreter to compiled code. Base implementation does nothing.
97+
*/
98+
virtual void Reload(TR::IlBuilder *b) { }
99+
100+
/**
101+
* @brief create an identical copy of the current object.
102+
* @returns the copy of the current object
103+
*
104+
* Typically used when propagating the current state along a flow edge to another builder to
105+
* capture the input state for that other builder.
106+
* Default implementation simply returns the current object.
107+
*/
108+
virtual TR::VirtualMachineState *MakeCopy();
109+
110+
/**
111+
* @brief cause the current state variables to match those used by another vm state
112+
* @param other current state for the builder object control is merging into
113+
* @param b builder object where the operations will be added to merge this state into the other
114+
*
115+
* The builder object is assumed to be along the control flow edge from one builder object S to
116+
* another builder object T. "this" vm state is assumed to be the vm state for S. "other" is
117+
* assumed to be the vm state for T. Control from S should be to "b", and "b" should eventually
118+
* transfer to T. Base implementation does nothing.
119+
*/
120+
virtual void MergeInto(TR::VirtualMachineState *other, TR::IlBuilder *b) { }
121+
122+
};
123+
124+
}
125+
126+
#endif // !defined(OMR_VIRTUALMACHINESTATE_INCL)
+8-96
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2016 IBM Corp. and others
2+
* Copyright (c) 2016, 2018 IBM Corp. and others
33
*
44
* This program and the accompanying materials are made available under
55
* the terms of the Eclipse Public License 2.0 which accompanies this
@@ -19,107 +19,19 @@
1919
* 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
2020
*******************************************************************************/
2121

22-
#ifndef OMR_VIRTUALMACHINESTATE_INCL
23-
#define OMR_VIRTUALMACHINESTATE_INCL
22+
#ifndef TR_VIRTUALMACHINESTATE_INCL
23+
#define TR_VIRTUALMACHINESTATE_INCL
2424

2525

26-
namespace TR { class IlBuilder; }
27-
class TR_Memory;
26+
#include "ilgen/OMRVirtualMachineState.hpp"
2827

29-
template <class T> class List;
30-
template <class T> class ListAppender;
31-
32-
namespace OMR
28+
namespace TR
3329
{
3430

35-
/**
36-
* @brief Interface for expressing virtual machine state variables to JitBuilder
37-
*
38-
* VirtualMachineState is an interface that language compilers will implement
39-
* to define all the aspects of the virtual machine state that the JIT compiler will
40-
* simulate (operand stacks, virtual registers like "pc", "sp", etc.). The interface
41-
* has four functions: 1) Commit() to cause the simulated state to be written to the
42-
* actual virtual machine state, 2) Reload() to set the simulated machine state based
43-
* on the current virtual machine state, 3) MakeCopy() to make an identical copy of
44-
* the curent virtual machine state object, and 4) MergeInto() to perform the actions
45-
* needed for the current state to be merged with a second virtual machine state.
46-
*
47-
* ##Usage
48-
*
49-
* Commit() is typically called when transitioning from compiled code to the interpreter.
50-
*
51-
* Reload() is typically called on the transition back from the interpreter to compiled
52-
* code.
53-
*
54-
* MakeCopy() is typically called when control flow edges are created: the current vm state
55-
* must also become the initial vm state at the target of the control flow edge and be
56-
* able to evolve independently from the current vm state.
57-
*
58-
* MergeInto() is typically called when one compiled code path needs to merge into a second
59-
* compiled code path (think the bottom of an if-then-else control flow diamond). At the
60-
* merge point, the locations of all aspects of the simulated machine state must be
61-
* identical so that the code below the merge point will compute correct results.
62-
* MergeInto() typically causes the current simulated machine state to be written to the
63-
* locations that were used by an existing simulated machine state. The "other" object
64-
* passed to MergeInto() must have the exact same shape (number of components and each
65-
* component must also match in its type).
66-
*
67-
* Language compilers should extend this base class, add instance variables for all
68-
* necessary virtual machine state variables (using classes like VirtualMachineRegister
69-
* and VirtualMachineOperandStack) and then implement Commit(), Reload(), MakeCopy(),
70-
* and MergeInto() to call Commit(), Reload(), MakeCopy(), and MergeInto(), respectively, on
71-
* each individual instance variable. It feels like boilerplate, but this approach makes
72-
* it easy for the compiler to reference individual virtual machine state variables and
73-
* at the same time permits complete flexibility in how the VM-wide Commit(), Reload(),
74-
* MakeCopy(), and MergeInto() operations can be implemented.
75-
*/
76-
77-
class VirtualMachineState
31+
class VirtualMachineState : public OMR::VirtualMachineState
7832
{
79-
public:
80-
81-
/**
82-
* @brief Cause all simulated aspects of the virtual machine state to become real.
83-
* @param b builder object where the operations will be added to change the virtual machine state.
84-
*
85-
* The builder object b is assumed to be along a control flow path transitioning
86-
* from compiled code to the interpreter. Base implementation does nothing.
87-
*/
88-
virtual void Commit(TR::IlBuilder *b) { }
89-
90-
/**
91-
* @brief Load the current virtual machine state into the simulated variables used by compiled code.
92-
* @param b builder object where the operations will be added to reload the virtual machine state.
93-
*
94-
* The builder object b is assumed to be along a control flow path transitioning
95-
* from the interpreter to compiled code. Base implementation does nothing.
96-
*/
97-
virtual void Reload(TR::IlBuilder *b) { }
98-
99-
/**
100-
* @brief create an identical copy of the current object.
101-
* @returns the copy of the current object
102-
*
103-
* Typically used when propagating the current state along a flow edge to another builder to
104-
* capture the input state for that other builder.
105-
* Default implementation simply returns the current object.
106-
*/
107-
virtual VirtualMachineState *MakeCopy() { return this; }
108-
109-
/**
110-
* @brief cause the current state variables to match those used by another vm state
111-
* @param other current state for the builder object control is merging into
112-
* @param b builder object where the operations will be added to merge this state into the other
113-
*
114-
* The builder object is assumed to be along the control flow edge from one builder object S to
115-
* another builder object T. "this" vm state is assumed to be the vm state for S. "other" is
116-
* assumed to be the vm state for T. Control from S should be to "b", and "b" should eventually
117-
* transfer to T. Base implementation does nothing.
118-
*/
119-
virtual void MergeInto(OMR::VirtualMachineState *other, TR::IlBuilder *b) { }
120-
12133
};
12234

123-
}
35+
} // namespace TR
12436

125-
#endif // !defined(OMR_VIRTUALMACHINESTATE_INCL)
37+
#endif // !defined(TR_VIRTUALMACHINESTATE_INCL)

‎jitbuilder/build/files/common.mk

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ JIT_PRODUCT_BACKEND_SOURCES+=\
229229
$(JIT_OMR_DIRTY_DIR)/ilgen/OMRMethodBuilder.cpp \
230230
$(JIT_OMR_DIRTY_DIR)/ilgen/OMRThunkBuilder.cpp \
231231
$(JIT_OMR_DIRTY_DIR)/ilgen/OMRTypeDictionary.cpp \
232+
$(JIT_OMR_DIRTY_DIR)/ilgen/OMRVirtualMachineState.cpp \
232233
$(JIT_OMR_DIRTY_DIR)/ilgen/VirtualMachineOperandArray.cpp \
233234
$(JIT_OMR_DIRTY_DIR)/ilgen/VirtualMachineOperandStack.cpp \
234235
$(JIT_OMR_DIRTY_DIR)/runtime/Alignment.cpp \

‎jitbuilder/build/rules/common.mk

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ $(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRTypeDictionary.hpp: $(FIXED_SRC
138138
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/TypeDictionary.hpp: $(FIXED_SRCBASE)/$(JIT_OMR_DIRTY_DIR)/ilgen/TypeDictionary.hpp $(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen
139139
cp $< $@ || cp $< $@
140140

141+
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRVirtualMachineState.hpp: $(FIXED_SRCBASE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRVirtualMachineState.hpp $(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen
142+
cp $< $@ || cp $< $@
143+
141144
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/VirtualMachineState.hpp: $(FIXED_SRCBASE)/$(JIT_OMR_DIRTY_DIR)/ilgen/VirtualMachineState.hpp $(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen
142145
cp $< $@ || cp $< $@
143146

@@ -187,6 +190,7 @@ JITBUILDER_FILES=$(RELEASE_DIR)/Makefile \
187190
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/BytecodeBuilder.hpp \
188191
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRTypeDictionary.hpp \
189192
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/TypeDictionary.hpp \
193+
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/OMRVirtualMachineState.hpp \
190194
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/VirtualMachineState.hpp \
191195
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/VirtualMachineRegister.hpp \
192196
$(RELEASE_INCLUDE)/$(JIT_OMR_DIRTY_DIR)/ilgen/VirtualMachineRegisterInStruct.hpp \

0 commit comments

Comments
 (0)
Please sign in to comment.