1 /*
   2  * Copyright (c) 2000, 2009, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores,
  20  * CA 94065 USA or visit www.oracle.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.code;
  26 
  27 import java.io.*;
  28 
  29 import sun.jvm.hotspot.utilities.*;
  30 
  31 /** <P> Classes used for serializing debugging information. These
  32     abstractions are introducted to provide symmetric read and write
  33     operations. </P>
  34 
  35     <P>
  36     <UL>
  37     <LI> ScopeValue: describes the value of a variable/expression in a scope
  38     <UL>
  39     <LI> LocationValue: describes a value in a given location (in frame or register)
  40     <LI> ConstantValue: describes a constant
  41     </UL>
  42     </UL>
  43     </P> */
  44 
  45 public abstract class ScopeValue {
  46   // Package private enumeration values (FIXME: read from target VM)
  47   static final int LOCATION_CODE        = 0;
  48   static final int CONSTANT_INT_CODE    = 1;
  49   static final int CONSTANT_OOP_CODE    = 2;
  50   static final int CONSTANT_LONG_CODE   = 3;
  51   static final int CONSTANT_DOUBLE_CODE = 4;
  52   static final int CONSTANT_OBJECT_CODE = 5;
  53   static final int CONSTANT_OBJECT_ID_CODE = 6;
  54 
  55   public boolean isLocation()       { return false; }
  56   public boolean isConstantInt()    { return false; }
  57   public boolean isConstantDouble() { return false; }
  58   public boolean isConstantLong()   { return false; }
  59   public boolean isConstantOop()    { return false; }
  60   public boolean isObject()         { return false; }
  61 
  62   public static ScopeValue readFrom(DebugInfoReadStream stream) {
  63     switch (stream.readInt()) {
  64     case LOCATION_CODE:
  65       return new LocationValue(stream);
  66     case CONSTANT_INT_CODE:
  67       return new ConstantIntValue(stream);
  68     case CONSTANT_OOP_CODE:
  69       return new ConstantOopReadValue(stream);
  70     case CONSTANT_LONG_CODE:
  71       return new ConstantLongValue(stream);
  72     case CONSTANT_DOUBLE_CODE:
  73       return new ConstantDoubleValue(stream);
  74     case CONSTANT_OBJECT_CODE:
  75       return stream.readObjectValue();
  76     case CONSTANT_OBJECT_ID_CODE:
  77       return stream.getCachedObject();
  78     default:
  79       Assert.that(false, "should not reach here");
  80       return null;
  81     }
  82   }
  83 
  84   public abstract void printOn(PrintStream tty);
  85 }