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