< prev index next >

src/jdk.vm.ci/share/classes/jdk.vm.ci.code/src/jdk/vm/ci/code/CodeUtil.java

Print this page




   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 jdk.vm.ci.code;
  24 
  25 import java.util.*;
  26 
  27 import jdk.vm.ci.meta.*;






  28 
  29 /**
  30  * Miscellaneous collection of utility methods used by {@code jdk.vm.ci.code} and its clients.
  31  */
  32 public class CodeUtil {
  33 
  34     public static final String NEW_LINE = String.format("%n");
  35 
  36     public static final int K = 1024;
  37     public static final int M = 1024 * 1024;
  38 
  39     public static boolean isOdd(int n) {
  40         return (n & 1) == 1;
  41     }
  42 
  43     public static boolean isEven(int n) {
  44         return (n & 1) == 0;
  45     }
  46 
  47     /**


 306                     sb.append("  ").append(row);
 307                     if (i != rows.length - 1) {
 308                         sb.append(NEW_LINE);
 309                     }
 310                 }
 311             }
 312         }
 313         if (frame.caller() != null) {
 314             sb.append(NEW_LINE);
 315             append(sb, frame.caller());
 316         } else if (frame.getCaller() != null) {
 317             sb.append(NEW_LINE);
 318             append(sb, frame.getCaller());
 319         }
 320         return sb;
 321     }
 322 
 323     public interface RefMapFormatter {
 324 
 325         String formatStackSlot(int frameRefMapIndex);
 326 
 327         String formatRegister(int regRefMapIndex);
 328     }
 329 
 330     /**
 331      * Formats a location in a register reference map.
 332      */
 333     public static class DefaultRegFormatter implements RefMapFormatter {
 334 
 335         private final Register[] registers;
 336 
 337         public DefaultRegFormatter(Architecture arch) {
 338             registers = new Register[arch.getRegisterReferenceMapSize()];
 339             for (Register r : arch.getRegisters()) {
 340                 if (r.getReferenceMapIndex() >= 0) {
 341                     registers[r.getReferenceMapIndex()] = r;
 342                 }
 343             }
 344         }
 345 
 346         public String formatStackSlot(int frameRefMapIndex) {
 347             return null;
 348         }
 349 
 350         public String formatRegister(int regRefMapIndex) {
 351             int i = regRefMapIndex;
 352             int idx = 0;
 353             while (registers[i] == null) {
 354                 i--;
 355                 idx++;
 356             }
 357             if (idx == 0) {
 358                 return registers[i].toString();
 359             } else {
 360                 return String.format("%s+%d", registers[i].toString(), idx);
 361             }
 362         }
 363     }
 364 
 365     /**
 366      * Formats a location present in a register or frame reference map.
 367      */
 368     public static class DefaultRefMapFormatter extends DefaultRegFormatter {
 369 
 370         /**
 371          * The size of a stack slot.
 372          */
 373         public final int slotSize;
 374 
 375         /**
 376          * The register used as the frame pointer.
 377          */
 378         public final Register fp;
 379 
 380         /**
 381          * The offset (in bytes) from the slot pointed to by {@link #fp} to the slot corresponding
 382          * to bit 0 in the frame reference map.
 383          */
 384         public final int refMapToFPOffset;
 385 
 386         public DefaultRefMapFormatter(Architecture arch, int slotSize, Register fp, int refMapToFPOffset) {
 387             super(arch);
 388             this.slotSize = slotSize;
 389             this.fp = fp;
 390             this.refMapToFPOffset = refMapToFPOffset;
 391         }
 392 
 393         @Override
 394         public String formatStackSlot(int frameRefMapIndex) {
 395             int refMapOffset = frameRefMapIndex * slotSize;
 396             int fpOffset = refMapOffset + refMapToFPOffset;
 397             if (fpOffset >= 0) {
 398                 return fp + "+" + fpOffset;
 399             }
 400             return fp.name + fpOffset;
 401         }
 402     }
 403 
 404     public static class NumberedRefMapFormatter implements RefMapFormatter {
 405 
 406         public String formatStackSlot(int frameRefMapIndex) {
 407             return "s" + frameRefMapIndex;




   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 jdk.vm.ci.code;
  24 
  25 import java.util.ArrayList;
  26 import java.util.Arrays;
  27 import java.util.Collections;
  28 import java.util.Map;
  29 
  30 import jdk.vm.ci.meta.JavaType;
  31 import jdk.vm.ci.meta.MetaUtil;
  32 import jdk.vm.ci.meta.ResolvedJavaMethod;
  33 import jdk.vm.ci.meta.Signature;
  34 
  35 /**
  36  * Miscellaneous collection of utility methods used by {@code jdk.vm.ci.code} and its clients.
  37  */
  38 public class CodeUtil {
  39 
  40     public static final String NEW_LINE = String.format("%n");
  41 
  42     public static final int K = 1024;
  43     public static final int M = 1024 * 1024;
  44 
  45     public static boolean isOdd(int n) {
  46         return (n & 1) == 1;
  47     }
  48 
  49     public static boolean isEven(int n) {
  50         return (n & 1) == 0;
  51     }
  52 
  53     /**


 312                     sb.append("  ").append(row);
 313                     if (i != rows.length - 1) {
 314                         sb.append(NEW_LINE);
 315                     }
 316                 }
 317             }
 318         }
 319         if (frame.caller() != null) {
 320             sb.append(NEW_LINE);
 321             append(sb, frame.caller());
 322         } else if (frame.getCaller() != null) {
 323             sb.append(NEW_LINE);
 324             append(sb, frame.getCaller());
 325         }
 326         return sb;
 327     }
 328 
 329     public interface RefMapFormatter {
 330 
 331         String formatStackSlot(int frameRefMapIndex);





































 332     }
 333 
 334     /**
 335      * Formats a location present in a reference map.
 336      */
 337     public static class DefaultRefMapFormatter implements RefMapFormatter {
 338 
 339         /**
 340          * The size of a stack slot.
 341          */
 342         public final int slotSize;
 343 
 344         /**
 345          * The register used as the frame pointer.
 346          */
 347         public final Register fp;
 348 
 349         /**
 350          * The offset (in bytes) from the slot pointed to by {@link #fp} to the slot corresponding
 351          * to bit 0 in the frame reference map.
 352          */
 353         public final int refMapToFPOffset;
 354 
 355         public DefaultRefMapFormatter(int slotSize, Register fp, int refMapToFPOffset) {

 356             this.slotSize = slotSize;
 357             this.fp = fp;
 358             this.refMapToFPOffset = refMapToFPOffset;
 359         }
 360 
 361         @Override
 362         public String formatStackSlot(int frameRefMapIndex) {
 363             int refMapOffset = frameRefMapIndex * slotSize;
 364             int fpOffset = refMapOffset + refMapToFPOffset;
 365             if (fpOffset >= 0) {
 366                 return fp + "+" + fpOffset;
 367             }
 368             return fp.name + fpOffset;
 369         }
 370     }
 371 
 372     public static class NumberedRefMapFormatter implements RefMapFormatter {
 373 
 374         public String formatStackSlot(int frameRefMapIndex) {
 375             return "s" + frameRefMapIndex;


< prev index next >