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