CACAO
CodeMemory.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/CodeMemory.hpp - CodeMemory
2 
3  Copyright (C) 2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 #ifndef _JIT_COMPILER2_CODEMEMORY
26 #define _JIT_COMPILER2_CODEMEMORY
27 
30 #include "vm/types.hpp"
31 
35 #include <cassert>
36 
37 MM_MAKE_NAME(CodeMemory)
38 
39 namespace cacao {
40 namespace jit {
41 namespace compiler2 {
42 
43 // forward declarations
44 class MachineInstruction;
45 
46 /**
47  * CodeMemory
48  */
49 class CodeMemory : public memory::ManagerMixin<CodeMemory> {
50 public:
51  typedef std::pair<const MachineInstruction*,CodeFragment> ResolvePointTy;
52 private:
54 
55  LinkListTy linklist; ///< instructions that require linking
56 
57  CodeSegment cseg; ///< code segment
58  DataSegment dseg; ///< data segment
59 
60 public:
61  /// constructor
62  CodeMemory() : cseg(this), dseg(this) {}
63 
64  /// get CodeSegment
65  const CodeSegment& get_CodeSegment() const { return cseg; }
66  /// get CodeSegment
67  CodeSegment& get_CodeSegment() { return cseg; }
68  /// get DataSegment
69  const DataSegment& get_DataSegment() const { return dseg; }
70  /// get DataSegment
71  DataSegment& get_DataSegment() { return dseg; }
72 
73  s4 get_offset(CodeSegment::IdxTy to, CodeSegment::IdxTy from) const;
74  s4 get_offset(CodeSegment::IdxTy to, CodeFragment &CF) const {
75  return get_offset(to, CF.get_end());
76  }
77  s4 get_offset(CodeSegment::IdxTy to) const {
78  return get_offset(to, cseg.get_following_index());
79  }
80  /**
81  * @deprecated this should be moved to FixedCodeMemory or so
82  */
83  s4 get_offset(DataSegment::IdxTy to, CodeSegment::IdxTy from) const;
84  s4 get_offset(DataSegment::IdxTy to, CodeFragment &CF) const {
85  return get_offset(to, CF.get_end());
86  }
87  /// Add a MachineInstruction that require linking
88  void require_linking(const MachineInstruction*, CodeFragment CF);
89 
90  /**
91  * Link instructions.
92  *
93  * @deprecated this should be moved to FixedCodeMemory or so
94  */
95  void link();
96 
97  /**
98  * get a code fragment
99  */
100  CodeFragment get_CodeFragment(std::size_t size);
101 
102  /**
103  * get an aligned code fragment
104  *
105  * @return A CodeFragment aligend to Target::alignment.
106  */
107  CodeFragment get_aligned_CodeFragment(std::size_t size);
108 
109 };
110 
111 
112 } // end namespace compiler2
113 } // end namespace jit
114 } // end namespace cacao
115 
116 #endif /* _JIT_COMPILER2_CODEMEMORY */
117 
118 
119 /*
120  * These are local overrides for various environment variables in Emacs.
121  * Please do not remove this and leave it at the end of the file, where
122  * Emacs will automagically detect them.
123  * ---------------------------------------------------------------------
124  * Local variables:
125  * mode: c++
126  * indent-tabs-mode: t
127  * c-basic-offset: 4
128  * tab-width: 4
129  * End:
130  * vim:noexpandtab:sw=4:ts=4:
131  */
alloc::list< ResolvePointTy >::type LinkListTy
Definition: CodeMemory.hpp:53
argument_type from
s4 get_offset(CodeSegment::IdxTy to, CodeFragment &CF) const
Definition: CodeMemory.hpp:74
Custom new/delete handler mixin.
Definition: Manager.hpp:43
#define MM_MAKE_NAME(x)
Definition: memstats.hpp:127
s4 get_offset(DataSegment::IdxTy to, CodeFragment &CF) const
Definition: CodeMemory.hpp:84
JNIEnv jthread jobject jclass jlong size
Definition: jvmti.h:387
std::pair< const MachineInstruction *, CodeFragment > ResolvePointTy
Definition: CodeMemory.hpp:51
const CodeSegment & get_CodeSegment() const
get CodeSegment
Definition: CodeMemory.hpp:65
std::list< T, Allocator< T > > type
Definition: list.hpp:38
void link(basicblock *v, basicblock *w)
Definition: dominator.cpp:178
IdxTy get_end() const
Get the index of the first element after the reference.
Definition: Segment.hpp:356
s4 get_offset(CodeSegment::IdxTy to) const
Definition: CodeMemory.hpp:77
int32_t s4
Definition: types.hpp:45
CodeSegment & get_CodeSegment()
get CodeSegment
Definition: CodeMemory.hpp:67
CodeSegment cseg
code segment
Definition: CodeMemory.hpp:57
Proxy to encode explicit and implicit successors.
DataSegment & get_DataSegment()
get DataSegment
Definition: CodeMemory.hpp:71
LinkListTy linklist
instructions that require linking
Definition: CodeMemory.hpp:55
Segment reference.
Definition: Segment.hpp:44
DataSegment dseg
data segment
Definition: CodeMemory.hpp:58
const DataSegment & get_DataSegment() const
get DataSegment
Definition: CodeMemory.hpp:69