author | Claus Gittinger <cg@exept.de> |
Thu, 24 Nov 2011 12:54:24 +0100 | |
changeset 2290 | cd61fd0b66ac |
parent 2265 | c3b1b1c03533 |
child 2353 | fa7400d022a0 |
permissions | -rw-r--r-- |
749 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
3 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
4 |
SWING Research Group, Czech Technical University in Prague |
|
5 |
||
6 |
Parts of the code written by Claus Gittinger are under following |
|
7 |
license: |
|
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 |
||
16 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed: |
|
17 |
||
18 |
Permission is hereby granted, free of charge, to any person |
|
19 |
obtaining a copy of this software and associated documentation |
|
20 |
files (the 'Software'), to deal in the Software without |
|
21 |
restriction, including without limitation the rights to use, |
|
22 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
23 |
copies of the Software, and to permit persons to whom the |
|
24 |
Software is furnished to do so, subject to the following |
|
25 |
conditions: |
|
26 |
||
27 |
The above copyright notice and this permission notice shall be |
|
28 |
included in all copies or substantial portions of the Software. |
|
29 |
||
30 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
31 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
32 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
33 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
34 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
35 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
36 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
37 |
OTHER DEALINGS IN THE SOFTWARE. |
|
38 |
||
39 |
[1] Code written at SWING Research Group contain a signature |
|
40 |
of one of the above copright owners. |
|
41 |
" |
|
42 |
"{ Package: 'stx:libjava' }" |
|
43 |
||
44 |
Object subclass:#JavaNativeMemory |
|
45 |
instanceVariableNames:'addresses chunks' |
|
46 |
classVariableNames:'' |
|
47 |
poolDictionaries:'' |
|
48 |
category:'Languages-Java-Support' |
|
49 |
! |
|
50 |
||
51 |
!JavaNativeMemory class methodsFor:'documentation'! |
|
52 |
||
53 |
copyright |
|
54 |
" |
|
55 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
56 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
57 |
SWING Research Group, Czech Technical University in Prague |
|
58 |
||
59 |
Parts of the code written by Claus Gittinger are under following |
|
60 |
license: |
|
61 |
||
62 |
This software is furnished under a license and may be used |
|
63 |
only in accordance with the terms of that license and with the |
|
64 |
inclusion of the above copyright notice. This software may not |
|
65 |
be provided or otherwise made available to, or used by, any |
|
66 |
other person. No title to or ownership of the software is |
|
67 |
hereby transferred. |
|
68 |
||
69 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed: |
|
70 |
||
71 |
Permission is hereby granted, free of charge, to any person |
|
72 |
obtaining a copy of this software and associated documentation |
|
73 |
files (the 'Software'), to deal in the Software without |
|
74 |
restriction, including without limitation the rights to use, |
|
75 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
76 |
copies of the Software, and to permit persons to whom the |
|
77 |
Software is furnished to do so, subject to the following |
|
78 |
conditions: |
|
79 |
||
80 |
The above copyright notice and this permission notice shall be |
|
81 |
included in all copies or substantial portions of the Software. |
|
82 |
||
83 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
84 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
85 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
86 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
87 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
88 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
89 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
90 |
OTHER DEALINGS IN THE SOFTWARE. |
|
91 |
||
92 |
[1] Code written at SWING Research Group contain a signature |
|
93 |
of one of the above copright owners. |
|
94 |
||
95 |
" |
|
96 |
! ! |
|
97 |
||
98 |
!JavaNativeMemory class methodsFor:'instance creation'! |
|
99 |
||
100 |
new |
|
101 |
"return an initialized instance" |
|
102 |
||
103 |
^ self basicNew initialize. |
|
104 |
! ! |
|
105 |
||
106 |
!JavaNativeMemory methodsFor:'accessing'! |
|
107 |
||
108 |
byteAt:address |
|
109 |
|i chunk offset| |
|
110 |
||
111 |
addresses size == 0 ifTrue:[ |
|
112 |
self errorAccessingUnallocatedMemory:address |
|
113 |
]. |
|
114 |
i := 1. |
|
115 |
[ |
|
116 |
i <= (addresses size - 1) and:[ (addresses at:i + 1) <= address ] |
|
117 |
] whileTrue:[ i := i + 1 ]. |
|
118 |
offset := address - (addresses at:i). |
|
119 |
chunk := chunks at:i. |
|
120 |
(offset > chunk size) ifTrue:[ |
|
121 |
self errorAccessingUnallocatedMemory:address |
|
122 |
]. |
|
123 |
^chunk at: offset + 1 |
|
124 |
||
125 |
"Created: / 09-12-2010 / 17:32:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
126 |
! |
|
127 |
||
128 |
longAt:address put:value |
|
129 |
|i chunk offset| |
|
130 |
||
131 |
addresses size == 0 ifTrue:[ |
|
132 |
self errorAccessingUnallocatedMemory:address |
|
133 |
]. |
|
134 |
i := 1. |
|
135 |
[ |
|
136 |
i <= (addresses size - 1) and:[ (addresses at:i + 1) <= address ] |
|
137 |
] whileTrue:[ i := i + 1 ]. |
|
138 |
offset := address - (addresses at:i). |
|
139 |
chunk := chunks at:i. |
|
140 |
(offset > chunk size) ifTrue:[ |
|
141 |
self errorAccessingUnallocatedMemory:address |
|
142 |
]. |
|
143 |
chunk longLongAt: offset + 1 put: value |
|
144 |
||
145 |
"Created: / 09-12-2010 / 17:32:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
146 |
! ! |
|
147 |
||
148 |
!JavaNativeMemory methodsFor:'allocation/deallocation'! |
|
149 |
||
150 |
free: address |
|
151 |
||
152 |
"Frees the memory" |
|
153 |
||
154 |
| index | |
|
155 |
address = 0 ifTrue:[^self]. |
|
156 |
||
157 |
index := addresses |
|
158 |
indexOf: address |
|
159 |
ifAbsent:[self error:'Never allocated']. |
|
160 |
||
161 |
(chunks at: index) |
|
162 |
ifNil:[self error: 'Freed twice']. |
|
163 |
||
164 |
chunks at: index put: nil. |
|
165 |
||
166 |
"Created: / 07-12-2010 / 23:33:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
167 |
! |
|
168 |
||
169 |
malloc: size |
|
170 |
||
171 |
"Allocate new chunk of memory, size bytes long" |
|
172 |
||
173 |
| address | |
|
174 |
self assert: addresses size == chunks size. |
|
175 |
addresses size > 0 |
|
176 |
ifTrue: [address := addresses last + chunks last size ] |
|
177 |
ifFalse:[address := 0]. |
|
178 |
address := address + (Random nextIntegerBetween: 128 and: 256). |
|
179 |
||
180 |
addresses add: address. |
|
181 |
chunks add: (ByteArray new: size). |
|
182 |
||
183 |
^address |
|
184 |
||
185 |
"Created: / 07-12-2010 / 23:25:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
186 |
! ! |
|
187 |
||
188 |
!JavaNativeMemory methodsFor:'error reporting'! |
|
189 |
||
190 |
errorAccessingUnallocatedMemory:arg |
|
191 |
self shouldImplement |
|
192 |
||
193 |
"Created: / 07-12-2010 / 23:40:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
194 |
! ! |
|
195 |
||
196 |
!JavaNativeMemory methodsFor:'initialization'! |
|
197 |
||
198 |
initialize |
|
199 |
"Invoked when a new instance is created." |
|
200 |
||
201 |
addresses := OrderedCollection new. |
|
202 |
chunks := OrderedCollection new. |
|
203 |
||
204 |
"/ super initialize. -- commented since inherited method does nothing |
|
205 |
||
206 |
"Modified: / 07-12-2010 / 23:09:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
207 |
! ! |
|
208 |
||
209 |
!JavaNativeMemory class methodsFor:'documentation'! |
|
210 |
||
2265
c3b1b1c03533
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
211 |
version |
c3b1b1c03533
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
212 |
^ '$Header: /cvs/stx/stx/libjava/JavaNativeMemory.st,v 1.3 2011-11-24 11:53:30 cg Exp $' |
c3b1b1c03533
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
213 |
! |
c3b1b1c03533
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
214 |
|
2246 | 215 |
version_CVS |
2265
c3b1b1c03533
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2246
diff
changeset
|
216 |
^ '$Header: /cvs/stx/stx/libjava/JavaNativeMemory.st,v 1.3 2011-11-24 11:53:30 cg Exp $' |
2246 | 217 |
! |
218 |
||
749 | 219 |
version_SVN |
2246 | 220 |
^ '§Id: JavaNativeMemory.st,v 1.1 2011/08/18 19:06:53 vrany Exp §' |
2152 | 221 |
! ! |