1 /*
   2  * Copyright (c) 2016, 2018, 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 
  25 
  26 package jdk.tools.jaotc;
  27 
  28 import java.util.List;
  29 
  30 import jdk.vm.ci.code.site.Mark;
  31 
  32 final class CodeOffsets {
  33     private final int entry;
  34     private final int verifiedEntry;
  35     private final int exceptionHandler;
  36     private final int deoptHandler;
  37 
  38     private CodeOffsets(int entry, int verifiedEntry, int exceptionHandler, int deoptHandler) {
  39         this.entry = entry;
  40         this.verifiedEntry = verifiedEntry;
  41         this.exceptionHandler = exceptionHandler;
  42         this.deoptHandler = deoptHandler;
  43     }
  44 
  45     static CodeOffsets buildFrom(List<Mark> marks) {
  46         int entry = 0;
  47         int verifiedEntry = 0;
  48         int exceptionHandler = -1;
  49         int deoptHandler = -1;
  50 
  51         for (Mark mark : marks) {
  52             if (mark.id instanceof Integer) {
  53                 MarkId markId = MarkId.getEnum((int) mark.id);
  54                 switch (markId) {
  55                     case UNVERIFIED_ENTRY:
  56                         entry = mark.pcOffset;
  57                         break;
  58                     case VERIFIED_ENTRY:
  59                         verifiedEntry = mark.pcOffset;
  60                         break;
  61                     case OSR_ENTRY:
  62                         // Unhandled
  63                         break;
  64                     case EXCEPTION_HANDLER_ENTRY:
  65                         exceptionHandler = mark.pcOffset;
  66                         break;
  67                     case DEOPT_HANDLER_ENTRY:
  68                         deoptHandler = mark.pcOffset;
  69                         break;
  70                     default:
  71                         break; // Ignore others
  72                 }
  73             }
  74         }
  75         return new CodeOffsets(entry, verifiedEntry, exceptionHandler, deoptHandler);
  76     }
  77 
  78     int entry() {
  79         return entry;
  80     }
  81 
  82     int verifiedEntry() {
  83         return verifiedEntry;
  84     }
  85 
  86     int exceptionHandler() {
  87         return exceptionHandler;
  88     }
  89 
  90     int deoptHandler() {
  91         return deoptHandler;
  92     }
  93 }