Mercurial > hg > truffle
comparison agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPoolCache.java @ 6725:da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author | coleenp |
---|---|
date | Sat, 01 Sep 2012 13:25:18 -0400 |
parents | 6a991dcb52bb |
children | bd7a7ce2e264 |
comparison
equal
deleted
inserted
replaced
6724:36d1d483d5d6 | 6725:da91efe96a93 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
29 import sun.jvm.hotspot.debugger.*; | 29 import sun.jvm.hotspot.debugger.*; |
30 import sun.jvm.hotspot.runtime.*; | 30 import sun.jvm.hotspot.runtime.*; |
31 import sun.jvm.hotspot.types.*; | 31 import sun.jvm.hotspot.types.*; |
32 import sun.jvm.hotspot.utilities.*; | 32 import sun.jvm.hotspot.utilities.*; |
33 | 33 |
34 // ConstantPoolCache : A constant pool cache (constantPoolCacheOopDesc). | 34 // ConstantPoolCache : A constant pool cache (ConstantPoolCache). |
35 // See cpCacheOop.hpp for details about this class. | 35 // See cpCache.hpp for details about this class. |
36 // | 36 // |
37 public class ConstantPoolCache extends Oop { | 37 public class ConstantPoolCache extends Metadata { |
38 static { | 38 static { |
39 VM.registerVMInitializedObserver(new Observer() { | 39 VM.registerVMInitializedObserver(new Observer() { |
40 public void update(Observable o, Object data) { | 40 public void update(Observable o, Object data) { |
41 initialize(VM.getVM().getTypeDataBase()); | 41 initialize(VM.getVM().getTypeDataBase()); |
42 } | 42 } |
43 }); | 43 }); |
44 } | 44 } |
45 | 45 |
46 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { | 46 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException { |
47 Type type = db.lookupType("constantPoolCacheOopDesc"); | 47 Type type = db.lookupType("ConstantPoolCache"); |
48 constants = new OopField(type.getOopField("_constant_pool"), 0); | 48 constants = new MetadataField(type.getAddressField("_constant_pool"), 0); |
49 baseOffset = type.getSize(); | 49 baseOffset = type.getSize(); |
50 Type elType = db.lookupType("ConstantPoolCacheEntry"); | 50 Type elType = db.lookupType("ConstantPoolCacheEntry"); |
51 elementSize = elType.getSize(); | 51 elementSize = elType.getSize(); |
52 length = new CIntField(type.getCIntegerField("_length"), 0); | 52 length = new CIntField(type.getCIntegerField("_length"), 0); |
53 intSize = VM.getVM().getObjectHeap().getIntSize(); | |
53 } | 54 } |
54 | 55 |
55 ConstantPoolCache(OopHandle handle, ObjectHeap heap) { | 56 public ConstantPoolCache(Address addr) { |
56 super(handle, heap); | 57 super(addr); |
57 } | 58 } |
58 | 59 |
59 public boolean isConstantPoolCache() { return true; } | 60 public boolean isConstantPoolCache() { return true; } |
60 | 61 |
61 private static OopField constants; | 62 private static MetadataField constants; |
62 | 63 |
63 private static long baseOffset; | 64 private static long baseOffset; |
64 private static long elementSize; | 65 private static long elementSize; |
65 private static CIntField length; | 66 private static CIntField length; |
67 private static long intSize; | |
66 | 68 |
67 | 69 |
68 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); } | 70 public ConstantPool getConstants() { return (ConstantPool) constants.getValue(this); } |
69 | 71 |
70 public long getObjectSize() { | 72 public long getSize() { |
71 return alignObjectSize(baseOffset + getLength() * elementSize); | 73 return Oop.alignObjectSize(baseOffset + getLength() * elementSize); |
72 } | 74 } |
73 | 75 |
74 public ConstantPoolCacheEntry getEntryAt(int i) { | 76 public ConstantPoolCacheEntry getEntryAt(int i) { |
75 if (i < 0 || i >= getLength()) throw new IndexOutOfBoundsException(i + " " + getLength()); | 77 if (i < 0 || i >= getLength()) throw new IndexOutOfBoundsException(i + " " + getLength()); |
76 return new ConstantPoolCacheEntry(this, i); | 78 return new ConstantPoolCacheEntry(this, i); |
77 } | 79 } |
78 | 80 |
79 public static boolean isSecondaryIndex(int i) { return (i < 0); } | |
80 public static int decodeSecondaryIndex(int i) { return isSecondaryIndex(i) ? ~i : i; } | |
81 public static int encodeSecondaryIndex(int i) { return !isSecondaryIndex(i) ? ~i : i; } | |
82 | |
83 // secondary entries hold invokedynamic call site bindings | |
84 public ConstantPoolCacheEntry getSecondaryEntryAt(int i) { | |
85 int rawIndex = i; | |
86 if (isSecondaryIndex(i)) { | |
87 rawIndex = decodeSecondaryIndex(i); | |
88 } | |
89 ConstantPoolCacheEntry e = getEntryAt(rawIndex); | |
90 if (Assert.ASSERTS_ENABLED) { | |
91 Assert.that(e.isSecondaryEntry(), "must be a secondary entry:" + rawIndex); | |
92 } | |
93 return e; | |
94 } | |
95 | |
96 public ConstantPoolCacheEntry getMainEntryAt(int i) { | |
97 int primaryIndex = i; | |
98 if (isSecondaryIndex(i)) { | |
99 // run through an extra level of indirection: | |
100 int rawIndex = decodeSecondaryIndex(i); | |
101 primaryIndex = getEntryAt(rawIndex).getMainEntryIndex(); | |
102 } | |
103 ConstantPoolCacheEntry e = getEntryAt(primaryIndex); | |
104 if (Assert.ASSERTS_ENABLED) { | |
105 Assert.that(!e.isSecondaryEntry(), "must not be a secondary entry:" + primaryIndex); | |
106 } | |
107 return e; | |
108 } | |
109 | |
110 public int getIntAt(int entry, int fld) { | 81 public int getIntAt(int entry, int fld) { |
111 //alignObjectSize ? | 82 //alignObjectSize ? |
112 long offset = baseOffset + /*alignObjectSize*/entry * elementSize + fld* getHeap().getIntSize(); | 83 long offset = baseOffset + /*alignObjectSize*/entry * elementSize + fld * intSize; |
113 return (int) getHandle().getCIntegerAt(offset, getHeap().getIntSize(), true ); | 84 return (int) getAddress().getCIntegerAt(offset, intSize, true ); |
114 } | 85 } |
115 | 86 |
116 | 87 |
117 public void printValueOn(PrintStream tty) { | 88 public void printValueOn(PrintStream tty) { |
118 tty.print("ConstantPoolCache for " + getConstants().getPoolHolder().getName().asString()); | 89 tty.print("ConstantPoolCache for " + getConstants().getPoolHolder().getName().asString()); |
119 } | 90 } |
120 | 91 |
121 public int getLength() { | 92 public int getLength() { |
122 return (int) length.getValue(this); | 93 return (int) length.getValue(getAddress()); |
123 } | 94 } |
124 | 95 |
125 public void iterateFields(OopVisitor visitor, boolean doVMFields) { | 96 public void iterateFields(MetadataVisitor visitor) { |
126 super.iterateFields(visitor, doVMFields); | 97 super.iterateFields(visitor); |
127 if (doVMFields) { | 98 visitor.doMetadata(constants, true); |
128 visitor.doOop(constants, true); | |
129 for (int i = 0; i < getLength(); i++) { | 99 for (int i = 0; i < getLength(); i++) { |
130 ConstantPoolCacheEntry entry = getEntryAt(i); | 100 ConstantPoolCacheEntry entry = getEntryAt(i); |
131 entry.iterateFields(visitor); | 101 entry.iterateFields(visitor); |
132 } | 102 } |
133 } | 103 } |
134 } | |
135 }; | 104 }; |