1 /* 2 * Copyright (c) 2015, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package java.lang; 26 27 final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame { 28 private static Object[] EMPTY_ARRAY = new Object[0]; 29 30 // These flags must match the values maintained in the VM 31 private static final int MODE_INTERPRETED = 0x01; 32 private static final int MODE_COMPILED = 0x02; 33 LiveStackFrameInfo(StackWalker walker)34 LiveStackFrameInfo(StackWalker walker) { 35 super(walker); 36 } 37 38 // These fields are initialized by the VM if ExtendedOption.LOCALS_AND_OPERANDS is set 39 private Object[] monitors = EMPTY_ARRAY; 40 private Object[] locals = EMPTY_ARRAY; 41 private Object[] operands = EMPTY_ARRAY; 42 private int mode = 0; 43 44 @Override getMonitors()45 public Object[] getMonitors() { 46 return monitors; 47 } 48 49 @Override getLocals()50 public Object[] getLocals() { 51 return locals; 52 } 53 54 @Override getStack()55 public Object[] getStack() { 56 return operands; 57 } 58 59 @Override toString()60 public String toString() { 61 StringBuilder retVal = new StringBuilder(super.toString()); 62 if (mode != 0) { 63 retVal.append("("); 64 if ((mode & MODE_INTERPRETED) == MODE_INTERPRETED) { 65 retVal.append(" interpreted "); 66 } 67 if ((mode & MODE_COMPILED) == MODE_COMPILED) { 68 retVal.append(" compiled "); 69 } 70 retVal.append(")"); 71 } 72 return retVal.toString(); 73 } 74 75 /* 76 * Convert primitive value to {@code PrimitiveSlot} object to represent 77 * a local variable or an element on the operand stack of primitive type. 78 */ 79 asPrimitive(int value)80 static PrimitiveSlot asPrimitive(int value) { 81 return new PrimitiveSlot32(value); 82 } 83 asPrimitive(long value)84 static PrimitiveSlot asPrimitive(long value) { 85 return new PrimitiveSlot64(value); 86 } 87 88 private static class PrimitiveSlot32 extends PrimitiveSlot { 89 final int value; PrimitiveSlot32(int value)90 PrimitiveSlot32(int value) { 91 this.value = value; 92 } 93 94 @Override size()95 public int size() { 96 return 4; 97 } 98 99 @Override intValue()100 public int intValue() { 101 return value; 102 } 103 104 @Override toString()105 public String toString() { 106 return String.valueOf(value); 107 } 108 } 109 110 private static class PrimitiveSlot64 extends PrimitiveSlot { 111 final long value; PrimitiveSlot64(long value)112 PrimitiveSlot64(long value) { 113 this.value = value; 114 } 115 116 @Override size()117 public int size() { 118 return 8; 119 } 120 121 @Override longValue()122 public long longValue() { 123 return value; 124 } 125 126 @Override toString()127 public String toString() { 128 return String.valueOf(value); 129 } 130 } 131 } 132