CACAO
CodeMemory.cpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/CodeMemory.cpp - 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 
27 #include "mm/dumpmemory.hpp"
28 
29 #include "toolbox/logging.hpp"
30 #include "Target.hpp"
31 
33 #include <functional>
34 
35 #define DEBUG_NAME "compiler2/CodeMemory"
36 
37 #define MCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
38 
39 namespace cacao {
40 namespace jit {
41 namespace compiler2 {
42 
43 s4 CodeMemory::get_offset(CodeSegment::IdxTy to, CodeSegment::IdxTy from) const {
44  // Note that from/to is swapped because CodeSegment is written upside down!
45  return s4(from.idx) - s4(to.idx);
46 }
47 
48 s4 CodeMemory::get_offset(DataSegment::IdxTy to, CodeSegment::IdxTy from) const {
49  // Note that from is swapped because CodeSegment is written upside down!
50  return -(
51  s4(dseg.size()) - s4(from.idx)
52  +
53  s4(cseg.size()) - 1 - s4(to.idx));
54 }
55 
57  LOG2("LinkMeLater: " << MI << nl);
58  linklist.push_back(std::make_pair(MI,CF));
59 }
60 
61 namespace {
62 
63 /// @Cpp11 use std::function
64 struct LinkMeClass : std::unary_function<void, CodeMemory::ResolvePointTy&> {
65  void operator()(CodeMemory::ResolvePointTy &link_me) {
66  const MachineInstruction *MI = link_me.first;
67  CodeFragment &CF = link_me.second;
68  LOG2("LinkMe " << MI << nl);
69  MI->link(CF);
70  }
71 } LinkMe;
72 
73 } // end anonymous namespace
74 
76  std::for_each(linklist.begin(),linklist.end(),LinkMe);
77 }
78 
80  return cseg.get_Ref(size);
81 }
82 
84  std::size_t nops = (cseg.size() + size) % Target::alignment;
85  return cseg.get_Ref(size + nops);
86 }
87 
88 } // end namespace compiler2
89 } // end namespace jit
90 } // end namespace cacao
91 
92 
93 /*
94  * These are local overrides for various environment variables in Emacs.
95  * Please do not remove this and leave it at the end of the file, where
96  * Emacs will automagically detect them.
97  * ---------------------------------------------------------------------
98  * Local variables:
99  * mode: c++
100  * indent-tabs-mode: t
101  * c-basic-offset: 4
102  * tab-width: 4
103  * End:
104  * vim:noexpandtab:sw=4:ts=4:
105  */
CodeFragment get_CodeFragment(std::size_t size)
get a code fragment
Definition: CodeMemory.cpp:79
CodeFragment get_aligned_CodeFragment(std::size_t size)
get an aligned code fragment
Definition: CodeMemory.cpp:83
argument_type from
void link()
Link instructions.
Definition: CodeMemory.cpp:75
static const std::size_t alignment
Definition: X86_64.hpp:43
std::size_t size() const
get size
Definition: Segment.hpp:153
JNIEnv jthread jobject jclass jlong size
Definition: jvmti.h:387
std::pair< const MachineInstruction *, CodeFragment > ResolvePointTy
Definition: CodeMemory.hpp:51
void require_linking(const MachineInstruction *, CodeFragment CF)
Add a MachineInstruction that require linking.
Definition: CodeMemory.cpp:56
s4 get_offset(CodeSegment::IdxTy to, CodeSegment::IdxTy from) const
Definition: CodeMemory.cpp:43
#define LOG2(STMT)
Definition: logging.hpp:93
int32_t s4
Definition: types.hpp:45
virtual void link(CodeFragment &CF) const
link machine code
CodeSegment cseg
code segment
Definition: CodeMemory.hpp:57
Proxy to encode explicit and implicit successors.
LinkListTy linklist
instructions that require linking
Definition: CodeMemory.hpp:55
Segment reference.
Definition: Segment.hpp:44
Nl nl
Definition: OStream.cpp:56
Ref get_Ref(std::size_t t)
get a new reference to the segment
Definition: Segment.hpp:208
DataSegment dseg
data segment
Definition: CodeMemory.hpp:58