001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 */ 018package org.apache.bcel.verifier.structurals; 019 020 021 022/** 023 * This class represents a JVM execution frame; that means, 024 * a local variable array and an operand stack. 025 * 026 * @version $Id: Frame.java 1806200 2017-08-25 16:33:06Z ggregory $ 027 */ 028 029public class Frame{ 030 031 /** 032 * For instance initialization methods, it is important to remember 033 * which instance it is that is not initialized yet. It will be 034 * initialized invoking another constructor later. 035 * NULL means the instance already *is* initialized. 036 * @deprecated Use the getter/setter to access the field as it may 037 * be made private in a later release 038 */ 039 @Deprecated 040 protected static UninitializedObjectType _this; 041 042 /** 043 * 044 */ 045 private final LocalVariables locals; 046 047 /** 048 * 049 */ 050 private final OperandStack stack; 051 052 /** 053 * 054 */ 055 public Frame(final int maxLocals, final int maxStack) { 056 locals = new LocalVariables(maxLocals); 057 stack = new OperandStack(maxStack); 058 } 059 060 /** 061 * 062 */ 063 public Frame(final LocalVariables locals, final OperandStack stack) { 064 this.locals = locals; 065 this.stack = stack; 066 } 067 068 /** 069 * 070 */ 071 @Override 072 protected Object clone() { 073 final Frame f = new Frame(locals.getClone(), stack.getClone()); 074 return f; 075 } 076 077 /** 078 * 079 */ 080 public Frame getClone() { 081 return (Frame) clone(); 082 } 083 084 /** 085 * 086 */ 087 public LocalVariables getLocals() { 088 return locals; 089 } 090 091 /** 092 * 093 */ 094 public OperandStack getStack() { 095 return stack; 096 } 097 098 /** @return a hash code value for the object. 099 */ 100 @Override 101 public int hashCode() { return stack.hashCode() ^ locals.hashCode(); } 102 103 /** 104 * 105 */ 106 @Override 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 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 */ 131 public static UninitializedObjectType getThis() { 132 return _this; 133 } 134 135 /** 136 * @param _this the _this to set 137 * @since 6.0 138 */ 139 public static void setThis(final UninitializedObjectType _this) { 140 Frame._this = _this; 141 } 142}