001/*
002 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.word;
024
025import jdk.internal.jvmci.meta.*;
026
027import com.oracle.graal.nodes.memory.HeapAccess.BarrierType;
028
029/**
030 * Lowest-level memory access of native C memory. These methods access the raw memory without any
031 * null checks, read- or write barriers. Even when the VM uses compressed pointers, then readObject
032 * and writeObject methods access uncompressed pointers.
033 * <p>
034 * Do not use these methods to access Java objects, i.e., do not use
035 * {@code Word.fromObject(obj).readXxx()}. Instead, use {@link ObjectAccess} or
036 * {@link BarrieredAccess} to access Java objects.
037 */
038public interface Pointer extends Unsigned, PointerBase {
039
040    /**
041     * Unsafe conversion of this Pointer to a Java language object. No correctness checks or type
042     * checks are performed. The caller must ensure that the Pointer contains a valid Java object
043     * that can i.e., processed by the garbage collector.
044     *
045     * @return this Pointer cast to Object.
046     */
047    Object toObject();
048
049    /**
050     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
051     * bytes.
052     * <p>
053     * The offset is always treated as a {@link Signed} value. However, the static type is
054     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
055     * knows that the highest-order bit of the unsigned value is never used).
056     *
057     * @param offset the signed offset for the memory access
058     * @param locationIdentity the identity of the read
059     * @return the result of the memory access
060     */
061    byte readByte(WordBase offset, LocationIdentity locationIdentity);
062
063    /**
064     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
065     * bytes.
066     * <p>
067     * The offset is always treated as a {@link Signed} value. However, the static type is
068     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
069     * knows that the highest-order bit of the unsigned value is never used).
070     *
071     * @param offset the signed offset for the memory access
072     * @param locationIdentity the identity of the read
073     * @return the result of the memory access
074     */
075    char readChar(WordBase offset, LocationIdentity locationIdentity);
076
077    /**
078     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
079     * bytes.
080     * <p>
081     * The offset is always treated as a {@link Signed} value. However, the static type is
082     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
083     * knows that the highest-order bit of the unsigned value is never used).
084     *
085     * @param offset the signed offset for the memory access
086     * @param locationIdentity the identity of the read
087     * @return the result of the memory access
088     */
089    short readShort(WordBase offset, LocationIdentity locationIdentity);
090
091    /**
092     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
093     * bytes.
094     * <p>
095     * The offset is always treated as a {@link Signed} value. However, the static type is
096     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
097     * knows that the highest-order bit of the unsigned value is never used).
098     *
099     * @param offset the signed offset for the memory access
100     * @param locationIdentity the identity of the read
101     * @return the result of the memory access
102     */
103    int readInt(WordBase offset, LocationIdentity locationIdentity);
104
105    /**
106     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
107     * bytes.
108     * <p>
109     * The offset is always treated as a {@link Signed} value. However, the static type is
110     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
111     * knows that the highest-order bit of the unsigned value is never used).
112     *
113     * @param offset the signed offset for the memory access
114     * @param locationIdentity the identity of the read
115     * @return the result of the memory access
116     */
117    long readLong(WordBase offset, LocationIdentity locationIdentity);
118
119    /**
120     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
121     * bytes.
122     * <p>
123     * The offset is always treated as a {@link Signed} value. However, the static type is
124     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
125     * knows that the highest-order bit of the unsigned value is never used).
126     *
127     * @param offset the signed offset for the memory access
128     * @param locationIdentity the identity of the read
129     * @return the result of the memory access
130     */
131    float readFloat(WordBase offset, LocationIdentity locationIdentity);
132
133    /**
134     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
135     * bytes.
136     * <p>
137     * The offset is always treated as a {@link Signed} value. However, the static type is
138     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
139     * knows that the highest-order bit of the unsigned value is never used).
140     *
141     * @param offset the signed offset for the memory access
142     * @param locationIdentity the identity of the read
143     * @return the result of the memory access
144     */
145    double readDouble(WordBase offset, LocationIdentity locationIdentity);
146
147    /**
148     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
149     * bytes.
150     * <p>
151     * The offset is always treated as a {@link Signed} value. However, the static type is
152     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
153     * knows that the highest-order bit of the unsigned value is never used).
154     *
155     * @param offset the signed offset for the memory access
156     * @param locationIdentity the identity of the read
157     * @return the result of the memory access
158     */
159    Word readWord(WordBase offset, LocationIdentity locationIdentity);
160
161    /**
162     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
163     * bytes.
164     * <p>
165     * The offset is always treated as a {@link Signed} value. However, the static type is
166     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
167     * knows that the highest-order bit of the unsigned value is never used).
168     *
169     * @param offset the signed offset for the memory access
170     * @param locationIdentity the identity of the read
171     * @return the result of the memory access
172     */
173    Object readObject(WordBase offset, LocationIdentity locationIdentity);
174
175    /**
176     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
177     * bytes.
178     *
179     * @param offset the signed offset for the memory access
180     * @param locationIdentity the identity of the read
181     * @return the result of the memory access
182     */
183    byte readByte(int offset, LocationIdentity locationIdentity);
184
185    /**
186     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
187     * bytes.
188     *
189     * @param offset the signed offset for the memory access
190     * @param locationIdentity the identity of the read
191     * @return the result of the memory access
192     */
193    char readChar(int offset, LocationIdentity locationIdentity);
194
195    /**
196     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
197     * bytes.
198     *
199     * @param offset the signed offset for the memory access
200     * @param locationIdentity the identity of the read
201     * @return the result of the memory access
202     */
203    short readShort(int offset, LocationIdentity locationIdentity);
204
205    /**
206     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
207     * bytes.
208     *
209     * @param offset the signed offset for the memory access
210     * @param locationIdentity the identity of the read
211     * @return the result of the memory access
212     */
213    int readInt(int offset, LocationIdentity locationIdentity);
214
215    /**
216     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
217     * bytes.
218     *
219     * @param offset the signed offset for the memory access
220     * @param locationIdentity the identity of the read
221     * @return the result of the memory access
222     */
223    long readLong(int offset, LocationIdentity locationIdentity);
224
225    /**
226     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
227     * bytes.
228     *
229     * @param offset the signed offset for the memory access
230     * @param locationIdentity the identity of the read
231     * @return the result of the memory access
232     */
233    float readFloat(int offset, LocationIdentity locationIdentity);
234
235    /**
236     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
237     * bytes.
238     *
239     * @param offset the signed offset for the memory access
240     * @param locationIdentity the identity of the read
241     * @return the result of the memory access
242     */
243    double readDouble(int offset, LocationIdentity locationIdentity);
244
245    /**
246     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
247     * bytes.
248     *
249     * @param offset the signed offset for the memory access
250     * @param locationIdentity the identity of the read
251     * @return the result of the memory access
252     */
253    Word readWord(int offset, LocationIdentity locationIdentity);
254
255    /**
256     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
257     * bytes.
258     *
259     * @param offset the signed offset for the memory access
260     * @param locationIdentity the identity of the read
261     * @return the result of the memory access
262     */
263    Object readObject(int offset, LocationIdentity locationIdentity);
264
265    /**
266     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
267     * bytes.
268     * <p>
269     * The offset is always treated as a {@link Signed} value. However, the static type is
270     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
271     * knows that the highest-order bit of the unsigned value is never used).
272     *
273     * @param offset the signed offset for the memory access
274     * @param locationIdentity the identity of the write
275     * @param val the value to be written to memory
276     */
277    void writeByte(WordBase offset, byte val, LocationIdentity locationIdentity);
278
279    /**
280     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
281     * bytes.
282     * <p>
283     * The offset is always treated as a {@link Signed} value. However, the static type is
284     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
285     * knows that the highest-order bit of the unsigned value is never used).
286     *
287     * @param offset the signed offset for the memory access
288     * @param locationIdentity the identity of the write
289     * @param val the value to be written to memory
290     */
291    void writeChar(WordBase offset, char val, LocationIdentity locationIdentity);
292
293    /**
294     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
295     * bytes.
296     * <p>
297     * The offset is always treated as a {@link Signed} value. However, the static type is
298     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
299     * knows that the highest-order bit of the unsigned value is never used).
300     *
301     * @param offset the signed offset for the memory access
302     * @param locationIdentity the identity of the write
303     * @param val the value to be written to memory
304     */
305    void writeShort(WordBase offset, short val, LocationIdentity locationIdentity);
306
307    /**
308     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
309     * bytes.
310     * <p>
311     * The offset is always treated as a {@link Signed} value. However, the static type is
312     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
313     * knows that the highest-order bit of the unsigned value is never used).
314     *
315     * @param offset the signed offset for the memory access
316     * @param locationIdentity the identity of the write
317     * @param val the value to be written to memory
318     */
319    void writeInt(WordBase offset, int val, LocationIdentity locationIdentity);
320
321    /**
322     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
323     * bytes.
324     * <p>
325     * The offset is always treated as a {@link Signed} value. However, the static type is
326     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
327     * knows that the highest-order bit of the unsigned value is never used).
328     *
329     * @param offset the signed offset for the memory access
330     * @param locationIdentity the identity of the write
331     * @param val the value to be written to memory
332     */
333    void writeLong(WordBase offset, long val, LocationIdentity locationIdentity);
334
335    /**
336     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
337     * bytes.
338     * <p>
339     * The offset is always treated as a {@link Signed} value. However, the static type is
340     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
341     * knows that the highest-order bit of the unsigned value is never used).
342     *
343     * @param offset the signed offset for the memory access
344     * @param locationIdentity the identity of the write
345     * @param val the value to be written to memory
346     */
347    void writeFloat(WordBase offset, float val, LocationIdentity locationIdentity);
348
349    /**
350     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
351     * bytes.
352     * <p>
353     * The offset is always treated as a {@link Signed} value. However, the static type is
354     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
355     * knows that the highest-order bit of the unsigned value is never used).
356     *
357     * @param offset the signed offset for the memory access
358     * @param locationIdentity the identity of the write
359     * @param val the value to be written to memory
360     */
361    void writeDouble(WordBase offset, double val, LocationIdentity locationIdentity);
362
363    /**
364     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
365     * bytes.
366     * <p>
367     * The offset is always treated as a {@link Signed} value. However, the static type is
368     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
369     * knows that the highest-order bit of the unsigned value is never used).
370     *
371     * @param offset the signed offset for the memory access
372     * @param locationIdentity the identity of the write
373     * @param val the value to be written to memory
374     */
375    void writeWord(WordBase offset, WordBase val, LocationIdentity locationIdentity);
376
377    /**
378     * Initializes the memory at address {@code (this + offset)}. Both the base address and offset
379     * are in bytes. The memory must be uninitialized or zero prior to this operation.
380     * <p>
381     * The offset is always treated as a {@link Signed} value. However, the static type is
382     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
383     * knows that the highest-order bit of the unsigned value is never used).
384     *
385     * @param offset the signed offset for the memory access
386     * @param locationIdentity the identity of the write
387     * @param val the value to be written to memory
388     */
389    void initializeLong(WordBase offset, long val, LocationIdentity locationIdentity);
390
391    /**
392     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
393     * bytes.
394     * <p>
395     * The offset is always treated as a {@link Signed} value. However, the static type is
396     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
397     * knows that the highest-order bit of the unsigned value is never used).
398     *
399     * @param offset the signed offset for the memory access
400     * @param locationIdentity the identity of the write
401     * @param val the value to be written to memory
402     */
403    void writeObject(WordBase offset, Object val, LocationIdentity locationIdentity);
404
405    /**
406     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
407     * bytes.
408     *
409     * @param offset the signed offset for the memory access
410     * @param locationIdentity the identity of the write
411     * @param val the value to be written to memory
412     */
413    void writeByte(int offset, byte val, LocationIdentity locationIdentity);
414
415    /**
416     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
417     * bytes.
418     *
419     * @param offset the signed offset for the memory access
420     * @param locationIdentity the identity of the write
421     * @param val the value to be written to memory
422     */
423    void writeChar(int offset, char val, LocationIdentity locationIdentity);
424
425    /**
426     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
427     * bytes.
428     *
429     * @param offset the signed offset for the memory access
430     * @param locationIdentity the identity of the write
431     * @param val the value to be written to memory
432     */
433    void writeShort(int offset, short val, LocationIdentity locationIdentity);
434
435    /**
436     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
437     * bytes.
438     *
439     * @param offset the signed offset for the memory access
440     * @param locationIdentity the identity of the write
441     * @param val the value to be written to memory
442     */
443    void writeInt(int offset, int val, LocationIdentity locationIdentity);
444
445    /**
446     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
447     * bytes.
448     *
449     * @param offset the signed offset for the memory access
450     * @param locationIdentity the identity of the write
451     * @param val the value to be written to memory
452     */
453    void writeLong(int offset, long val, LocationIdentity locationIdentity);
454
455    /**
456     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
457     * bytes.
458     *
459     * @param offset the signed offset for the memory access
460     * @param locationIdentity the identity of the write
461     * @param val the value to be written to memory
462     */
463    void writeFloat(int offset, float val, LocationIdentity locationIdentity);
464
465    /**
466     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
467     * bytes.
468     *
469     * @param offset the signed offset for the memory access
470     * @param locationIdentity the identity of the write
471     * @param val the value to be written to memory
472     */
473    void writeDouble(int offset, double val, LocationIdentity locationIdentity);
474
475    /**
476     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
477     * bytes.
478     *
479     * @param offset the signed offset for the memory access
480     * @param locationIdentity the identity of the write
481     * @param val the value to be written to memory
482     */
483    void writeWord(int offset, WordBase val, LocationIdentity locationIdentity);
484
485    /**
486     * Initializes the memory at address {@code (this + offset)}. Both the base address and offset
487     * are in bytes. The memory must be uninitialized or zero prior to this operation.
488     *
489     * @param offset the signed offset for the memory access
490     * @param locationIdentity the identity of the write
491     * @param val the value to be written to memory
492     */
493    void initializeLong(int offset, long val, LocationIdentity locationIdentity);
494
495    /**
496     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
497     * bytes.
498     *
499     * @param offset the signed offset for the memory access
500     * @param locationIdentity the identity of the write
501     * @param val the value to be written to memory
502     */
503    void writeObject(int offset, Object val, LocationIdentity locationIdentity);
504
505    /**
506     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
507     * bytes.
508     * <p>
509     * The offset is always treated as a {@link Signed} value. However, the static type is
510     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
511     * knows that the highest-order bit of the unsigned value is never used).
512     *
513     * @param offset the signed offset for the memory access
514     * @return the result of the memory access
515     */
516    byte readByte(WordBase offset);
517
518    /**
519     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
520     * bytes.
521     * <p>
522     * The offset is always treated as a {@link Signed} value. However, the static type is
523     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
524     * knows that the highest-order bit of the unsigned value is never used).
525     *
526     * @param offset the signed offset for the memory access
527     * @return the result of the memory access
528     */
529    char readChar(WordBase offset);
530
531    /**
532     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
533     * bytes.
534     * <p>
535     * The offset is always treated as a {@link Signed} value. However, the static type is
536     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
537     * knows that the highest-order bit of the unsigned value is never used).
538     *
539     * @param offset the signed offset for the memory access
540     * @return the result of the memory access
541     */
542    short readShort(WordBase offset);
543
544    /**
545     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
546     * bytes.
547     * <p>
548     * The offset is always treated as a {@link Signed} value. However, the static type is
549     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
550     * knows that the highest-order bit of the unsigned value is never used).
551     *
552     * @param offset the signed offset for the memory access
553     * @return the result of the memory access
554     */
555    int readInt(WordBase offset);
556
557    /**
558     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
559     * bytes.
560     * <p>
561     * The offset is always treated as a {@link Signed} value. However, the static type is
562     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
563     * knows that the highest-order bit of the unsigned value is never used).
564     *
565     * @param offset the signed offset for the memory access
566     * @return the result of the memory access
567     */
568    long readLong(WordBase offset);
569
570    /**
571     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
572     * bytes.
573     * <p>
574     * The offset is always treated as a {@link Signed} value. However, the static type is
575     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
576     * knows that the highest-order bit of the unsigned value is never used).
577     *
578     * @param offset the signed offset for the memory access
579     * @return the result of the memory access
580     */
581    float readFloat(WordBase offset);
582
583    /**
584     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
585     * bytes.
586     * <p>
587     * The offset is always treated as a {@link Signed} value. However, the static type is
588     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
589     * knows that the highest-order bit of the unsigned value is never used).
590     *
591     * @param offset the signed offset for the memory access
592     * @return the result of the memory access
593     */
594    double readDouble(WordBase offset);
595
596    /**
597     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
598     * bytes.
599     * <p>
600     * The offset is always treated as a {@link Signed} value. However, the static type is
601     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
602     * knows that the highest-order bit of the unsigned value is never used).
603     *
604     * @param offset the signed offset for the memory access
605     * @return the result of the memory access
606     */
607    Word readWord(WordBase offset);
608
609    /**
610     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
611     * bytes.
612     * <p>
613     * The offset is always treated as a {@link Signed} value. However, the static type is
614     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
615     * knows that the highest-order bit of the unsigned value is never used).
616     *
617     * @param offset the signed offset for the memory access
618     * @return the result of the memory access
619     */
620    Object readObject(WordBase offset);
621
622    /**
623     * Reads the memory at address {@code (this + offset)}. This access will decompress the oop if
624     * the VM uses compressed oops, and it can be parameterized to allow read barriers (G1 referent
625     * field).
626     * <p>
627     * The offset is always treated as a {@link Signed} value. However, the static type is
628     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
629     * knows that the highest-order bit of the unsigned value is never used).
630     *
631     * @param offset the signed offset for the memory access
632     * @param barrierType the type of the read barrier to be added
633     * @return the result of the memory access
634     */
635    Object readObject(WordBase offset, BarrierType barrierType);
636
637    /**
638     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
639     * bytes.
640     *
641     * @param offset the signed offset for the memory access
642     * @return the result of the memory access
643     */
644    byte readByte(int offset);
645
646    /**
647     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
648     * bytes.
649     *
650     * @param offset the signed offset for the memory access
651     * @return the result of the memory access
652     */
653    char readChar(int offset);
654
655    /**
656     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
657     * bytes.
658     *
659     * @param offset the signed offset for the memory access
660     * @return the result of the memory access
661     */
662    short readShort(int offset);
663
664    /**
665     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
666     * bytes.
667     *
668     * @param offset the signed offset for the memory access
669     * @return the result of the memory access
670     */
671    int readInt(int offset);
672
673    /**
674     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
675     * bytes.
676     *
677     * @param offset the signed offset for the memory access
678     * @return the result of the memory access
679     */
680    long readLong(int offset);
681
682    /**
683     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
684     * bytes.
685     *
686     * @param offset the signed offset for the memory access
687     * @return the result of the memory access
688     */
689    float readFloat(int offset);
690
691    /**
692     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
693     * bytes.
694     *
695     * @param offset the signed offset for the memory access
696     * @return the result of the memory access
697     */
698    double readDouble(int offset);
699
700    /**
701     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
702     * bytes.
703     *
704     * @param offset the signed offset for the memory access
705     * @return the result of the memory access
706     */
707    Word readWord(int offset);
708
709    /**
710     * Reads the memory at address {@code (this + offset)}. Both the base address and offset are in
711     * bytes.
712     *
713     * @param offset the signed offset for the memory access
714     * @return the result of the memory access
715     */
716    Object readObject(int offset);
717
718    /**
719     * Reads the memory at address {@code (this + offset)}. This access will decompress the oop if
720     * the VM uses compressed oops, and it can be parameterized to allow read barriers (G1 referent
721     * field).
722     *
723     * @param offset the signed offset for the memory access
724     * @param barrierType the type of the read barrier to be added
725     * @return the result of the memory access
726     */
727    Object readObject(int offset, BarrierType barrierType);
728
729    /**
730     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
731     * bytes.
732     * <p>
733     * The offset is always treated as a {@link Signed} value. However, the static type is
734     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
735     * knows that the highest-order bit of the unsigned value is never used).
736     *
737     * @param offset the signed offset for the memory access
738     * @param val the value to be written to memory
739     */
740    void writeByte(WordBase offset, byte val);
741
742    /**
743     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
744     * bytes.
745     * <p>
746     * The offset is always treated as a {@link Signed} value. However, the static type is
747     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
748     * knows that the highest-order bit of the unsigned value is never used).
749     *
750     * @param offset the signed offset for the memory access
751     * @param val the value to be written to memory
752     */
753    void writeChar(WordBase offset, char val);
754
755    /**
756     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
757     * bytes.
758     * <p>
759     * The offset is always treated as a {@link Signed} value. However, the static type is
760     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
761     * knows that the highest-order bit of the unsigned value is never used).
762     *
763     * @param offset the signed offset for the memory access
764     * @param val the value to be written to memory
765     */
766    void writeShort(WordBase offset, short val);
767
768    /**
769     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
770     * bytes.
771     * <p>
772     * The offset is always treated as a {@link Signed} value. However, the static type is
773     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
774     * knows that the highest-order bit of the unsigned value is never used).
775     *
776     * @param offset the signed offset for the memory access
777     * @param val the value to be written to memory
778     */
779    void writeInt(WordBase offset, int val);
780
781    /**
782     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
783     * bytes.
784     * <p>
785     * The offset is always treated as a {@link Signed} value. However, the static type is
786     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
787     * knows that the highest-order bit of the unsigned value is never used).
788     *
789     * @param offset the signed offset for the memory access
790     * @param val the value to be written to memory
791     */
792    void writeLong(WordBase offset, long val);
793
794    /**
795     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
796     * bytes.
797     * <p>
798     * The offset is always treated as a {@link Signed} value. However, the static type is
799     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
800     * knows that the highest-order bit of the unsigned value is never used).
801     *
802     * @param offset the signed offset for the memory access
803     * @param val the value to be written to memory
804     */
805    void writeFloat(WordBase offset, float val);
806
807    /**
808     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
809     * bytes.
810     * <p>
811     * The offset is always treated as a {@link Signed} value. However, the static type is
812     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
813     * knows that the highest-order bit of the unsigned value is never used).
814     *
815     * @param offset the signed offset for the memory access
816     * @param val the value to be written to memory
817     */
818    void writeDouble(WordBase offset, double val);
819
820    /**
821     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
822     * bytes.
823     * <p>
824     * The offset is always treated as a {@link Signed} value. However, the static type is
825     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
826     * knows that the highest-order bit of the unsigned value is never used).
827     *
828     * @param offset the signed offset for the memory access
829     * @param val the value to be written to memory
830     */
831    void writeWord(WordBase offset, WordBase val);
832
833    /**
834     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
835     * bytes.
836     * <p>
837     * The offset is always treated as a {@link Signed} value. However, the static type is
838     * {@link WordBase} to avoid the frequent casts to of {@link Unsigned} values (where the caller
839     * knows that the highest-order bit of the unsigned value is never used).
840     *
841     * @param offset the signed offset for the memory access
842     * @param val the value to be written to memory
843     */
844    void writeObject(WordBase offset, Object val);
845
846    /**
847     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
848     * bytes.
849     *
850     * @param offset the signed offset for the memory access
851     * @param val the value to be written to memory
852     */
853    void writeByte(int offset, byte val);
854
855    /**
856     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
857     * bytes.
858     *
859     * @param offset the signed offset for the memory access
860     * @param val the value to be written to memory
861     */
862    void writeChar(int offset, char val);
863
864    /**
865     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
866     * bytes.
867     *
868     * @param offset the signed offset for the memory access
869     * @param val the value to be written to memory
870     */
871    void writeShort(int offset, short val);
872
873    /**
874     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
875     * bytes.
876     *
877     * @param offset the signed offset for the memory access
878     * @param val the value to be written to memory
879     */
880    void writeInt(int offset, int val);
881
882    /**
883     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
884     * bytes.
885     *
886     * @param offset the signed offset for the memory access
887     * @param val the value to be written to memory
888     */
889    void writeLong(int offset, long val);
890
891    /**
892     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
893     * bytes.
894     *
895     * @param offset the signed offset for the memory access
896     * @param val the value to be written to memory
897     */
898    void writeFloat(int offset, float val);
899
900    /**
901     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
902     * bytes.
903     *
904     * @param offset the signed offset for the memory access
905     * @param val the value to be written to memory
906     */
907    void writeDouble(int offset, double val);
908
909    /**
910     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
911     * bytes.
912     *
913     * @param offset the signed offset for the memory access
914     * @param val the value to be written to memory
915     */
916    void writeWord(int offset, WordBase val);
917
918    /**
919     * Writes the memory at address {@code (this + offset)}. Both the base address and offset are in
920     * bytes.
921     *
922     * @param offset the signed offset for the memory access
923     * @param val the value to be written to memory
924     */
925    void writeObject(int offset, Object val);
926
927    // Math functions that are defined in Unsigned, but known to preserve the
928    // pointer-characteristics.
929    // It is therefore safe that they return a static type of Pointer instead of Unsigned.
930
931    @Override
932    Pointer add(Unsigned val);
933
934    @Override
935    Pointer add(int val);
936
937    @Override
938    Pointer subtract(Unsigned val);
939
940    @Override
941    Pointer subtract(int val);
942
943    @Override
944    Pointer and(Unsigned val);
945
946    @Override
947    Pointer and(int val);
948
949    @Override
950    Pointer or(Unsigned val);
951
952    @Override
953    Pointer or(int val);
954}