1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 package org.apache.bcel.verifier.structurals; 19 20 21 22 /** 23 * This class represents a JVM execution frame; that means, 24 * a local variable array and an operand stack. 25 * 26 * @version $Id$ 27 */ 28 29 public class Frame{ 30 31 /** 32 * For instance initialization methods, it is important to remember 33 * which instance it is that is not initialized yet. It will be 34 * initialized invoking another constructor later. 35 * NULL means the instance already *is* initialized. 36 * @deprecated Use the getter/setter to access the field as it may 37 * be made private in a later release 38 */ 39 @Deprecated 40 protected static UninitializedObjectType _this; 41 42 /** 43 * 44 */ 45 private final LocalVariables locals; 46 47 /** 48 * 49 */ 50 private final OperandStack stack; 51 52 /** 53 * 54 */ Frame(final int maxLocals, final int maxStack)55 public Frame(final int maxLocals, final int maxStack) { 56 locals = new LocalVariables(maxLocals); 57 stack = new OperandStack(maxStack); 58 } 59 60 /** 61 * 62 */ Frame(final LocalVariables locals, final OperandStack stack)63 public Frame(final LocalVariables locals, final OperandStack stack) { 64 this.locals = locals; 65 this.stack = stack; 66 } 67 68 /** 69 * 70 */ 71 @Override clone()72 protected Object clone() { 73 final Frame f = new Frame(locals.getClone(), stack.getClone()); 74 return f; 75 } 76 77 /** 78 * 79 */ getClone()80 public Frame getClone() { 81 return (Frame) clone(); 82 } 83 84 /** 85 * 86 */ getLocals()87 public LocalVariables getLocals() { 88 return locals; 89 } 90 91 /** 92 * 93 */ getStack()94 public OperandStack getStack() { 95 return stack; 96 } 97 98 /** @return a hash code value for the object. 99 */ 100 @Override hashCode()101 public int hashCode() { return stack.hashCode() ^ locals.hashCode(); } 102 103 /** 104 * 105 */ 106 @Override equals(final Object o)107 public boolean equals(final Object o) { 108 if (!(o instanceof Frame)) { 109 return false; // implies "null" is non-equal. 110 } 111 final Frame f = (Frame) o; 112 return this.stack.equals(f.stack) && this.locals.equals(f.locals); 113 } 114 115 /** 116 * Returns a String representation of the Frame instance. 117 */ 118 @Override toString()119 public String toString() { 120 String s="Local Variables:\n"; 121 s += locals; 122 s += "OperandStack:\n"; 123 s += stack; 124 return s; 125 } 126 127 /** 128 * @return the _this 129 * @since 6.0 130 */ getThis()131 public static UninitializedObjectType getThis() { 132 return _this; 133 } 134 135 /** 136 * @param _this the _this to set 137 * @since 6.0 138 */ setThis(final UninitializedObjectType _this)139 public static void setThis(final UninitializedObjectType _this) { 140 Frame._this = _this; 141 } 142 } 143