877
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
1152
|
3 |
|
1155
|
4 |
New code and modifications done at SWING Research Group [1]:
|
1152
|
5 |
|
877
|
6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
7 |
SWING Research Group, Czech Technical University in Prague
|
|
8 |
|
|
9 |
This software is furnished under a license and may be used
|
|
10 |
only in accordance with the terms of that license and with the
|
|
11 |
inclusion of the above copyright notice. This software may not
|
|
12 |
be provided or otherwise made available to, or used by, any
|
|
13 |
other person. No title to or ownership of the software is
|
|
14 |
hereby transferred.
|
|
15 |
|
1155
|
16 |
[1] Code written at SWING Research Group contains a signature
|
|
17 |
of one of the above copright owners. For exact set of such code,
|
|
18 |
see the differences between this version and version stx:libjava
|
1152
|
19 |
as of 1.9.2010
|
877
|
20 |
"
|
752
|
21 |
"{ Package: 'stx:libjava' }"
|
|
22 |
|
|
23 |
Object subclass:#JavaNativeMemory
|
1520
|
24 |
instanceVariableNames:'chunk free allocated'
|
752
|
25 |
classVariableNames:''
|
|
26 |
poolDictionaries:''
|
|
27 |
category:'Languages-Java-Support'
|
|
28 |
!
|
|
29 |
|
1520
|
30 |
Link subclass:#ListEntry
|
|
31 |
instanceVariableNames:'start stop'
|
|
32 |
classVariableNames:''
|
|
33 |
poolDictionaries:''
|
|
34 |
privateIn:JavaNativeMemory
|
|
35 |
!
|
|
36 |
|
877
|
37 |
!JavaNativeMemory class methodsFor:'documentation'!
|
|
38 |
|
|
39 |
copyright
|
|
40 |
"
|
|
41 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
1152
|
42 |
|
1155
|
43 |
New code and modifications done at SWING Research Group [1]:
|
1152
|
44 |
|
877
|
45 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
46 |
SWING Research Group, Czech Technical University in Prague
|
|
47 |
|
|
48 |
This software is furnished under a license and may be used
|
|
49 |
only in accordance with the terms of that license and with the
|
|
50 |
inclusion of the above copyright notice. This software may not
|
|
51 |
be provided or otherwise made available to, or used by, any
|
|
52 |
other person. No title to or ownership of the software is
|
|
53 |
hereby transferred.
|
|
54 |
|
1155
|
55 |
[1] Code written at SWING Research Group contains a signature
|
|
56 |
of one of the above copright owners. For exact set of such code,
|
|
57 |
see the differences between this version and version stx:libjava
|
1152
|
58 |
as of 1.9.2010
|
877
|
59 |
|
|
60 |
"
|
|
61 |
! !
|
752
|
62 |
|
|
63 |
!JavaNativeMemory class methodsFor:'instance creation'!
|
|
64 |
|
|
65 |
new
|
|
66 |
"return an initialized instance"
|
|
67 |
|
|
68 |
^ self basicNew initialize.
|
|
69 |
! !
|
|
70 |
|
|
71 |
!JavaNativeMemory methodsFor:'accessing'!
|
|
72 |
|
|
73 |
byteAt:address
|
|
74 |
|
1520
|
75 |
^chunk at: address
|
752
|
76 |
|
|
77 |
"Created: / 09-12-2010 / 17:32:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
78 |
!
|
|
79 |
|
|
80 |
longAt:address put:value
|
1520
|
81 |
chunk longLongAt: address put: value
|
752
|
82 |
|
|
83 |
"Created: / 09-12-2010 / 17:32:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1520
|
84 |
!
|
|
85 |
|
|
86 |
memory
|
|
87 |
^chunk
|
|
88 |
|
|
89 |
"Created: / 09-07-2012 / 12:44:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
752
|
90 |
! !
|
|
91 |
|
|
92 |
!JavaNativeMemory methodsFor:'allocation/deallocation'!
|
|
93 |
|
|
94 |
free: address
|
|
95 |
|
|
96 |
"Frees the memory"
|
|
97 |
|
1520
|
98 |
| aentry aentryPrev |
|
752
|
99 |
|
1520
|
100 |
aentry := allocated.
|
|
101 |
aentryPrev := nil.
|
|
102 |
[ aentry notNil and:[aentry start ~~ address ] ] whileTrue:[
|
|
103 |
aentryPrev := aentry.
|
|
104 |
aentry := aentry next.
|
|
105 |
].
|
|
106 |
aentry isNil ifTrue:[
|
|
107 |
self errorFreeingUnallocatedMemory: 'Never allocated'.
|
|
108 |
^self.
|
|
109 |
].
|
752
|
110 |
|
1520
|
111 |
"/Remove from allocated list
|
|
112 |
aentryPrev notNil ifTrue:[
|
|
113 |
aentryPrev next: aentry next.
|
|
114 |
] ifFalse:[
|
|
115 |
allocated := aentry next.
|
|
116 |
].
|
752
|
117 |
|
1520
|
118 |
free := self insert: aentry into: free join: true.
|
|
119 |
|
|
120 |
"/Insert free entry
|
752
|
121 |
|
|
122 |
"Created: / 07-12-2010 / 23:33:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
123 |
!
|
|
124 |
|
|
125 |
malloc: size
|
|
126 |
|
|
127 |
"Allocate new chunk of memory, size bytes long"
|
|
128 |
|
1520
|
129 |
| fentry aentry |
|
|
130 |
fentry := free.
|
|
131 |
[ fentry notNil and:[fentry size < size] ] whileTrue:[
|
|
132 |
fentry := fentry next.
|
|
133 |
].
|
|
134 |
fentry isNil ifTrue:[
|
|
135 |
self errorOutOfMemory: 'Not enounh memory or too fragmented'.
|
|
136 |
^self.
|
|
137 |
].
|
752
|
138 |
|
1520
|
139 |
"/ create allocation entry
|
|
140 |
aentry := ListEntry new
|
|
141 |
start: fentry start;
|
|
142 |
stop: fentry start + size - 1.
|
|
143 |
|
|
144 |
"/Update free entry
|
|
145 |
fentry start: fentry start + size.
|
752
|
146 |
|
1520
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
allocated := self insert: aentry into: allocated join: false.
|
|
152 |
|
|
153 |
^aentry start.
|
752
|
154 |
|
|
155 |
"Created: / 07-12-2010 / 23:25:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
156 |
! !
|
|
157 |
|
|
158 |
!JavaNativeMemory methodsFor:'error reporting'!
|
|
159 |
|
|
160 |
errorAccessingUnallocatedMemory:arg
|
|
161 |
self shouldImplement
|
|
162 |
|
|
163 |
"Created: / 07-12-2010 / 23:40:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
1520
|
164 |
!
|
|
165 |
|
|
166 |
errorFreeingUnallocatedMemory:arg
|
|
167 |
self shouldImplement
|
|
168 |
|
|
169 |
"Created: / 09-07-2012 / 10:57:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
170 |
!
|
|
171 |
|
|
172 |
errorOutOfMemory: message
|
|
173 |
self shouldImplement
|
|
174 |
|
|
175 |
"Created: / 09-07-2012 / 10:52:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
752
|
176 |
! !
|
|
177 |
|
|
178 |
!JavaNativeMemory methodsFor:'initialization'!
|
|
179 |
|
|
180 |
initialize
|
|
181 |
"Invoked when a new instance is created."
|
|
182 |
|
1520
|
183 |
chunk:= ByteArray new: 1024 * 1024.
|
|
184 |
free := ListEntry new start: 1; stop: chunk size.
|
|
185 |
allocated := nil.
|
|
186 |
|
752
|
187 |
|
|
188 |
"/ super initialize. -- commented since inherited method does nothing
|
|
189 |
|
1520
|
190 |
"Modified: / 09-07-2012 / 11:54:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
191 |
! !
|
|
192 |
|
|
193 |
!JavaNativeMemory methodsFor:'private'!
|
|
194 |
|
|
195 |
insert: entry into: list join: join
|
|
196 |
"Inserts an entry into given list. Returns new
|
|
197 |
list. If join is true, possibly adjacent entries are joined"
|
|
198 |
|
|
199 |
| current prev |
|
|
200 |
|
|
201 |
list isNil ifTrue:[ ^ entry ].
|
|
202 |
current := list.
|
|
203 |
prev := nil.
|
|
204 |
[ current notNil and:[ current stop < entry start ] ] whileTrue:[
|
|
205 |
prev := current.
|
|
206 |
current := current next.
|
|
207 |
].
|
|
208 |
prev isNil ifTrue:[
|
|
209 |
entry next: current join: join.
|
|
210 |
^entry.
|
|
211 |
].
|
|
212 |
prev next: entry join: join.
|
|
213 |
entry next: current join: join.
|
|
214 |
^list
|
|
215 |
|
|
216 |
"Created: / 09-07-2012 / 11:29:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
217 |
! !
|
|
218 |
|
|
219 |
!JavaNativeMemory::ListEntry methodsFor:'accessing'!
|
|
220 |
|
|
221 |
next
|
|
222 |
^nextLink
|
|
223 |
|
|
224 |
"Created: / 09-07-2012 / 11:57:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
225 |
!
|
|
226 |
|
|
227 |
next: next
|
|
228 |
self next: next join: false.
|
|
229 |
|
|
230 |
"Created: / 09-07-2012 / 11:58:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
231 |
!
|
|
232 |
|
|
233 |
size
|
|
234 |
^stop
|
|
235 |
|
|
236 |
"Created: / 09-07-2012 / 10:49:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
237 |
!
|
|
238 |
|
|
239 |
start
|
|
240 |
^ start
|
|
241 |
|
|
242 |
"Created: / 09-07-2012 / 11:23:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
243 |
!
|
|
244 |
|
|
245 |
start:something
|
|
246 |
start := something.
|
|
247 |
!
|
|
248 |
|
|
249 |
stop
|
|
250 |
^ stop
|
|
251 |
|
|
252 |
"Created: / 09-07-2012 / 11:23:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
253 |
!
|
|
254 |
|
|
255 |
stop:something
|
|
256 |
stop := something.
|
|
257 |
! !
|
|
258 |
|
|
259 |
!JavaNativeMemory::ListEntry methodsFor:'printing & storing'!
|
|
260 |
|
|
261 |
printOn:aStream
|
|
262 |
"append a printed representation if the receiver to the argument, aStream"
|
|
263 |
|
|
264 |
super printOn:aStream.
|
|
265 |
aStream nextPutAll:'('.
|
|
266 |
start printOn:aStream.
|
|
267 |
aStream nextPutAll:'..'.
|
|
268 |
stop printOn:aStream.
|
|
269 |
aStream nextPutAll:')'.
|
|
270 |
|
|
271 |
"Modified: / 09-07-2012 / 11:54:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
272 |
! !
|
|
273 |
|
|
274 |
!JavaNativeMemory::ListEntry methodsFor:'utilities'!
|
|
275 |
|
|
276 |
next: next join: join
|
|
277 |
(join and:[next notNil]) ifTrue:[
|
|
278 |
stop + 1 == next start ifTrue:[
|
|
279 |
stop := next stop.
|
|
280 |
(nextLink notNil and:[stop + 1 == nextLink start]) ifTrue:[
|
|
281 |
stop := nextLink stop.
|
|
282 |
nextLink := nextLink next.
|
|
283 |
].
|
|
284 |
^self
|
|
285 |
].
|
|
286 |
].
|
|
287 |
nextLink := next.
|
|
288 |
|
|
289 |
"Created: / 09-07-2012 / 11:49:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
752
|
290 |
! !
|
|
291 |
|
|
292 |
!JavaNativeMemory class methodsFor:'documentation'!
|
|
293 |
|
|
294 |
version_SVN
|
|
295 |
^ '$Id$'
|
|
296 |
! !
|