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 24 package jdk.tools.jaotc; 25 26 import jdk.tools.jaotc.binformat.BinaryContainer; 27 import jdk.tools.jaotc.binformat.Relocation; 28 import jdk.tools.jaotc.binformat.Relocation.RelocType; 29 import jdk.tools.jaotc.binformat.Symbol; 30 31 import jdk.vm.ci.code.site.Mark; 32 33 final class MarkProcessor { 34 35 private final BinaryContainer binaryContainer; 36 37 MarkProcessor(DataBuilder dataBuilder) { 38 binaryContainer = dataBuilder.getBinaryContainer(); 39 } 40 41 /** 42 * Parse a {@link Mark} generated by the compiler and create all needed binary section 43 * constructs. 44 * 45 * @param methodInfo compiled method info 46 * @param mark mark being processed 47 */ 48 void process(CompiledMethodInfo methodInfo, Mark mark) { 49 MarkId markId = MarkId.getEnum((int) mark.id); 50 switch (markId) { 51 case EXCEPTION_HANDLER_ENTRY: 52 case DEOPT_HANDLER_ENTRY: 53 break; 54 case POLL_FAR: 55 case POLL_RETURN_FAR: 56 case CARD_TABLE_ADDRESS: 57 case HEAP_TOP_ADDRESS: 58 case HEAP_END_ADDRESS: 59 case NARROW_KLASS_BASE_ADDRESS: 60 case NARROW_OOP_BASE_ADDRESS: 61 case CRC_TABLE_ADDRESS: 62 case LOG_OF_HEAP_REGION_GRAIN_BYTES: 63 case INLINE_CONTIGUOUS_ALLOCATION_SUPPORTED: 64 String vmSymbolName; 65 switch (markId) { 66 case POLL_FAR: 67 case POLL_RETURN_FAR: 68 vmSymbolName = BinaryContainer.getPollingPageSymbolName(); 69 break; 70 case CARD_TABLE_ADDRESS: 71 vmSymbolName = BinaryContainer.getCardTableAddressSymbolName(); 72 break; 73 case HEAP_TOP_ADDRESS: 74 vmSymbolName = BinaryContainer.getHeapTopAddressSymbolName(); 75 break; 76 case HEAP_END_ADDRESS: 77 vmSymbolName = BinaryContainer.getHeapEndAddressSymbolName(); 78 break; 79 case NARROW_KLASS_BASE_ADDRESS: 80 vmSymbolName = BinaryContainer.getNarrowKlassBaseAddressSymbolName(); 81 break; 82 case NARROW_OOP_BASE_ADDRESS: 83 vmSymbolName = BinaryContainer.getNarrowOopBaseAddressSymbolName(); 84 break; 85 case CRC_TABLE_ADDRESS: 86 vmSymbolName = BinaryContainer.getCrcTableAddressSymbolName(); 87 break; 88 case LOG_OF_HEAP_REGION_GRAIN_BYTES: 89 vmSymbolName = BinaryContainer.getLogOfHeapRegionGrainBytesSymbolName(); 90 break; 91 case INLINE_CONTIGUOUS_ALLOCATION_SUPPORTED: 92 vmSymbolName = BinaryContainer.getInlineContiguousAllocationSupportedSymbolName(); 93 break; 94 default: 95 throw new InternalError("Unhandled mark: " + mark); 96 } 97 String s = "got." + vmSymbolName; 98 Symbol gotSymbol = binaryContainer.getGotSymbol(s); 99 assert gotSymbol != null : " Processing Mark: Encountered undefined got symbol for " + mark; 100 final int textBaseOffset = methodInfo.getTextSectionOffset(); 101 final int textOffset = textBaseOffset + mark.pcOffset; 102 Relocation reloc = new Relocation(textOffset, RelocType.EXTERNAL_PLT_TO_GOT, 8, binaryContainer.getCodeContainer(), gotSymbol); 103 binaryContainer.addRelocation(reloc); 104 break; 105 case VERIFIED_ENTRY: 106 case UNVERIFIED_ENTRY: 107 case OSR_ENTRY: 108 case INVOKEINTERFACE: 109 case INVOKEVIRTUAL: 110 case INVOKESTATIC: 111 case INVOKESPECIAL: 112 case INLINE_INVOKE: 113 case POLL_NEAR: 114 case POLL_RETURN_NEAR: 115 // Nothing to do. 116 break; 117 default: 118 throw new InternalError("Unexpected mark found: " + mark); 119 } 120 } 121 }