constantTag.hpp revision 1522:136b78722a08
1251881Speter/*
2251881Speter * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
3251881Speter * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4251881Speter *
5251881Speter * This code is free software; you can redistribute it and/or modify it
6251881Speter * under the terms of the GNU General Public License version 2 only, as
7251881Speter * published by the Free Software Foundation.
8251881Speter *
9251881Speter * This code is distributed in the hope that it will be useful, but WITHOUT
10251881Speter * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11251881Speter * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12251881Speter * version 2 for more details (a copy is included in the LICENSE file that
13251881Speter * accompanied this code).
14251881Speter *
15251881Speter * You should have received a copy of the GNU General Public License version
16251881Speter * 2 along with this work; if not, write to the Free Software Foundation,
17251881Speter * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18251881Speter *
19251881Speter * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20251881Speter * or visit www.oracle.com if you need additional information or have any
21251881Speter * questions.
22251881Speter *
23251881Speter */
24251881Speter
25251881Speter// constant tags in Java .class files
26251881Speter
27251881Speter
28251881Speterenum {
29251881Speter  // See jvm.h for shared JVM_CONSTANT_XXX tags
30251881Speter  // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/utilities/ConstantTag.java
31251881Speter  // Hotspot specific tags
32251881Speter  JVM_CONSTANT_Invalid                  = 0,    // For bad value initialization
33251881Speter  JVM_CONSTANT_InternalMin              = 100,  // First implementation tag (aside from bad value of course)
34251881Speter  JVM_CONSTANT_UnresolvedClass          = 100,  // Temporary tag until actual use
35251881Speter  JVM_CONSTANT_ClassIndex               = 101,  // Temporary tag while constructing constant pool
36251881Speter  JVM_CONSTANT_UnresolvedString         = 102,  // Temporary tag until actual use
37251881Speter  JVM_CONSTANT_StringIndex              = 103,  // Temporary tag while constructing constant pool
38251881Speter  JVM_CONSTANT_UnresolvedClassInError   = 104,  // Error tag due to resolution error
39251881Speter  JVM_CONSTANT_Object                   = 105,  // Required for BoundMethodHandle arguments.
40251881Speter  JVM_CONSTANT_InternalMax              = 105   // Last implementation tag
41251881Speter};
42251881Speter
43251881Speter
44251881Speterclass constantTag VALUE_OBJ_CLASS_SPEC {
45251881Speter private:
46251881Speter  jbyte _tag;
47251881Speter public:
48251881Speter  bool is_klass() const             { return _tag == JVM_CONSTANT_Class; }
49251881Speter  bool is_field () const            { return _tag == JVM_CONSTANT_Fieldref; }
50251881Speter  bool is_method() const            { return _tag == JVM_CONSTANT_Methodref; }
51251881Speter  bool is_interface_method() const  { return _tag == JVM_CONSTANT_InterfaceMethodref; }
52251881Speter  bool is_string() const            { return _tag == JVM_CONSTANT_String; }
53251881Speter  bool is_int() const               { return _tag == JVM_CONSTANT_Integer; }
54251881Speter  bool is_float() const             { return _tag == JVM_CONSTANT_Float; }
55251881Speter  bool is_long() const              { return _tag == JVM_CONSTANT_Long; }
56251881Speter  bool is_double() const            { return _tag == JVM_CONSTANT_Double; }
57251881Speter  bool is_name_and_type() const     { return _tag == JVM_CONSTANT_NameAndType; }
58251881Speter  bool is_utf8() const              { return _tag == JVM_CONSTANT_Utf8; }
59251881Speter
60251881Speter  bool is_invalid() const           { return _tag == JVM_CONSTANT_Invalid; }
61251881Speter
62251881Speter  bool is_unresolved_klass() const {
63251881Speter    return _tag == JVM_CONSTANT_UnresolvedClass || _tag == JVM_CONSTANT_UnresolvedClassInError;
64251881Speter  }
65251881Speter
66251881Speter  bool is_unresolved_klass_in_error() const {
67251881Speter    return _tag == JVM_CONSTANT_UnresolvedClassInError;
68251881Speter  }
69251881Speter
70251881Speter  bool is_klass_index() const       { return _tag == JVM_CONSTANT_ClassIndex; }
71251881Speter  bool is_unresolved_string() const { return _tag == JVM_CONSTANT_UnresolvedString; }
72251881Speter  bool is_string_index() const      { return _tag == JVM_CONSTANT_StringIndex; }
73251881Speter
74251881Speter  bool is_object() const            { return _tag == JVM_CONSTANT_Object; }
75251881Speter
76251881Speter  bool is_klass_reference() const   { return is_klass_index() || is_unresolved_klass(); }
77251881Speter  bool is_klass_or_reference() const{ return is_klass() || is_klass_reference(); }
78251881Speter  bool is_field_or_method() const   { return is_field() || is_method() || is_interface_method(); }
79251881Speter  bool is_symbol() const            { return is_utf8(); }
80251881Speter
81251881Speter  bool is_method_type() const              { return _tag == JVM_CONSTANT_MethodType; }
82251881Speter  bool is_method_handle() const            { return _tag == JVM_CONSTANT_MethodHandle; }
83251881Speter
84251881Speter  constantTag() {
85251881Speter    _tag = JVM_CONSTANT_Invalid;
86251881Speter  }
87251881Speter  constantTag(jbyte tag) {
88251881Speter    assert((tag >= 0 && tag <= JVM_CONSTANT_NameAndType) ||
89251881Speter           (tag >= JVM_CONSTANT_MethodHandle && tag <= JVM_CONSTANT_MethodType) ||
90251881Speter           (tag >= JVM_CONSTANT_InternalMin && tag <= JVM_CONSTANT_InternalMax), "Invalid constant tag");
91251881Speter    _tag = tag;
92251881Speter  }
93251881Speter
94251881Speter  jbyte value()                      { return _tag; }
95251881Speter
96251881Speter  BasicType basic_type() const;        // if used with ldc, what kind of value gets pushed?
97251881Speter
98251881Speter  const char* internal_name() const;  // for error reporting
99251881Speter
100251881Speter  void print_on(outputStream* st) const PRODUCT_RETURN;
101251881Speter};
102251881Speter