hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaInstanceKlass.java
author coleenp
Wed, 22 May 2013 14:37:49 -0400
changeset 17826 9ad5cd464a75
parent 13728 882756847a04
child 22234 da823d78ad65
permissions -rw-r--r--
8003421: NPG: Move oops out of InstanceKlass into mirror Summary: Inject protection_domain, signers, init_lock into java_lang_Class Reviewed-by: stefank, dholmes, sla
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
     2
 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.utilities.soql;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
/**
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
   This is JavaScript wrapper for InstanceKlass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
public class JSJavaInstanceKlass extends JSJavaKlass {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
   private static final int FIELD_SOURCE_FILE        = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
   private static final int FIELD_INTERFACES         = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
   private static final int FIELD_FIELDS             = 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
   private static final int FIELD_METHODS            = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
   private static final int FIELD_IS_PRIVATE         = 5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
   private static final int FIELD_IS_PUBLIC          = 6;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
   private static final int FIELD_IS_PROTECTED       = 7;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
   private static final int FIELD_IS_PACKAGE_PRIVATE = 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
   private static final int FIELD_IS_STATIC          = 9;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
   private static final int FIELD_IS_FINAL           = 10;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
   private static final int FIELD_IS_ABSTRACT        = 11;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
   private static final int FIELD_IS_STRICT          = 12;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
   private static final int FIELD_IS_SYNTHETIC       = 13;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
   private static final int FIELD_IS_INTERFACE       = 14;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
   private static final int FIELD_CLASS_LOADER       = 15;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
   private static final int FIELD_STATICS            = 18;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
   private static final int FIELD_UNDEFINED          = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
   public JSJavaInstanceKlass(InstanceKlass kls, JSJavaFactory fac) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      super(kls, fac);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      this.instanceFields = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
      this.staticFields = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
   public final InstanceKlass getInstanceKlass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      return (InstanceKlass) getKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
   public Object getMetaClassFieldValue(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      int fieldID = getFieldID(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      InstanceKlass ik = getInstanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      switch (fieldID) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      case FIELD_SOURCE_FILE: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
         Symbol sourceFile = ik.getSourceFileName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
         return (sourceFile != null)? sourceFile.asString() : "<unknown>";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      case FIELD_INTERFACES:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
         return getInterfaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      case FIELD_FIELDS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
         return factory.newJSList(ik.getImmediateFields());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      case FIELD_METHODS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
         return factory.newJSList(ik.getImmediateMethods());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      case FIELD_IS_PRIVATE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
         return Boolean.valueOf(getAccessFlags().isPrivate());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      case FIELD_IS_PUBLIC:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
         return Boolean.valueOf(getAccessFlags().isPublic());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      case FIELD_IS_PROTECTED:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
         return Boolean.valueOf(getAccessFlags().isProtected());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      case FIELD_IS_PACKAGE_PRIVATE: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
         AccessFlags acc = getAccessFlags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
         return Boolean.valueOf(!acc.isPrivate() && !acc.isPublic() && !acc.isProtected());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      case FIELD_IS_STATIC:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
         return Boolean.valueOf(getAccessFlags().isStatic());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      case FIELD_IS_FINAL:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
         return Boolean.valueOf(getAccessFlags().isFinal());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      case FIELD_IS_ABSTRACT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
         return Boolean.valueOf(getAccessFlags().isAbstract());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      case FIELD_IS_STRICT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
         return Boolean.valueOf(getAccessFlags().isStrict());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      case FIELD_IS_SYNTHETIC:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
         return Boolean.valueOf(getAccessFlags().isSynthetic());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      case FIELD_IS_INTERFACE:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
         return Boolean.valueOf(ik.isInterface());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      case FIELD_CLASS_LOADER:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
         return factory.newJSJavaObject(ik.getClassLoader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      case FIELD_STATICS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
         return getStatics();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      case FIELD_UNDEFINED:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
         return super.getMetaClassFieldValue(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
   public boolean hasMetaClassField(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      if (getFieldID(name) != FIELD_UNDEFINED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
          return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
          return super.hasMetaClassField(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
   public String getName() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      return getInstanceKlass().getName().asString().replace('/', '.');
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
   public boolean isArray() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
   public String[] getMetaClassFieldNames() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      String[] superFields = super.getMetaClassFieldNames();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      Set k = fields.keySet();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      String[] res = new String[k.size() + superFields.length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      System.arraycopy(superFields, 0, res, 0, superFields.length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      int i = superFields.length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      for (Iterator itr = k.iterator(); itr.hasNext();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
          res[i] = (String) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
          i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
   public Object getInstanceFieldValue(String name, Instance instance) throws NoSuchFieldException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      Field fld = findInstanceField(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      if (fld != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
         return getFieldValue(fld, name, instance);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
         throw new NoSuchFieldException(name + " is not field of "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
                + getInstanceKlass().getName().asString().replace('/', '.'));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
   public Object getStaticFieldValue(String name) throws NoSuchFieldException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      Field fld = findStaticField(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      if (fld != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
         return getFieldValue(fld, name, getInstanceKlass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
         throw new NoSuchFieldException(name + " is not field of "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
                + getInstanceKlass().getName().asString().replace('/', '.'));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
   public String[] getInstanceFieldNames() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      if (instanceFieldNames == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
         InstanceKlass current = getInstanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
         while (current != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
            List tmp = current.getImmediateFields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
            for (Iterator itr = tmp.iterator(); itr.hasNext();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
               Field fld = (Field) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
               if (!fld.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
                  String name = fld.getID().getName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                  if (instanceFields.get(name) == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
                     instanceFields.put(name, fld);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
                  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
            current = (InstanceKlass) current.getSuper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
         Set s = instanceFields.keySet();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
         instanceFieldNames = new String[s.size()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
         int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
         for (Iterator itr = s.iterator(); itr.hasNext(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
            instanceFieldNames[i] = (String) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      return instanceFieldNames;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
   public boolean hasInstanceField(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      Field fld = findInstanceField(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      return (fld != null)? true: false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
   public String[] getStaticFieldNames() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      if (staticFieldNames == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
         InstanceKlass current = getInstanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
         List tmp = current.getImmediateFields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
         for (Iterator itr = tmp.iterator(); itr.hasNext();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
            Field fld = (Field) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
            if (fld.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
               staticFields.put(fld.getID().getName(), fld);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
         Set s = staticFields.keySet();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
         staticFieldNames = new String[s.size()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
         int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
         for (Iterator itr = s.iterator(); itr.hasNext(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
            staticFieldNames[i] = (String) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      return staticFieldNames;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
   public boolean hasStaticField(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      Field fld = findStaticField(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      return (fld != null)? true: false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
   //-- Intenals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
   private static Map fields = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
   private static void addField(String name, int fieldId) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      fields.put(name, new Integer(fieldId));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
   private static int getFieldID(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      Integer res = (Integer) fields.get(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      return (res != null)? res.intValue() : FIELD_UNDEFINED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
   static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      addField("sourceFile", FIELD_SOURCE_FILE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      addField("interfaces", FIELD_INTERFACES);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      addField("fields", FIELD_FIELDS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      addField("methods", FIELD_METHODS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      addField("isPrivate", FIELD_IS_PRIVATE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      addField("isPublic", FIELD_IS_PUBLIC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      addField("isProtected", FIELD_IS_PROTECTED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      addField("isPackagePrivate", FIELD_IS_PACKAGE_PRIVATE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      addField("isStatic", FIELD_IS_STATIC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      addField("isFinal", FIELD_IS_FINAL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      addField("isAbstract", FIELD_IS_ABSTRACT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
      addField("isStrict", FIELD_IS_STRICT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
      addField("isSynthetic", FIELD_IS_SYNTHETIC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      addField("isInterface", FIELD_IS_INTERFACE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      addField("classLoader", FIELD_CLASS_LOADER);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      addField("statics", FIELD_STATICS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
   private AccessFlags getAccessFlags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      if (accFlags == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
         accFlags = new AccessFlags(getInstanceKlass().computeModifierFlags());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      return accFlags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
   private Object getFieldValue(Field fld, String name, Oop oop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
       FieldType fd = fld.getFieldType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
       if (fd.isObject() || fd.isArray()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
         return factory.newJSJavaObject(((OopField)fld).getValue(oop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
       } else if (fd.isByte()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
          return new Byte(((ByteField)fld).getValue(oop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
       } else if (fd.isChar()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
          return new String(new char[] { ((CharField)fld).getValue(oop) });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
       } else if (fd.isDouble()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
          return new Double(((DoubleField)fld).getValue(oop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
       } else if (fd.isFloat()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
          return new Float(((FloatField)fld).getValue(oop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
       } else if (fd.isInt()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
          return new Integer(((IntField)fld).getValue(oop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
       } else if (fd.isLong()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
          return new Long(((LongField)fld).getValue(oop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
       } else if (fd.isShort()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
          return new Short(((ShortField)fld).getValue(oop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
       } else if (fd.isBoolean()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
          return Boolean.valueOf(((BooleanField)fld).getValue(oop));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
       } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
          if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
             Assert.that(false, "invalid field type for " + name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
          return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   281
   private Object getFieldValue(Field fld, String name, InstanceKlass oop) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   282
       FieldType fd = fld.getFieldType();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   283
       if (fd.isObject() || fd.isArray()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   284
         return factory.newJSJavaObject(((OopField)fld).getValue(oop));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   285
       } else if (fd.isByte()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   286
          return new Byte(((ByteField)fld).getValue(oop));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   287
       } else if (fd.isChar()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   288
          return new String(new char[] { ((CharField)fld).getValue(oop) });
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   289
       } else if (fd.isDouble()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   290
          return new Double(((DoubleField)fld).getValue(oop));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   291
       } else if (fd.isFloat()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   292
          return new Float(((FloatField)fld).getValue(oop));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   293
       } else if (fd.isInt()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   294
          return new Integer(((IntField)fld).getValue(oop));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   295
       } else if (fd.isLong()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   296
          return new Long(((LongField)fld).getValue(oop));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   297
       } else if (fd.isShort()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   298
          return new Short(((ShortField)fld).getValue(oop));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   299
       } else if (fd.isBoolean()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   300
          return Boolean.valueOf(((BooleanField)fld).getValue(oop));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   301
       } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   302
          if (Assert.ASSERTS_ENABLED) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   303
             Assert.that(false, "invalid field type for " + name);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   304
          }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   305
          return null;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   306
       }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   307
   }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5547
diff changeset
   308
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
   private Field findInstanceField(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      Field fld = (Field) instanceFields.get(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      if (fld != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
         return fld;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
         InstanceKlass current = getInstanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
         while (current != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
            List tmp = current.getImmediateFields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
            for (Iterator itr = tmp.iterator(); itr.hasNext();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
               fld = (Field) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
               if (fld.getID().getName().equals(name) && !fld.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
                   instanceFields.put(name, fld);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
                   return fld;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
            // lookup in super class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
            current = (InstanceKlass) current.getSuper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
      // no match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
   private Field findStaticField(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      Field fld = (Field) staticFields.get(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      if (fld != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
         return fld;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
         // static fields are searched only in current.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
         // Direct/indirect super classes and interfaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
         // are not included in search.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
         InstanceKlass current = getInstanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
         List tmp = current.getImmediateFields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
         for (Iterator itr = tmp.iterator(); itr.hasNext();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
            fld = (Field) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
            if (fld.getID().getName().equals(name) && fld.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
               staticFields.put(name, fld);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
               return fld;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
         // no match
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
         return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
   private JSList getInterfaces() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      InstanceKlass ik = getInstanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      List intfs = ik.getDirectImplementedInterfaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      List res = new ArrayList(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      for (Iterator itr = intfs.iterator(); itr.hasNext();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
          Klass k = (Klass) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
          res.add(k.getJavaMirror());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      return factory.newJSList(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
   private JSMap getStatics() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
      String[] names = getStaticFieldNames();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
      Map map = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      for (int i=0; i < names.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
         try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
            map.put(names[i], getStaticFieldValue(names[i]));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
         } catch (NoSuchFieldException exp) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      return factory.newJSMap(map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
   private Map           instanceFields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
   private Map           staticFields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
   private String[]      instanceFieldNames;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
   private String[]      staticFieldNames;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
   private AccessFlags   accFlags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
}