|
| 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) |
0 commit comments