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