Source Code Cross Referenced for PlatformAddress.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » platform » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.luni.platform 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package org.apache.harmony.luni.platform;
019:
020:        /**
021:         * The platform address class is an unsafe virtualization of an OS memory block.
022:         * 
023:         */
024:        public class PlatformAddress implements  ICommonDataTypes, Comparable {
025:
026:            /**
027:             * This final field defines the size of an address on this platform.
028:             */
029:            static final int SIZEOF = Platform.getMemorySystem()
030:                    .getPointerSize();
031:
032:            /**
033:             * NULL is the canonical address with address value zero.
034:             */
035:            public static final PlatformAddress NULL = new PlatformAddress(0, 0);
036:
037:            public static final IMemorySpy memorySpy = new RuntimeMemorySpy();
038:
039:            static final IMemorySystem osMemory = Platform.getMemorySystem();
040:
041:            static final long UNKNOWN = -1;
042:
043:            final long osaddr;
044:
045:            final long size;
046:
047:            PlatformAddress(long address, long size) {
048:                super ();
049:                osaddr = address;
050:                this .size = size;
051:            }
052:
053:            /**
054:             * Sending auto free to an address means that, when this subsystem has
055:             * allocated the memory, it will automatically be freed when this object is
056:             * collected by the garbage collector if the memory has not already been
057:             * freed explicitly.
058:             * 
059:             */
060:            public final void autoFree() {
061:                memorySpy.autoFree(this );
062:            }
063:
064:            public PlatformAddress duplicate() {
065:                return PlatformAddressFactory.on(osaddr, size);
066:            }
067:
068:            public PlatformAddress offsetBytes(int offset) {
069:                return PlatformAddressFactory
070:                        .on(osaddr + offset, size - offset);
071:            }
072:
073:            public PlatformAddress offsetBytes(long offset) {
074:                return PlatformAddressFactory
075:                        .on(osaddr + offset, size - offset);
076:            }
077:
078:            public final void moveTo(PlatformAddress dest, long numBytes) {
079:                osMemory.memmove(dest.osaddr, osaddr, numBytes);
080:            }
081:
082:            public final boolean equals(Object other) {
083:                return (other instanceof  PlatformAddress)
084:                        && (((PlatformAddress) other).osaddr == osaddr);
085:            }
086:
087:            public final int hashCode() {
088:                return (int) osaddr;
089:            }
090:
091:            public final boolean isNULL() {
092:                return this  == NULL;
093:            }
094:
095:            public void free() {
096:                // Memory spys can veto the basic free if they determine the memory was
097:                // not allocated.
098:                if (memorySpy.free(this )) {
099:                    osMemory.free(osaddr);
100:                }
101:            }
102:
103:            public final void setAddress(int offset, PlatformAddress address) {
104:                osMemory.setAddress(osaddr + offset, address.osaddr);
105:            }
106:
107:            public final PlatformAddress getAddress(int offset) {
108:                int addr = getInt(offset);
109:                return PlatformAddressFactory.on(addr);
110:            }
111:
112:            public final void setByte(int offset, byte value) {
113:                memorySpy.rangeCheck(this , offset, SIZEOF_JBYTE);
114:                osMemory.setByte(osaddr + offset, value);
115:            }
116:
117:            public final void setByteArray(int offset, byte[] bytes,
118:                    int bytesOffset, int length) {
119:                memorySpy.rangeCheck(this , offset, length * SIZEOF_JBYTE);
120:                osMemory.setByteArray(osaddr + offset, bytes, bytesOffset,
121:                        length);
122:            }
123:
124:            public final byte getByte(int offset) {
125:                memorySpy.rangeCheck(this , offset, SIZEOF_JBYTE);
126:                return osMemory.getByte(osaddr + offset);
127:            }
128:
129:            public final void getByteArray(int offset, byte[] bytes,
130:                    int bytesOffset, int length) {
131:                memorySpy.rangeCheck(this , offset, length * SIZEOF_JBYTE);
132:                osMemory.getByteArray(osaddr + offset, bytes, bytesOffset,
133:                        length);
134:            }
135:
136:            public final void setShort(int offset, short value, Endianness order) {
137:                memorySpy.rangeCheck(this , offset, SIZEOF_JSHORT);
138:                osMemory.setShort(osaddr + offset, value, order);
139:            }
140:
141:            public final void setShort(int offset, short value) {
142:                memorySpy.rangeCheck(this , offset, SIZEOF_JSHORT);
143:                osMemory.setShort(osaddr + offset, value);
144:            }
145:
146:            public final short getShort(int offset, Endianness order) {
147:                memorySpy.rangeCheck(this , offset, SIZEOF_JSHORT);
148:                return osMemory.getShort(osaddr + offset, order);
149:            }
150:
151:            public final short getShort(int offset) {
152:                memorySpy.rangeCheck(this , offset, SIZEOF_JSHORT);
153:                return osMemory.getShort(osaddr + offset);
154:            }
155:
156:            public final void setInt(int offset, int value, Endianness order) {
157:                memorySpy.rangeCheck(this , offset, SIZEOF_JINT);
158:                osMemory.setInt(osaddr + offset, value, order);
159:            }
160:
161:            public final void setInt(int offset, int value) {
162:                memorySpy.rangeCheck(this , offset, SIZEOF_JINT);
163:                osMemory.setInt(osaddr + offset, value);
164:            }
165:
166:            public final int getInt(int offset, Endianness order) {
167:                memorySpy.rangeCheck(this , offset, SIZEOF_JINT);
168:                return osMemory.getInt(osaddr + offset, order);
169:            }
170:
171:            public final int getInt(int offset) {
172:                memorySpy.rangeCheck(this , offset, SIZEOF_JINT);
173:                return osMemory.getInt(osaddr + offset);
174:            }
175:
176:            public final void setLong(int offset, long value, Endianness order) {
177:                memorySpy.rangeCheck(this , offset, SIZEOF_JLONG);
178:                osMemory.setLong(osaddr + offset, value, order);
179:            }
180:
181:            public final void setLong(int offset, long value) {
182:                memorySpy.rangeCheck(this , offset, SIZEOF_JLONG);
183:                osMemory.setLong(osaddr + offset, value);
184:            }
185:
186:            public final long getLong(int offset, Endianness order) {
187:                memorySpy.rangeCheck(this , offset, SIZEOF_JLONG);
188:                return osMemory.getLong(osaddr + offset, order);
189:            }
190:
191:            public final long getLong(int offset) {
192:                memorySpy.rangeCheck(this , offset, SIZEOF_JLONG);
193:                return osMemory.getLong(osaddr + offset);
194:            }
195:
196:            public final void setFloat(int offset, float value, Endianness order) {
197:                memorySpy.rangeCheck(this , offset, SIZEOF_JFLOAT);
198:                osMemory.setFloat(osaddr + offset, value, order);
199:            }
200:
201:            public final void setFloat(int offset, float value) {
202:                memorySpy.rangeCheck(this , offset, SIZEOF_JFLOAT);
203:                osMemory.setFloat(osaddr + offset, value);
204:            }
205:
206:            public final float getFloat(int offset, Endianness order) {
207:                memorySpy.rangeCheck(this , offset, SIZEOF_JFLOAT);
208:                return osMemory.getFloat(osaddr + offset, order);
209:            }
210:
211:            public final float getFloat(int offset) {
212:                memorySpy.rangeCheck(this , offset, SIZEOF_JFLOAT);
213:                return osMemory.getFloat(osaddr + offset);
214:            }
215:
216:            public final void setDouble(int offset, double value,
217:                    Endianness order) {
218:                memorySpy.rangeCheck(this , offset, SIZEOF_JDOUBLE);
219:                osMemory.setDouble(osaddr + offset, value, order);
220:            }
221:
222:            public final void setDouble(int offset, double value) {
223:                memorySpy.rangeCheck(this , offset, SIZEOF_JDOUBLE);
224:                osMemory.setDouble(osaddr + offset, value);
225:            }
226:
227:            public final double getDouble(int offset, Endianness order) {
228:                memorySpy.rangeCheck(this , offset, SIZEOF_JDOUBLE);
229:                return osMemory.getDouble(osaddr + offset, order);
230:            }
231:
232:            public final double getDouble(int offset) {
233:                memorySpy.rangeCheck(this , offset, SIZEOF_JDOUBLE);
234:                return osMemory.getDouble(osaddr + offset);
235:            }
236:
237:            public final long toLong() {
238:                return osaddr;
239:            }
240:
241:            public final String toString() {
242:                return "PlatformAddress[" + osaddr + "]"; //$NON-NLS-1$ //$NON-NLS-2$
243:            }
244:
245:            public final long getSize() {
246:                return size;
247:            }
248:
249:            public final int compareTo(Object other) {
250:                if (other == null) {
251:                    throw new NullPointerException(); // per spec.
252:                }
253:                if (other instanceof  PlatformAddress) {
254:                    long otherPA = ((PlatformAddress) other).osaddr;
255:                    if (osaddr == otherPA) {
256:                        return 0;
257:                    }
258:                    return osaddr < otherPA ? -1 : 1;
259:                }
260:
261:                throw new ClassCastException(); // per spec.
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.