提交 68345435 编写于 作者: N never

7092278: "jmap -finalizerinfo" throws...

7092278: "jmap -finalizerinfo" throws "sun.jvm.hotspot.utilities.AssertionFailure: invalid cp index 0 137"
Reviewed-by: kvn
上级 86701242
...@@ -44,14 +44,14 @@ public class InstanceKlass extends Klass { ...@@ -44,14 +44,14 @@ public class InstanceKlass extends Klass {
} }
// field offset constants // field offset constants
public static int ACCESS_FLAGS_OFFSET; private static int ACCESS_FLAGS_OFFSET;
public static int NAME_INDEX_OFFSET; private static int NAME_INDEX_OFFSET;
public static int SIGNATURE_INDEX_OFFSET; private static int SIGNATURE_INDEX_OFFSET;
public static int INITVAL_INDEX_OFFSET; private static int INITVAL_INDEX_OFFSET;
public static int LOW_OFFSET; private static int LOW_OFFSET;
public static int HIGH_OFFSET; private static int HIGH_OFFSET;
public static int GENERIC_SIGNATURE_INDEX_OFFSET; private static int GENERIC_SIGNATURE_INDEX_OFFSET;
public static int FIELD_SLOTS; private static int FIELD_SLOTS;
public static int IMPLEMENTORS_LIMIT; public static int IMPLEMENTORS_LIMIT;
// ClassState constants // ClassState constants
...@@ -122,6 +122,13 @@ public class InstanceKlass extends Klass { ...@@ -122,6 +122,13 @@ public class InstanceKlass extends Klass {
InstanceKlass(OopHandle handle, ObjectHeap heap) { InstanceKlass(OopHandle handle, ObjectHeap heap) {
super(handle, heap); super(handle, heap);
if (getJavaFieldsCount() != getAllFieldsCount()) {
// Exercise the injected field logic
for (int i = getJavaFieldsCount(); i < getAllFieldsCount(); i++) {
getFieldName(i);
getFieldSignature(i);
}
}
} }
private static OopField arrayKlasses; private static OopField arrayKlasses;
...@@ -253,24 +260,51 @@ public class InstanceKlass extends Klass { ...@@ -253,24 +260,51 @@ public class InstanceKlass extends Klass {
return getFields().getShortAt(index * FIELD_SLOTS + ACCESS_FLAGS_OFFSET); return getFields().getShortAt(index * FIELD_SLOTS + ACCESS_FLAGS_OFFSET);
} }
public short getFieldNameIndex(int index) {
if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
return getFields().getShortAt(index * FIELD_SLOTS + NAME_INDEX_OFFSET);
}
public Symbol getFieldName(int index) { public Symbol getFieldName(int index) {
int nameIndex = getFields().getShortAt(index * FIELD_SLOTS + NAME_INDEX_OFFSET); int nameIndex = getFields().getShortAt(index * FIELD_SLOTS + NAME_INDEX_OFFSET);
if (index < getJavaFieldsCount()) {
return getConstants().getSymbolAt(nameIndex); return getConstants().getSymbolAt(nameIndex);
} else {
return vmSymbols.symbolAt(nameIndex);
}
}
public short getFieldSignatureIndex(int index) {
if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
return getFields().getShortAt(index * FIELD_SLOTS + SIGNATURE_INDEX_OFFSET);
} }
public Symbol getFieldSignature(int index) { public Symbol getFieldSignature(int index) {
int signatureIndex = getFields().getShortAt(index * FIELD_SLOTS + SIGNATURE_INDEX_OFFSET); int signatureIndex = getFields().getShortAt(index * FIELD_SLOTS + SIGNATURE_INDEX_OFFSET);
if (index < getJavaFieldsCount()) {
return getConstants().getSymbolAt(signatureIndex); return getConstants().getSymbolAt(signatureIndex);
} else {
return vmSymbols.symbolAt(signatureIndex);
}
}
public short getFieldGenericSignatureIndex(int index) {
return getFields().getShortAt(index * FIELD_SLOTS + GENERIC_SIGNATURE_INDEX_OFFSET);
} }
public Symbol getFieldGenericSignature(int index) { public Symbol getFieldGenericSignature(int index) {
short genericSignatureIndex = getFields().getShortAt(index * FIELD_SLOTS + GENERIC_SIGNATURE_INDEX_OFFSET); short genericSignatureIndex = getFieldGenericSignatureIndex(index);
if (genericSignatureIndex != 0) { if (genericSignatureIndex != 0) {
return getConstants().getSymbolAt(genericSignatureIndex); return getConstants().getSymbolAt(genericSignatureIndex);
} }
return null; return null;
} }
public short getFieldInitialValueIndex(int index) {
if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
return getFields().getShortAt(index * FIELD_SLOTS + INITVAL_INDEX_OFFSET);
}
public int getFieldOffset(int index) { public int getFieldOffset(int index) {
TypeArray fields = getFields(); TypeArray fields = getFields();
return VM.getVM().buildIntFromShorts(fields.getShortAt(index * FIELD_SLOTS + LOW_OFFSET), return VM.getVM().buildIntFromShorts(fields.getShortAt(index * FIELD_SLOTS + LOW_OFFSET),
...@@ -288,7 +322,7 @@ public class InstanceKlass extends Klass { ...@@ -288,7 +322,7 @@ public class InstanceKlass extends Klass {
public Klass getImplementor(int i) { return (Klass) implementors[i].getValue(this); } public Klass getImplementor(int i) { return (Klass) implementors[i].getValue(this); }
public TypeArray getFields() { return (TypeArray) fields.getValue(this); } public TypeArray getFields() { return (TypeArray) fields.getValue(this); }
public int getJavaFieldsCount() { return (int) javaFieldsCount.getValue(this); } public int getJavaFieldsCount() { return (int) javaFieldsCount.getValue(this); }
public int getAllFieldsCount() { return (int)getFields().getLength(); } public int getAllFieldsCount() { return (int)getFields().getLength() / FIELD_SLOTS; }
public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); } public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); }
public Oop getClassLoader() { return classLoader.getValue(this); } public Oop getClassLoader() { return classLoader.getValue(this); }
public Oop getProtectionDomain() { return protectionDomain.getValue(this); } public Oop getProtectionDomain() { return protectionDomain.getValue(this); }
...@@ -511,7 +545,6 @@ public class InstanceKlass extends Klass { ...@@ -511,7 +545,6 @@ public class InstanceKlass extends Klass {
} }
void iterateStaticFieldsInternal(OopVisitor visitor) { void iterateStaticFieldsInternal(OopVisitor visitor) {
TypeArray fields = getFields();
int length = getJavaFieldsCount(); int length = getJavaFieldsCount();
for (int index = 0; index < length; index++) { for (int index = 0; index < length; index++) {
short accessFlags = getFieldAccessFlags(index); short accessFlags = getFieldAccessFlags(index);
...@@ -541,8 +574,6 @@ public class InstanceKlass extends Klass { ...@@ -541,8 +574,6 @@ public class InstanceKlass extends Klass {
if (getSuper() != null) { if (getSuper() != null) {
((InstanceKlass) getSuper()).iterateNonStaticFields(visitor, obj); ((InstanceKlass) getSuper()).iterateNonStaticFields(visitor, obj);
} }
TypeArray fields = getFields();
int length = getJavaFieldsCount(); int length = getJavaFieldsCount();
for (int index = 0; index < length; index++) { for (int index = 0; index < length; index++) {
short accessFlags = getFieldAccessFlags(index); short accessFlags = getFieldAccessFlags(index);
...@@ -556,9 +587,7 @@ public class InstanceKlass extends Klass { ...@@ -556,9 +587,7 @@ public class InstanceKlass extends Klass {
/** Field access by name. */ /** Field access by name. */
public Field findLocalField(Symbol name, Symbol sig) { public Field findLocalField(Symbol name, Symbol sig) {
TypeArray fields = getFields(); int length = getJavaFieldsCount();
int length = (int) fields.getLength();
ConstantPool cp = getConstants();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
Symbol f_name = getFieldName(i); Symbol f_name = getFieldName(i);
Symbol f_sig = getFieldSignature(i); Symbol f_sig = getFieldSignature(i);
...@@ -648,8 +677,6 @@ public class InstanceKlass extends Klass { ...@@ -648,8 +677,6 @@ public class InstanceKlass extends Klass {
public List getImmediateFields() { public List getImmediateFields() {
// A list of Fields for each field declared in this class/interface, // A list of Fields for each field declared in this class/interface,
// not including inherited fields. // not including inherited fields.
TypeArray fields = getFields();
int length = getJavaFieldsCount(); int length = getJavaFieldsCount();
List immediateFields = new ArrayList(length); List immediateFields = new ArrayList(length);
for (int index = 0; index < length; index++) { for (int index = 0; index < length; index++) {
...@@ -839,7 +866,6 @@ public class InstanceKlass extends Klass { ...@@ -839,7 +866,6 @@ public class InstanceKlass extends Klass {
// Creates new field from index in fields TypeArray // Creates new field from index in fields TypeArray
private Field newField(int index) { private Field newField(int index) {
TypeArray fields = getFields();
FieldType type = new FieldType(getFieldSignature(index)); FieldType type = new FieldType(getFieldSignature(index));
if (type.isOop()) { if (type.isOop()) {
if (VM.getVM().isCompressedOopsEnabled()) { if (VM.getVM().isCompressedOopsEnabled()) {
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
package sun.jvm.hotspot.runtime;
import java.io.*;
import java.util.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.memory.*;
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.*;
public class vmSymbols {
static {
VM.registerVMInitializedObserver(new Observer() {
public void update(Observable o, Object data) {
initialize(VM.getVM().getTypeDataBase());
}
});
}
private static Address symbolsAddress;
private static int FIRST_SID;
private static int SID_LIMIT;
private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
Type type = db.lookupType("vmSymbols");
symbolsAddress = type.getAddressField("_symbols[0]").getStaticFieldAddress();
FIRST_SID = db.lookupIntConstant("vmSymbols::FIRST_SID");
SID_LIMIT = db.lookupIntConstant("vmSymbols::SID_LIMIT");
}
public static Symbol symbolAt(int id) {
if (id < FIRST_SID || id >= SID_LIMIT) throw new IndexOutOfBoundsException("bad SID " + id);
return Symbol.create(symbolsAddress.getAddressAt(id * VM.getVM().getAddressSize()));
}
}
...@@ -379,23 +379,21 @@ public class ClassWriter implements /* imports */ ClassConstants ...@@ -379,23 +379,21 @@ public class ClassWriter implements /* imports */ ClassConstants
} }
protected void writeFields() throws IOException { protected void writeFields() throws IOException {
TypeArray fields = klass.getFields();
final int length = klass.getJavaFieldsCount(); final int length = klass.getJavaFieldsCount();
// write number of fields // write number of fields
dos.writeShort((short) (length / InstanceKlass.FIELD_SLOTS) ); dos.writeShort((short) length);
if (DEBUG) debugMessage("number of fields = " if (DEBUG) debugMessage("number of fields = " + length);
+ length/InstanceKlass.FIELD_SLOTS);
for (int index = 0; index < length; index += InstanceKlass.FIELD_SLOTS) { for (int index = 0; index < length; index++) {
short accessFlags = fields.getShortAt(index + InstanceKlass.ACCESS_FLAGS_OFFSET); short accessFlags = klass.getFieldAccessFlags(index);
dos.writeShort(accessFlags & (short) JVM_RECOGNIZED_FIELD_MODIFIERS); dos.writeShort(accessFlags & (short) JVM_RECOGNIZED_FIELD_MODIFIERS);
short nameIndex = fields.getShortAt(index + InstanceKlass.NAME_INDEX_OFFSET); short nameIndex = klass.getFieldNameIndex(index);
dos.writeShort(nameIndex); dos.writeShort(nameIndex);
short signatureIndex = fields.getShortAt(index + InstanceKlass.SIGNATURE_INDEX_OFFSET); short signatureIndex = klass.getFieldSignatureIndex(index);
dos.writeShort(signatureIndex); dos.writeShort(signatureIndex);
if (DEBUG) debugMessage("\tfield name = " + nameIndex + ", signature = " + signatureIndex); if (DEBUG) debugMessage("\tfield name = " + nameIndex + ", signature = " + signatureIndex);
...@@ -404,11 +402,11 @@ public class ClassWriter implements /* imports */ ClassConstants ...@@ -404,11 +402,11 @@ public class ClassWriter implements /* imports */ ClassConstants
if (hasSyn) if (hasSyn)
fieldAttributeCount++; fieldAttributeCount++;
short initvalIndex = fields.getShortAt(index + InstanceKlass.INITVAL_INDEX_OFFSET); short initvalIndex = klass.getFieldInitialValueIndex(index);
if (initvalIndex != 0) if (initvalIndex != 0)
fieldAttributeCount++; fieldAttributeCount++;
short genSigIndex = fields.getShortAt(index + InstanceKlass.GENERIC_SIGNATURE_INDEX_OFFSET); short genSigIndex = klass.getFieldGenericSignatureIndex(index);
if (genSigIndex != 0) if (genSigIndex != 0)
fieldAttributeCount++; fieldAttributeCount++;
......
...@@ -968,6 +968,7 @@ ...@@ -968,6 +968,7 @@
class vmSymbols: AllStatic { class vmSymbols: AllStatic {
friend class vmIntrinsics; friend class vmIntrinsics;
friend class VMStructs;
public: public:
// enum for figuring positions and size of array holding Symbol*s // enum for figuring positions and size of array holding Symbol*s
enum SID { enum SID {
......
...@@ -703,6 +703,12 @@ static inline uint64_t cast_uint64_t(size_t x) ...@@ -703,6 +703,12 @@ static inline uint64_t cast_uint64_t(size_t x)
static_field(SystemDictionary, _box_klasses[0], klassOop) \ static_field(SystemDictionary, _box_klasses[0], klassOop) \
static_field(SystemDictionary, _java_system_loader, oop) \ static_field(SystemDictionary, _java_system_loader, oop) \
\ \
/*************/ \
/* vmSymbols */ \
/*************/ \
\
static_field(vmSymbols, _symbols[0], Symbol*) \
\
/*******************/ \ /*******************/ \
/* HashtableBucket */ \ /* HashtableBucket */ \
/*******************/ \ /*******************/ \
...@@ -1548,6 +1554,7 @@ static inline uint64_t cast_uint64_t(size_t x) ...@@ -1548,6 +1554,7 @@ static inline uint64_t cast_uint64_t(size_t x)
declare_type(LoaderConstraintEntry, HashtableEntry<klassOop>) \ declare_type(LoaderConstraintEntry, HashtableEntry<klassOop>) \
declare_toplevel_type(HashtableBucket) \ declare_toplevel_type(HashtableBucket) \
declare_toplevel_type(SystemDictionary) \ declare_toplevel_type(SystemDictionary) \
declare_toplevel_type(vmSymbols) \
declare_toplevel_type(ProtectionDomainEntry) \ declare_toplevel_type(ProtectionDomainEntry) \
\ \
declare_toplevel_type(GenericGrowableArray) \ declare_toplevel_type(GenericGrowableArray) \
...@@ -2530,6 +2537,13 @@ static inline uint64_t cast_uint64_t(size_t x) ...@@ -2530,6 +2537,13 @@ static inline uint64_t cast_uint64_t(size_t x)
X86_ONLY(declare_constant(frame::entry_frame_call_wrapper_offset)) \ X86_ONLY(declare_constant(frame::entry_frame_call_wrapper_offset)) \
declare_constant(frame::pc_return_offset) \ declare_constant(frame::pc_return_offset) \
\ \
/*************/ \
/* vmSymbols */ \
/*************/ \
\
declare_constant(vmSymbols::FIRST_SID) \
declare_constant(vmSymbols::SID_LIMIT) \
\
/********************************/ \ /********************************/ \
/* Calling convention constants */ \ /* Calling convention constants */ \
/********************************/ \ /********************************/ \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册