|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, 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 | +package sun.jvm.hotspot.code; |
| 26 | + |
| 27 | +import java.util.*; |
| 28 | +import sun.jvm.hotspot.debugger.*; |
| 29 | +import sun.jvm.hotspot.runtime.*; |
| 30 | +import sun.jvm.hotspot.types.*; |
| 31 | +import sun.jvm.hotspot.utilities.Observable; |
| 32 | +import sun.jvm.hotspot.utilities.Observer; |
| 33 | + |
| 34 | +public class UpcallStub extends RuntimeBlob { |
| 35 | + |
| 36 | + private static CIntegerField frameDataOffsetField; |
| 37 | + private static AddressField lastJavaFPField; |
| 38 | + private static AddressField lastJavaSPField; |
| 39 | + private static AddressField lastJavaPCField; |
| 40 | + |
| 41 | + static { |
| 42 | + VM.registerVMInitializedObserver(new Observer() { |
| 43 | + public void update(Observable o, Object data) { |
| 44 | + initialize(VM.getVM().getTypeDataBase()); |
| 45 | + } |
| 46 | + }); |
| 47 | + } |
| 48 | + |
| 49 | + private static void initialize(TypeDataBase db) { |
| 50 | + Type type = db.lookupType("UpcallStub"); |
| 51 | + frameDataOffsetField = type.getCIntegerField("_frame_data_offset"); |
| 52 | + |
| 53 | + Type anchorType = db.lookupType("JavaFrameAnchor"); |
| 54 | + lastJavaSPField = anchorType.getAddressField("_last_Java_sp"); |
| 55 | + lastJavaPCField = anchorType.getAddressField("_last_Java_pc"); |
| 56 | + |
| 57 | + try { |
| 58 | + lastJavaFPField = anchorType.getAddressField("_last_Java_fp"); |
| 59 | + } catch (Exception e) { |
| 60 | + // Some platforms (e.g. PPC64) does not have this field. |
| 61 | + lastJavaFPField = null; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + public UpcallStub(Address addr) { |
| 66 | + super(addr); |
| 67 | + } |
| 68 | + |
| 69 | + protected Address getJavaFrameAnchor(Frame frame) { |
| 70 | + var frameDataOffset = frameDataOffsetField.getValue(addr); |
| 71 | + var frameDataAddr = frame.getUnextendedSP().addOffsetTo(frameDataOffset); |
| 72 | + var frameData = VMObjectFactory.newObject(FrameData.class, frameDataAddr); |
| 73 | + return frameData.getJavaFrameAnchor(); |
| 74 | + } |
| 75 | + |
| 76 | + public Address getLastJavaSP(Frame frame) { |
| 77 | + return lastJavaSPField.getValue(getJavaFrameAnchor(frame)); |
| 78 | + } |
| 79 | + |
| 80 | + public Address getLastJavaFP(Frame frame) { |
| 81 | + return lastJavaFPField == null ? null : lastJavaFPField.getValue(getJavaFrameAnchor(frame)); |
| 82 | + } |
| 83 | + |
| 84 | + public Address getLastJavaPC(Frame frame) { |
| 85 | + return lastJavaPCField.getValue(getJavaFrameAnchor(frame)); |
| 86 | + } |
| 87 | + |
| 88 | + public boolean isUpcallStub() { |
| 89 | + return true; |
| 90 | + } |
| 91 | + |
| 92 | + public static class FrameData extends VMObject { |
| 93 | + |
| 94 | + private static AddressField jfaField; |
| 95 | + |
| 96 | + static { |
| 97 | + VM.registerVMInitializedObserver(new Observer() { |
| 98 | + public void update(Observable o, Object data) { |
| 99 | + initialize(VM.getVM().getTypeDataBase()); |
| 100 | + } |
| 101 | + }); |
| 102 | + } |
| 103 | + |
| 104 | + private static void initialize(TypeDataBase db) { |
| 105 | + Type type = db.lookupType("UpcallStub::FrameData"); |
| 106 | + jfaField = type.getAddressField("jfa"); |
| 107 | + } |
| 108 | + |
| 109 | + public FrameData(Address addr) { |
| 110 | + super(addr); |
| 111 | + } |
| 112 | + |
| 113 | + public Address getJavaFrameAnchor() { |
| 114 | + return addr.addOffsetTo(jfaField.getOffset()); |
| 115 | + } |
| 116 | + |
| 117 | + } |
| 118 | + |
| 119 | +} |
0 commit comments