1 /*
   2  * Copyright (c) 2017, 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 
  24 package jdk.tools.jaotc;
  25 
  26 public final class StubInformation {
  27     private int stubOffset;         // the offset inside the code (text + stubOffset)
  28     private int stubSize;           // the stub size
  29     private int dispatchJumpOffset; // offset after main dispatch jump instruction
  30     private int resolveJumpOffset;  // offset after jump instruction to runtime call resolution function.
  31     private int resolveJumpStart;   // offset of jump instruction to VM runtime call resolution function.
  32     private int c2iJumpOffset;      // offset after jump instruction to c2i adapter for static calls.
  33     private int movOffset;          // offset after move instruction which loads from got cell:
  34                                     // - Method* for static call
  35                                     // - Klass* for virtual call
  36 
  37     private boolean isVirtual;  // virtual call stub
  38 
  39     // maybe add type of stub as well, right now we only have static stubs
  40 
  41     StubInformation(int stubOffset, boolean isVirtual) {
  42         this.stubOffset = stubOffset;
  43         this.isVirtual = isVirtual;
  44         this.stubSize = -1;
  45         this.movOffset = -1;
  46         this.c2iJumpOffset = -1;
  47         this.resolveJumpOffset = -1;
  48         this.resolveJumpStart = -1;
  49         this.dispatchJumpOffset = -1;
  50     }
  51 
  52     int getOffset() {
  53         return stubOffset;
  54     }
  55 
  56     boolean isVirtual() {
  57         return isVirtual;
  58     }
  59 
  60     public void setSize(int stubSize) {
  61         this.stubSize = stubSize;
  62     }
  63 
  64     int getSize() {
  65         return stubSize;
  66     }
  67 
  68     public void setMovOffset(int movOffset) {
  69         this.movOffset = movOffset + stubOffset;
  70     }
  71 
  72     int getMovOffset() {
  73         return movOffset;
  74     }
  75 
  76     public void setC2IJumpOffset(int c2iJumpOffset) {
  77         this.c2iJumpOffset = c2iJumpOffset + stubOffset;
  78     }
  79 
  80     int getC2IJumpOffset() {
  81         return c2iJumpOffset;
  82     }
  83 
  84     public void setResolveJumpOffset(int resolveJumpOffset) {
  85         this.resolveJumpOffset = resolveJumpOffset + stubOffset;
  86     }
  87 
  88     int getResolveJumpOffset() {
  89         return resolveJumpOffset;
  90     }
  91 
  92     public void setResolveJumpStart(int resolveJumpStart) {
  93         this.resolveJumpStart = resolveJumpStart + stubOffset;
  94     }
  95 
  96     int getResolveJumpStart() {
  97         return resolveJumpStart;
  98     }
  99 
 100     public void setDispatchJumpOffset(int dispatchJumpOffset) {
 101         this.dispatchJumpOffset = dispatchJumpOffset + stubOffset;
 102     }
 103 
 104     int getDispatchJumpOffset() {
 105         return dispatchJumpOffset;
 106     }
 107 
 108     void verify() {
 109         assert stubOffset > 0 : "incorrect stubOffset: " + stubOffset;
 110         assert stubSize > 0 : "incorrect stubSize: " + stubSize;
 111         assert movOffset > 0 : "incorrect movOffset: " + movOffset;
 112         assert dispatchJumpOffset > 0 : "incorrect dispatchJumpOffset: " + dispatchJumpOffset;
 113         assert resolveJumpStart > 0 : "incorrect resolveJumpStart: " + resolveJumpStart;
 114         assert resolveJumpOffset > 0 : "incorrect resolveJumpOffset: " + resolveJumpOffset;
 115         if (!isVirtual) {
 116             assert c2iJumpOffset > 0 : "incorrect c2iJumpOffset: " + c2iJumpOffset;
 117         }
 118     }
 119 }