Frame.java

  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. package org.apache.bcel.verifier.structurals;

  18. /**
  19.  * This class represents a JVM execution frame; that means, a local variable array and an operand stack.
  20.  */

  21. public class Frame {

  22.     /**
  23.      * For instance initialization methods, it is important to remember which instance it is that is not initialized yet. It
  24.      * will be initialized invoking another constructor later. NULL means the instance already *is* initialized.
  25.      *
  26.      * @deprecated Use the getter/setter to access the field as it may be made private in a later release
  27.      */
  28.     @Deprecated
  29.     protected static UninitializedObjectType _this;

  30.     /**
  31.      * @return the _this
  32.      * @since 6.0
  33.      */
  34.     public static UninitializedObjectType getThis() {
  35.         return _this;
  36.     }

  37.     /**
  38.      * @param _this the _this to set
  39.      * @since 6.0
  40.      */
  41.     public static void setThis(final UninitializedObjectType _this) {
  42.         Frame._this = _this;
  43.     }

  44.     /**
  45.      */
  46.     private final LocalVariables locals;

  47.     /**
  48.      */
  49.     private final OperandStack stack;

  50.     /**
  51.      */
  52.     public Frame(final int maxLocals, final int maxStack) {
  53.         locals = new LocalVariables(maxLocals);
  54.         stack = new OperandStack(maxStack);
  55.     }

  56.     /**
  57.      */
  58.     public Frame(final LocalVariables locals, final OperandStack stack) {
  59.         this.locals = locals;
  60.         this.stack = stack;
  61.     }

  62.     /**
  63.      */
  64.     @Override
  65.     protected Object clone() {
  66.         return new Frame(locals.getClone(), stack.getClone());
  67.     }

  68.     /**
  69.      */
  70.     @Override
  71.     public boolean equals(final Object o) {
  72.         if (!(o instanceof Frame)) {
  73.             return false; // implies "null" is non-equal.
  74.         }
  75.         final Frame f = (Frame) o;
  76.         return this.stack.equals(f.stack) && this.locals.equals(f.locals);
  77.     }

  78.     /**
  79.      */
  80.     public Frame getClone() {
  81.         return (Frame) clone();
  82.     }

  83.     /**
  84.      */
  85.     public LocalVariables getLocals() {
  86.         return locals;
  87.     }

  88.     /**
  89.      */
  90.     public OperandStack getStack() {
  91.         return stack;
  92.     }

  93.     /**
  94.      * @return a hash code value for the object.
  95.      */
  96.     @Override
  97.     public int hashCode() {
  98.         return stack.hashCode() ^ locals.hashCode();
  99.     }

  100.     /**
  101.      * Returns a String representation of the Frame instance.
  102.      */
  103.     @Override
  104.     public String toString() {
  105.         final StringBuilder s = new StringBuilder("Local Variables:\n");
  106.         s.append(locals);
  107.         s.append("OperandStack:\n");
  108.         s.append(stack);
  109.         return s.toString();
  110.     }
  111. }