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