Fri, 02 Nov 2012 17:18:16 -0700
Merge
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/classfile/bytecodeAssembler.cpp Fri Nov 02 17:18:16 2012 -0700 1.3 @@ -0,0 +1,269 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 + 1.30 +#include "classfile/bytecodeAssembler.hpp" 1.31 +#include "interpreter/bytecodes.hpp" 1.32 +#include "memory/oopFactory.hpp" 1.33 +#include "oops/constantPool.hpp" 1.34 + 1.35 +#ifdef TARGET_ARCH_x86 1.36 +# include "bytes_x86.hpp" 1.37 +#endif 1.38 +#ifdef TARGET_ARCH_sparc 1.39 +# include "bytes_sparc.hpp" 1.40 +#endif 1.41 +#ifdef TARGET_ARCH_zero 1.42 +# include "bytes_zero.hpp" 1.43 +#endif 1.44 +#ifdef TARGET_ARCH_arm 1.45 +# include "bytes_arm.hpp" 1.46 +#endif 1.47 +#ifdef TARGET_ARCH_ppc 1.48 +# include "bytes_ppc.hpp" 1.49 +#endif 1.50 + 1.51 +u2 BytecodeConstantPool::find_or_add(BytecodeCPEntry const& bcpe) { 1.52 + u2 index; 1.53 + u2* probe = _indices.get(bcpe); 1.54 + if (probe == NULL) { 1.55 + index = _entries.length(); 1.56 + _entries.append(bcpe); 1.57 + _indices.put(bcpe, index); 1.58 + } else { 1.59 + index = *probe; 1.60 + } 1.61 + return index + _orig->length(); 1.62 +} 1.63 + 1.64 +ConstantPool* BytecodeConstantPool::create_constant_pool(TRAPS) const { 1.65 + if (_entries.length() == 0) { 1.66 + return _orig; 1.67 + } 1.68 + 1.69 + ConstantPool* cp = ConstantPool::allocate( 1.70 + _orig->pool_holder()->class_loader_data(), 1.71 + _orig->length() + _entries.length(), CHECK_NULL); 1.72 + 1.73 + cp->set_pool_holder(_orig->pool_holder()); 1.74 + _orig->copy_cp_to(1, _orig->length() - 1, cp, 1, CHECK_NULL); 1.75 + 1.76 + for (int i = 0; i < _entries.length(); ++i) { 1.77 + BytecodeCPEntry entry = _entries.at(i); 1.78 + int idx = i + _orig->length(); 1.79 + switch (entry._tag) { 1.80 + case BytecodeCPEntry::UTF8: 1.81 + cp->symbol_at_put(idx, entry._u.utf8); 1.82 + entry._u.utf8->increment_refcount(); 1.83 + break; 1.84 + case BytecodeCPEntry::KLASS: 1.85 + cp->unresolved_klass_at_put( 1.86 + idx, cp->symbol_at(entry._u.klass)); 1.87 + break; 1.88 + case BytecodeCPEntry::STRING: 1.89 + cp->unresolved_string_at_put( 1.90 + idx, cp->symbol_at(entry._u.string)); 1.91 + break; 1.92 + case BytecodeCPEntry::NAME_AND_TYPE: 1.93 + cp->name_and_type_at_put(idx, 1.94 + entry._u.name_and_type.name_index, 1.95 + entry._u.name_and_type.type_index); 1.96 + break; 1.97 + case BytecodeCPEntry::METHODREF: 1.98 + cp->method_at_put(idx, 1.99 + entry._u.methodref.class_index, 1.100 + entry._u.methodref.name_and_type_index); 1.101 + break; 1.102 + default: 1.103 + ShouldNotReachHere(); 1.104 + } 1.105 + } 1.106 + return cp; 1.107 +} 1.108 + 1.109 +void BytecodeAssembler::append(u1 imm_u1) { 1.110 + _code->append(imm_u1); 1.111 +} 1.112 + 1.113 +void BytecodeAssembler::append(u2 imm_u2) { 1.114 + _code->append(0); 1.115 + _code->append(0); 1.116 + Bytes::put_Java_u2(_code->adr_at(_code->length() - 2), imm_u2); 1.117 +} 1.118 + 1.119 +void BytecodeAssembler::append(u4 imm_u4) { 1.120 + _code->append(0); 1.121 + _code->append(0); 1.122 + _code->append(0); 1.123 + _code->append(0); 1.124 + Bytes::put_Java_u4(_code->adr_at(_code->length() - 4), imm_u4); 1.125 +} 1.126 + 1.127 +void BytecodeAssembler::xload(u4 index, u1 onebyteop, u1 twobyteop) { 1.128 + if (index < 4) { 1.129 + _code->append(onebyteop + index); 1.130 + } else { 1.131 + _code->append(twobyteop); 1.132 + _code->append((u2)index); 1.133 + } 1.134 +} 1.135 + 1.136 +void BytecodeAssembler::dup() { 1.137 + _code->append(Bytecodes::_dup); 1.138 +} 1.139 + 1.140 +void BytecodeAssembler::_new(Symbol* sym) { 1.141 + u2 cpool_index = _cp->klass(sym); 1.142 + _code->append(Bytecodes::_new); 1.143 + append(cpool_index); 1.144 +} 1.145 + 1.146 +void BytecodeAssembler::load_string(Symbol* sym) { 1.147 + u2 cpool_index = _cp->string(sym); 1.148 + if (cpool_index < 0x100) { 1.149 + ldc(cpool_index); 1.150 + } else { 1.151 + ldc_w(cpool_index); 1.152 + } 1.153 +} 1.154 + 1.155 +void BytecodeAssembler::ldc(u1 index) { 1.156 + _code->append(Bytecodes::_ldc); 1.157 + append(index); 1.158 +} 1.159 + 1.160 +void BytecodeAssembler::ldc_w(u2 index) { 1.161 + _code->append(Bytecodes::_ldc_w); 1.162 + append(index); 1.163 +} 1.164 + 1.165 +void BytecodeAssembler::athrow() { 1.166 + _code->append(Bytecodes::_athrow); 1.167 +} 1.168 + 1.169 +void BytecodeAssembler::iload(u4 index) { 1.170 + xload(index, Bytecodes::_iload_0, Bytecodes::_iload); 1.171 +} 1.172 + 1.173 +void BytecodeAssembler::lload(u4 index) { 1.174 + xload(index, Bytecodes::_lload_0, Bytecodes::_lload); 1.175 +} 1.176 + 1.177 +void BytecodeAssembler::fload(u4 index) { 1.178 + xload(index, Bytecodes::_fload_0, Bytecodes::_fload); 1.179 +} 1.180 + 1.181 +void BytecodeAssembler::dload(u4 index) { 1.182 + xload(index, Bytecodes::_dload_0, Bytecodes::_dload); 1.183 +} 1.184 + 1.185 +void BytecodeAssembler::aload(u4 index) { 1.186 + xload(index, Bytecodes::_aload_0, Bytecodes::_aload); 1.187 +} 1.188 + 1.189 +void BytecodeAssembler::load(BasicType bt, u4 index) { 1.190 + switch (bt) { 1.191 + case T_BOOLEAN: 1.192 + case T_CHAR: 1.193 + case T_BYTE: 1.194 + case T_SHORT: 1.195 + case T_INT: iload(index); break; 1.196 + case T_FLOAT: fload(index); break; 1.197 + case T_DOUBLE: dload(index); break; 1.198 + case T_LONG: lload(index); break; 1.199 + case T_OBJECT: 1.200 + case T_ARRAY: aload(index); break; 1.201 + default: 1.202 + ShouldNotReachHere(); 1.203 + } 1.204 +} 1.205 + 1.206 +void BytecodeAssembler::checkcast(Symbol* sym) { 1.207 + u2 cpool_index = _cp->klass(sym); 1.208 + _code->append(Bytecodes::_checkcast); 1.209 + append(cpool_index); 1.210 +} 1.211 + 1.212 +void BytecodeAssembler::invokespecial(Method* method) { 1.213 + invokespecial(method->klass_name(), method->name(), method->signature()); 1.214 +} 1.215 + 1.216 +void BytecodeAssembler::invokespecial(Symbol* klss, Symbol* name, Symbol* sig) { 1.217 + u2 methodref_index = _cp->methodref(klss, name, sig); 1.218 + _code->append(Bytecodes::_invokespecial); 1.219 + append(methodref_index); 1.220 +} 1.221 + 1.222 +void BytecodeAssembler::invokevirtual(Method* method) { 1.223 + invokevirtual(method->klass_name(), method->name(), method->signature()); 1.224 +} 1.225 + 1.226 +void BytecodeAssembler::invokevirtual(Symbol* klss, Symbol* name, Symbol* sig) { 1.227 + u2 methodref_index = _cp->methodref(klss, name, sig); 1.228 + _code->append(Bytecodes::_invokevirtual); 1.229 + append(methodref_index); 1.230 +} 1.231 + 1.232 +void BytecodeAssembler::ireturn() { 1.233 + _code->append(Bytecodes::_ireturn); 1.234 +} 1.235 + 1.236 +void BytecodeAssembler::lreturn() { 1.237 + _code->append(Bytecodes::_lreturn); 1.238 +} 1.239 + 1.240 +void BytecodeAssembler::freturn() { 1.241 + _code->append(Bytecodes::_freturn); 1.242 +} 1.243 + 1.244 +void BytecodeAssembler::dreturn() { 1.245 + _code->append(Bytecodes::_dreturn); 1.246 +} 1.247 + 1.248 +void BytecodeAssembler::areturn() { 1.249 + _code->append(Bytecodes::_areturn); 1.250 +} 1.251 + 1.252 +void BytecodeAssembler::_return() { 1.253 + _code->append(Bytecodes::_return); 1.254 +} 1.255 + 1.256 +void BytecodeAssembler::_return(BasicType bt) { 1.257 + switch (bt) { 1.258 + case T_BOOLEAN: 1.259 + case T_CHAR: 1.260 + case T_BYTE: 1.261 + case T_SHORT: 1.262 + case T_INT: ireturn(); break; 1.263 + case T_FLOAT: freturn(); break; 1.264 + case T_DOUBLE: dreturn(); break; 1.265 + case T_LONG: lreturn(); break; 1.266 + case T_OBJECT: 1.267 + case T_ARRAY: areturn(); break; 1.268 + case T_VOID: _return(); break; 1.269 + default: 1.270 + ShouldNotReachHere(); 1.271 + } 1.272 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/src/share/vm/classfile/bytecodeAssembler.hpp Fri Nov 02 17:18:16 2012 -0700 2.3 @@ -0,0 +1,214 @@ 2.4 +/* 2.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + * 2.26 + */ 2.27 + 2.28 +#ifndef SHARE_VM_CLASSFILE_BYTECODEASSEMBLER_HPP 2.29 +#define SHARE_VM_CLASSFILE_BYTECODEASSEMBLER_HPP 2.30 + 2.31 +#include "memory/allocation.hpp" 2.32 +#include "oops/method.hpp" 2.33 +#include "oops/symbol.hpp" 2.34 +#include "utilities/globalDefinitions.hpp" 2.35 +#include "utilities/growableArray.hpp" 2.36 +#include "utilities/resourceHash.hpp" 2.37 + 2.38 + 2.39 +/** 2.40 + * Bytecode Assembler 2.41 + * 2.42 + * These classes are used to synthesize code for creating new methods from 2.43 + * within the VM. This is only a partial implementation of an assembler; 2.44 + * only the bytecodes that are needed by clients are implemented at this time. 2.45 + * This is used during default method analysis to create overpass methods 2.46 + * and add them to a call during parsing. Other uses (such as creating 2.47 + * bridges) may come later. Any missing bytecodes can be implemented on an 2.48 + * as-need basis. 2.49 + */ 2.50 + 2.51 +class BytecodeBuffer : public GrowableArray<u1> { 2.52 + public: 2.53 + BytecodeBuffer() : GrowableArray<u1>(20) {} 2.54 +}; 2.55 + 2.56 +// Entries in a yet-to-be-created constant pool. Limited types for now. 2.57 +class BytecodeCPEntry VALUE_OBJ_CLASS_SPEC { 2.58 + public: 2.59 + enum tag { 2.60 + ERROR_TAG, 2.61 + UTF8, 2.62 + KLASS, 2.63 + STRING, 2.64 + NAME_AND_TYPE, 2.65 + METHODREF 2.66 + }; 2.67 + 2.68 + u1 _tag; 2.69 + union { 2.70 + Symbol* utf8; 2.71 + u2 klass; 2.72 + u2 string; 2.73 + struct { 2.74 + u2 name_index; 2.75 + u2 type_index; 2.76 + } name_and_type; 2.77 + struct { 2.78 + u2 class_index; 2.79 + u2 name_and_type_index; 2.80 + } methodref; 2.81 + uintptr_t hash; 2.82 + } _u; 2.83 + 2.84 + BytecodeCPEntry() : _tag(ERROR_TAG) { _u.hash = 0; } 2.85 + BytecodeCPEntry(u1 tag) : _tag(tag) { _u.hash = 0; } 2.86 + 2.87 + static BytecodeCPEntry utf8(Symbol* symbol) { 2.88 + BytecodeCPEntry bcpe(UTF8); 2.89 + bcpe._u.utf8 = symbol; 2.90 + return bcpe; 2.91 + } 2.92 + 2.93 + static BytecodeCPEntry klass(u2 index) { 2.94 + BytecodeCPEntry bcpe(KLASS); 2.95 + bcpe._u.klass = index; 2.96 + return bcpe; 2.97 + } 2.98 + 2.99 + static BytecodeCPEntry string(u2 index) { 2.100 + BytecodeCPEntry bcpe(STRING); 2.101 + bcpe._u.string = index; 2.102 + return bcpe; 2.103 + } 2.104 + 2.105 + static BytecodeCPEntry name_and_type(u2 name, u2 type) { 2.106 + BytecodeCPEntry bcpe(NAME_AND_TYPE); 2.107 + bcpe._u.name_and_type.name_index = name; 2.108 + bcpe._u.name_and_type.type_index = type; 2.109 + return bcpe; 2.110 + } 2.111 + 2.112 + static BytecodeCPEntry methodref(u2 class_index, u2 nat) { 2.113 + BytecodeCPEntry bcpe(METHODREF); 2.114 + bcpe._u.methodref.class_index = class_index; 2.115 + bcpe._u.methodref.name_and_type_index = nat; 2.116 + return bcpe; 2.117 + } 2.118 + 2.119 + static bool equals(BytecodeCPEntry const& e0, BytecodeCPEntry const& e1) { 2.120 + return e0._tag == e1._tag && e0._u.hash == e1._u.hash; 2.121 + } 2.122 + 2.123 + static unsigned hash(BytecodeCPEntry const& e0) { 2.124 + return (unsigned)(e0._tag ^ e0._u.hash); 2.125 + } 2.126 +}; 2.127 + 2.128 +class BytecodeConstantPool : ResourceObj { 2.129 + private: 2.130 + typedef ResourceHashtable<BytecodeCPEntry, u2, 2.131 + &BytecodeCPEntry::hash, &BytecodeCPEntry::equals> IndexHash; 2.132 + 2.133 + ConstantPool* _orig; 2.134 + GrowableArray<BytecodeCPEntry> _entries; 2.135 + IndexHash _indices; 2.136 + 2.137 + u2 find_or_add(BytecodeCPEntry const& bcpe); 2.138 + 2.139 + public: 2.140 + 2.141 + BytecodeConstantPool(ConstantPool* orig) : _orig(orig) {} 2.142 + 2.143 + BytecodeCPEntry const& at(u2 index) const { return _entries.at(index); } 2.144 + 2.145 + InstanceKlass* pool_holder() const { 2.146 + return InstanceKlass::cast(_orig->pool_holder()); 2.147 + } 2.148 + 2.149 + u2 utf8(Symbol* sym) { 2.150 + return find_or_add(BytecodeCPEntry::utf8(sym)); 2.151 + } 2.152 + 2.153 + u2 klass(Symbol* class_name) { 2.154 + return find_or_add(BytecodeCPEntry::klass(utf8(class_name))); 2.155 + } 2.156 + 2.157 + u2 string(Symbol* str) { 2.158 + return find_or_add(BytecodeCPEntry::string(utf8(str))); 2.159 + } 2.160 + 2.161 + u2 name_and_type(Symbol* name, Symbol* sig) { 2.162 + return find_or_add(BytecodeCPEntry::name_and_type(utf8(name), utf8(sig))); 2.163 + } 2.164 + 2.165 + u2 methodref(Symbol* class_name, Symbol* name, Symbol* sig) { 2.166 + return find_or_add(BytecodeCPEntry::methodref( 2.167 + klass(class_name), name_and_type(name, sig))); 2.168 + } 2.169 + 2.170 + ConstantPool* create_constant_pool(TRAPS) const; 2.171 +}; 2.172 + 2.173 +// Partial bytecode assembler - only what we need for creating 2.174 +// overpass methods for default methods is implemented 2.175 +class BytecodeAssembler : StackObj { 2.176 + private: 2.177 + BytecodeBuffer* _code; 2.178 + BytecodeConstantPool* _cp; 2.179 + 2.180 + void append(u1 imm_u1); 2.181 + void append(u2 imm_u2); 2.182 + void append(u4 imm_u4); 2.183 + 2.184 + void xload(u4 index, u1 quick, u1 twobyte); 2.185 + 2.186 + public: 2.187 + BytecodeAssembler(BytecodeBuffer* buffer, BytecodeConstantPool* cp) 2.188 + : _code(buffer), _cp(cp) {} 2.189 + 2.190 + void aload(u4 index); 2.191 + void areturn(); 2.192 + void athrow(); 2.193 + void checkcast(Symbol* sym); 2.194 + void dload(u4 index); 2.195 + void dreturn(); 2.196 + void dup(); 2.197 + void fload(u4 index); 2.198 + void freturn(); 2.199 + void iload(u4 index); 2.200 + void invokespecial(Method* method); 2.201 + void invokespecial(Symbol* cls, Symbol* name, Symbol* sig); 2.202 + void invokevirtual(Method* method); 2.203 + void invokevirtual(Symbol* cls, Symbol* name, Symbol* sig); 2.204 + void ireturn(); 2.205 + void ldc(u1 index); 2.206 + void ldc_w(u2 index); 2.207 + void lload(u4 index); 2.208 + void lreturn(); 2.209 + void _new(Symbol* sym); 2.210 + void _return(); 2.211 + 2.212 + void load_string(Symbol* sym); 2.213 + void load(BasicType bt, u4 index); 2.214 + void _return(BasicType bt); 2.215 +}; 2.216 + 2.217 +#endif // SHARE_VM_CLASSFILE_BYTECODEASSEMBLER_HPP
3.1 --- a/src/share/vm/classfile/classFileParser.cpp Fri Nov 02 13:30:47 2012 -0700 3.2 +++ b/src/share/vm/classfile/classFileParser.cpp Fri Nov 02 17:18:16 2012 -0700 3.3 @@ -27,6 +27,8 @@ 3.4 #include "classfile/classLoader.hpp" 3.5 #include "classfile/classLoaderData.hpp" 3.6 #include "classfile/classLoaderData.inline.hpp" 3.7 +#include "classfile/defaultMethods.hpp" 3.8 +#include "classfile/genericSignatures.hpp" 3.9 #include "classfile/javaClasses.hpp" 3.10 #include "classfile/symbolTable.hpp" 3.11 #include "classfile/systemDictionary.hpp" 3.12 @@ -84,6 +86,9 @@ 3.13 // - to check NameAndType_info signatures more aggressively 3.14 #define JAVA_7_VERSION 51 3.15 3.16 +// Extension method support. 3.17 +#define JAVA_8_VERSION 52 3.18 + 3.19 3.20 void ClassFileParser::parse_constant_pool_entries(ClassLoaderData* loader_data, constantPoolHandle cp, int length, TRAPS) { 3.21 // Use a local copy of ClassFileStream. It helps the C++ compiler to optimize 3.22 @@ -785,6 +790,7 @@ 3.23 ClassLoaderData* loader_data, 3.24 Handle protection_domain, 3.25 Symbol* class_name, 3.26 + bool* has_default_methods, 3.27 TRAPS) { 3.28 ClassFileStream* cfs = stream(); 3.29 assert(length > 0, "only called for length>0"); 3.30 @@ -821,6 +827,9 @@ 3.31 if (!Klass::cast(interf())->is_interface()) { 3.32 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(), "Implementing class", NULL); 3.33 } 3.34 + if (InstanceKlass::cast(interf())->has_default_methods()) { 3.35 + *has_default_methods = true; 3.36 + } 3.37 interfaces->at_put(index, interf()); 3.38 } 3.39 3.40 @@ -1928,7 +1937,8 @@ 3.41 if (method_attribute_name == vmSymbols::tag_code()) { 3.42 // Parse Code attribute 3.43 if (_need_verify) { 3.44 - guarantee_property(!access_flags.is_native() && !access_flags.is_abstract(), 3.45 + guarantee_property( 3.46 + !access_flags.is_native() && !access_flags.is_abstract(), 3.47 "Code attribute in native or abstract methods in class file %s", 3.48 CHECK_(nullHandle)); 3.49 } 3.50 @@ -2125,7 +2135,9 @@ 3.51 runtime_visible_annotations_length = method_attribute_length; 3.52 runtime_visible_annotations = cfs->get_u1_buffer(); 3.53 assert(runtime_visible_annotations != NULL, "null visible annotations"); 3.54 - parse_annotations(runtime_visible_annotations, runtime_visible_annotations_length, cp, &parsed_annotations, CHECK_(nullHandle)); 3.55 + parse_annotations(runtime_visible_annotations, 3.56 + runtime_visible_annotations_length, cp, &parsed_annotations, 3.57 + CHECK_(nullHandle)); 3.58 cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle)); 3.59 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { 3.60 runtime_invisible_annotations_length = method_attribute_length; 3.61 @@ -2169,12 +2181,10 @@ 3.62 } 3.63 3.64 // All sizing information for a Method* is finally available, now create it 3.65 - Method* m = Method::allocate(loader_data, code_length, access_flags, 3.66 - linenumber_table_length, 3.67 - total_lvt_length, 3.68 - exception_table_length, 3.69 - checked_exceptions_length, 3.70 - CHECK_(nullHandle)); 3.71 + Method* m = Method::allocate( 3.72 + loader_data, code_length, access_flags, linenumber_table_length, 3.73 + total_lvt_length, exception_table_length, checked_exceptions_length, 3.74 + ConstMethod::NORMAL, CHECK_(nullHandle)); 3.75 3.76 ClassLoadingService::add_class_method_size(m->size()*HeapWordSize); 3.77 3.78 @@ -2204,7 +2214,6 @@ 3.79 // Fill in code attribute information 3.80 m->set_max_stack(max_stack); 3.81 m->set_max_locals(max_locals); 3.82 - 3.83 m->constMethod()->set_stackmap_data(stackmap_data); 3.84 3.85 // Copy byte codes 3.86 @@ -2356,6 +2365,7 @@ 3.87 Array<AnnotationArray*>** methods_annotations, 3.88 Array<AnnotationArray*>** methods_parameter_annotations, 3.89 Array<AnnotationArray*>** methods_default_annotations, 3.90 + bool* has_default_methods, 3.91 TRAPS) { 3.92 ClassFileStream* cfs = stream(); 3.93 AnnotationArray* method_annotations = NULL; 3.94 @@ -2382,6 +2392,10 @@ 3.95 if (method->is_final()) { 3.96 *has_final_method = true; 3.97 } 3.98 + if (is_interface && !method->is_abstract() && !method->is_static()) { 3.99 + // default method 3.100 + *has_default_methods = true; 3.101 + } 3.102 methods->at_put(index, method()); 3.103 if (*methods_annotations == NULL) { 3.104 *methods_annotations = 3.105 @@ -2907,6 +2921,34 @@ 3.106 } 3.107 3.108 3.109 +#ifndef PRODUCT 3.110 +static void parseAndPrintGenericSignatures( 3.111 + instanceKlassHandle this_klass, TRAPS) { 3.112 + assert(ParseAllGenericSignatures == true, "Shouldn't call otherwise"); 3.113 + ResourceMark rm; 3.114 + 3.115 + if (this_klass->generic_signature() != NULL) { 3.116 + using namespace generic; 3.117 + ClassDescriptor* spec = ClassDescriptor::parse_generic_signature(this_klass(), CHECK); 3.118 + 3.119 + tty->print_cr("Parsing %s", this_klass->generic_signature()->as_C_string()); 3.120 + spec->print_on(tty); 3.121 + 3.122 + for (int i = 0; i < this_klass->methods()->length(); ++i) { 3.123 + Method* m = this_klass->methods()->at(i); 3.124 + MethodDescriptor* method_spec = MethodDescriptor::parse_generic_signature(m, spec); 3.125 + Symbol* sig = m->generic_signature(); 3.126 + if (sig == NULL) { 3.127 + sig = m->signature(); 3.128 + } 3.129 + tty->print_cr("Parsing %s", sig->as_C_string()); 3.130 + method_spec->print_on(tty); 3.131 + } 3.132 + } 3.133 +} 3.134 +#endif // ndef PRODUCT 3.135 + 3.136 + 3.137 instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name, 3.138 Handle class_loader, 3.139 Handle protection_domain, 3.140 @@ -2923,6 +2965,8 @@ 3.141 unsigned char *cached_class_file_bytes = NULL; 3.142 jint cached_class_file_length; 3.143 ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader()); 3.144 + bool has_default_methods = false; 3.145 + ResourceMark rm(THREAD); 3.146 3.147 ClassFileStream* cfs = stream(); 3.148 // Timing 3.149 @@ -3138,7 +3182,9 @@ 3.150 if (itfs_len == 0) { 3.151 local_interfaces = Universe::the_empty_klass_array(); 3.152 } else { 3.153 - local_interfaces = parse_interfaces(cp, itfs_len, loader_data, protection_domain, _class_name, CHECK_(nullHandle)); 3.154 + local_interfaces = parse_interfaces( 3.155 + cp, itfs_len, loader_data, protection_domain, _class_name, 3.156 + &has_default_methods, CHECK_(nullHandle)); 3.157 } 3.158 3.159 u2 java_fields_count = 0; 3.160 @@ -3164,6 +3210,7 @@ 3.161 &methods_annotations, 3.162 &methods_parameter_annotations, 3.163 &methods_default_annotations, 3.164 + &has_default_methods, 3.165 CHECK_(nullHandle)); 3.166 3.167 // Additional attributes 3.168 @@ -3193,6 +3240,11 @@ 3.169 super_klass = instanceKlassHandle(THREAD, kh()); 3.170 } 3.171 if (super_klass.not_null()) { 3.172 + 3.173 + if (super_klass->has_default_methods()) { 3.174 + has_default_methods = true; 3.175 + } 3.176 + 3.177 if (super_klass->is_interface()) { 3.178 ResourceMark rm(THREAD); 3.179 Exceptions::fthrow( 3.180 @@ -3229,14 +3281,11 @@ 3.181 int itable_size = 0; 3.182 int num_miranda_methods = 0; 3.183 3.184 - klassVtable::compute_vtable_size_and_num_mirandas(vtable_size, 3.185 - num_miranda_methods, 3.186 - super_klass(), 3.187 - methods, 3.188 - access_flags, 3.189 - class_loader, 3.190 - class_name, 3.191 - local_interfaces, 3.192 + GrowableArray<Method*> all_mirandas(20); 3.193 + 3.194 + klassVtable::compute_vtable_size_and_num_mirandas( 3.195 + &vtable_size, &num_miranda_methods, &all_mirandas, super_klass(), methods, 3.196 + access_flags, class_loader, class_name, local_interfaces, 3.197 CHECK_(nullHandle)); 3.198 3.199 // Size of Java itable (in words) 3.200 @@ -3656,6 +3705,7 @@ 3.201 3.202 this_klass->set_minor_version(minor_version); 3.203 this_klass->set_major_version(major_version); 3.204 + this_klass->set_has_default_methods(has_default_methods); 3.205 3.206 // Set up Method*::intrinsic_id as soon as we know the names of methods. 3.207 // (We used to do this lazily, but now we query it in Rewriter, 3.208 @@ -3673,6 +3723,16 @@ 3.209 cached_class_file_length); 3.210 } 3.211 3.212 + // Fill in field values obtained by parse_classfile_attributes 3.213 + if (parsed_annotations.has_any_annotations()) 3.214 + parsed_annotations.apply_to(this_klass); 3.215 + // Create annotations 3.216 + if (_annotations != NULL && this_klass->annotations() == NULL) { 3.217 + Annotations* anno = Annotations::allocate(loader_data, CHECK_NULL); 3.218 + this_klass->set_annotations(anno); 3.219 + } 3.220 + apply_parsed_class_attributes(this_klass); 3.221 + 3.222 // Miranda methods 3.223 if ((num_miranda_methods > 0) || 3.224 // if this class introduced new miranda methods or 3.225 @@ -3682,18 +3742,6 @@ 3.226 this_klass->set_has_miranda_methods(); // then set a flag 3.227 } 3.228 3.229 - // Fill in field values obtained by parse_classfile_attributes 3.230 - if (parsed_annotations.has_any_annotations()) { 3.231 - parsed_annotations.apply_to(this_klass); 3.232 - } 3.233 - // Create annotations 3.234 - if (_annotations != NULL && this_klass->annotations() == NULL) { 3.235 - Annotations* anno = Annotations::allocate(loader_data, CHECK_NULL); 3.236 - this_klass->set_annotations(anno); 3.237 - } 3.238 - apply_parsed_class_attributes(this_klass); 3.239 - 3.240 - // Compute transitive closure of interfaces this class implements 3.241 this_klass->set_transitive_interfaces(transitive_interfaces); 3.242 3.243 // Fill in information needed to compute superclasses. 3.244 @@ -3702,6 +3750,7 @@ 3.245 // Initialize itable offset tables 3.246 klassItable::setup_itable_offset_table(this_klass); 3.247 3.248 + // Compute transitive closure of interfaces this class implements 3.249 // Do final class setup 3.250 fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts); 3.251 3.252 @@ -3726,6 +3775,21 @@ 3.253 check_illegal_static_method(this_klass, CHECK_(nullHandle)); 3.254 } 3.255 3.256 + 3.257 +#ifdef ASSERT 3.258 + if (ParseAllGenericSignatures) { 3.259 + parseAndPrintGenericSignatures(this_klass, CHECK_(nullHandle)); 3.260 + } 3.261 +#endif 3.262 + 3.263 + // Generate any default methods - default methods are interface methods 3.264 + // that have a default implementation. This is new with Lambda project. 3.265 + if (has_default_methods && !access_flags.is_interface() && 3.266 + local_interfaces->length() > 0) { 3.267 + DefaultMethods::generate_default_methods( 3.268 + this_klass(), &all_mirandas, CHECK_(nullHandle)); 3.269 + } 3.270 + 3.271 // Allocate mirror and initialize static fields 3.272 java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle)); 3.273 3.274 @@ -3744,6 +3808,7 @@ 3.275 false /* not shared class */); 3.276 3.277 if (TraceClassLoading) { 3.278 + ResourceMark rm; 3.279 // print in a single call to reduce interleaving of output 3.280 if (cfs->source() != NULL) { 3.281 tty->print("[Loaded %s from %s]\n", this_klass->external_name(), 3.282 @@ -3758,13 +3823,13 @@ 3.283 tty->print("[Loaded %s]\n", this_klass->external_name()); 3.284 } 3.285 } else { 3.286 - ResourceMark rm; 3.287 tty->print("[Loaded %s from %s]\n", this_klass->external_name(), 3.288 InstanceKlass::cast(class_loader->klass())->external_name()); 3.289 } 3.290 } 3.291 3.292 if (TraceClassResolution) { 3.293 + ResourceMark rm; 3.294 // print out the superclass. 3.295 const char * from = Klass::cast(this_klass())->external_name(); 3.296 if (this_klass->java_super() != NULL) { 3.297 @@ -3785,6 +3850,7 @@ 3.298 3.299 #ifndef PRODUCT 3.300 if( PrintCompactFieldsSavings ) { 3.301 + ResourceMark rm; 3.302 if( nonstatic_field_size < orig_nonstatic_field_size ) { 3.303 tty->print("[Saved %d of %d bytes in %s]\n", 3.304 (orig_nonstatic_field_size - nonstatic_field_size)*heapOopSize, 3.305 @@ -3811,7 +3877,6 @@ 3.306 return this_klass; 3.307 } 3.308 3.309 - 3.310 unsigned int 3.311 ClassFileParser::compute_oop_map_count(instanceKlassHandle super, 3.312 unsigned int nonstatic_oop_map_count, 3.313 @@ -4263,13 +4328,16 @@ 3.314 const bool is_strict = (flags & JVM_ACC_STRICT) != 0; 3.315 const bool is_synchronized = (flags & JVM_ACC_SYNCHRONIZED) != 0; 3.316 const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION; 3.317 + const bool major_gte_8 = _major_version >= JAVA_8_VERSION; 3.318 const bool is_initializer = (name == vmSymbols::object_initializer_name()); 3.319 3.320 bool is_illegal = false; 3.321 3.322 if (is_interface) { 3.323 - if (!is_abstract || !is_public || is_static || is_final || 3.324 - is_native || (major_gte_15 && (is_synchronized || is_strict))) { 3.325 + if (!is_public || is_static || is_final || is_native || 3.326 + ((is_synchronized || is_strict) && major_gte_15 && 3.327 + (!major_gte_8 || is_abstract)) || 3.328 + (!major_gte_8 && !is_abstract)) { 3.329 is_illegal = true; 3.330 } 3.331 } else { // not interface
4.1 --- a/src/share/vm/classfile/classFileParser.hpp Fri Nov 02 13:30:47 2012 -0700 4.2 +++ b/src/share/vm/classfile/classFileParser.hpp Fri Nov 02 17:18:16 2012 -0700 4.3 @@ -151,6 +151,7 @@ 4.4 ClassLoaderData* loader_data, 4.5 Handle protection_domain, 4.6 Symbol* class_name, 4.7 + bool* has_default_methods, 4.8 TRAPS); 4.9 void record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS); 4.10 4.11 @@ -188,6 +189,7 @@ 4.12 Array<AnnotationArray*>** methods_annotations, 4.13 Array<AnnotationArray*>** methods_parameter_annotations, 4.14 Array<AnnotationArray*>** methods_default_annotations, 4.15 + bool* has_default_method, 4.16 TRAPS); 4.17 Array<int>* sort_methods(ClassLoaderData* loader_data, 4.18 Array<Method*>* methods,
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/src/share/vm/classfile/defaultMethods.cpp Fri Nov 02 17:18:16 2012 -0700 5.3 @@ -0,0 +1,1387 @@ 5.4 +/* 5.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 5.23 + * or visit www.oracle.com if you need additional information or have any 5.24 + * questions. 5.25 + * 5.26 + */ 5.27 + 5.28 +#include "precompiled.hpp" 5.29 +#include "classfile/bytecodeAssembler.hpp" 5.30 +#include "classfile/defaultMethods.hpp" 5.31 +#include "classfile/genericSignatures.hpp" 5.32 +#include "classfile/symbolTable.hpp" 5.33 +#include "memory/allocation.hpp" 5.34 +#include "memory/metadataFactory.hpp" 5.35 +#include "memory/resourceArea.hpp" 5.36 +#include "runtime/signature.hpp" 5.37 +#include "runtime/thread.hpp" 5.38 +#include "oops/instanceKlass.hpp" 5.39 +#include "oops/klass.hpp" 5.40 +#include "oops/method.hpp" 5.41 +#include "utilities/accessFlags.hpp" 5.42 +#include "utilities/exceptions.hpp" 5.43 +#include "utilities/ostream.hpp" 5.44 +#include "utilities/pair.hpp" 5.45 +#include "utilities/resourceHash.hpp" 5.46 + 5.47 +typedef enum { QUALIFIED, DISQUALIFIED } QualifiedState; 5.48 + 5.49 +// Because we use an iterative algorithm when iterating over the type 5.50 +// hierarchy, we can't use traditional scoped objects which automatically do 5.51 +// cleanup in the destructor when the scope is exited. PseudoScope (and 5.52 +// PseudoScopeMark) provides a similar functionality, but for when you want a 5.53 +// scoped object in non-stack memory (such as in resource memory, as we do 5.54 +// here). You've just got to remember to call 'destroy()' on the scope when 5.55 +// leaving it (and marks have to be explicitly added). 5.56 +class PseudoScopeMark : public ResourceObj { 5.57 + public: 5.58 + virtual void destroy() = 0; 5.59 +}; 5.60 + 5.61 +class PseudoScope : public ResourceObj { 5.62 + private: 5.63 + GrowableArray<PseudoScopeMark*> _marks; 5.64 + public: 5.65 + 5.66 + static PseudoScope* cast(void* data) { 5.67 + return static_cast<PseudoScope*>(data); 5.68 + } 5.69 + 5.70 + void add_mark(PseudoScopeMark* psm) { 5.71 + _marks.append(psm); 5.72 + } 5.73 + 5.74 + void destroy() { 5.75 + for (int i = 0; i < _marks.length(); ++i) { 5.76 + _marks.at(i)->destroy(); 5.77 + } 5.78 + } 5.79 +}; 5.80 + 5.81 +class ContextMark : public PseudoScopeMark { 5.82 + private: 5.83 + generic::Context::Mark _mark; 5.84 + public: 5.85 + ContextMark(const generic::Context::Mark& cm) : _mark(cm) {} 5.86 + virtual void destroy() { _mark.destroy(); } 5.87 +}; 5.88 + 5.89 +#ifndef PRODUCT 5.90 +static void print_slot(outputStream* str, Symbol* name, Symbol* signature) { 5.91 + ResourceMark rm; 5.92 + str->print("%s%s", name->as_C_string(), signature->as_C_string()); 5.93 +} 5.94 + 5.95 +static void print_method(outputStream* str, Method* mo, bool with_class=true) { 5.96 + ResourceMark rm; 5.97 + if (with_class) { 5.98 + str->print("%s.", mo->klass_name()->as_C_string()); 5.99 + } 5.100 + print_slot(str, mo->name(), mo->signature()); 5.101 +} 5.102 +#endif // ndef PRODUCT 5.103 + 5.104 +/** 5.105 + * Perform a depth-first iteration over the class hierarchy, applying 5.106 + * algorithmic logic as it goes. 5.107 + * 5.108 + * This class is one half of the inheritance hierarchy analysis mechanism. 5.109 + * It is meant to be used in conjunction with another class, the algorithm, 5.110 + * which is indicated by the ALGO template parameter. This class can be 5.111 + * paired with any algorithm class that provides the required methods. 5.112 + * 5.113 + * This class contains all the mechanics for iterating over the class hierarchy 5.114 + * starting at a particular root, without recursing (thus limiting stack growth 5.115 + * from this point). It visits each superclass (if present) and superinterface 5.116 + * in a depth-first manner, with callbacks to the ALGO class as each class is 5.117 + * encountered (visit()), The algorithm can cut-off further exploration of a 5.118 + * particular branch by returning 'false' from a visit() call. 5.119 + * 5.120 + * The ALGO class, must provide a visit() method, which each of which will be 5.121 + * called once for each node in the inheritance tree during the iteration. In 5.122 + * addition, it can provide a memory block via new_node_data(InstanceKlass*), 5.123 + * which it can use for node-specific storage (and access via the 5.124 + * current_data() and data_at_depth(int) methods). 5.125 + * 5.126 + * Bare minimum needed to be an ALGO class: 5.127 + * class Algo : public HierarchyVisitor<Algo> { 5.128 + * void* new_node_data(InstanceKlass* cls) { return NULL; } 5.129 + * void free_node_data(void* data) { return; } 5.130 + * bool visit() { return true; } 5.131 + * }; 5.132 + */ 5.133 +template <class ALGO> 5.134 +class HierarchyVisitor : StackObj { 5.135 + private: 5.136 + 5.137 + class Node : public ResourceObj { 5.138 + public: 5.139 + InstanceKlass* _class; 5.140 + bool _super_was_visited; 5.141 + int _interface_index; 5.142 + void* _algorithm_data; 5.143 + 5.144 + Node(InstanceKlass* cls, void* data, bool visit_super) 5.145 + : _class(cls), _super_was_visited(!visit_super), 5.146 + _interface_index(0), _algorithm_data(data) {} 5.147 + 5.148 + int number_of_interfaces() { return _class->local_interfaces()->length(); } 5.149 + int interface_index() { return _interface_index; } 5.150 + void set_super_visited() { _super_was_visited = true; } 5.151 + void increment_visited_interface() { ++_interface_index; } 5.152 + void set_all_interfaces_visited() { 5.153 + _interface_index = number_of_interfaces(); 5.154 + } 5.155 + bool has_visited_super() { return _super_was_visited; } 5.156 + bool has_visited_all_interfaces() { 5.157 + return interface_index() >= number_of_interfaces(); 5.158 + } 5.159 + InstanceKlass* interface_at(int index) { 5.160 + return InstanceKlass::cast(_class->local_interfaces()->at(index)); 5.161 + } 5.162 + InstanceKlass* next_super() { return _class->java_super(); } 5.163 + InstanceKlass* next_interface() { 5.164 + return interface_at(interface_index()); 5.165 + } 5.166 + }; 5.167 + 5.168 + bool _cancelled; 5.169 + GrowableArray<Node*> _path; 5.170 + 5.171 + Node* current_top() const { return _path.top(); } 5.172 + bool has_more_nodes() const { return !_path.is_empty(); } 5.173 + void push(InstanceKlass* cls, void* data) { 5.174 + assert(cls != NULL, "Requires a valid instance class"); 5.175 + Node* node = new Node(cls, data, has_super(cls)); 5.176 + _path.push(node); 5.177 + } 5.178 + void pop() { _path.pop(); } 5.179 + 5.180 + void reset_iteration() { 5.181 + _cancelled = false; 5.182 + _path.clear(); 5.183 + } 5.184 + bool is_cancelled() const { return _cancelled; } 5.185 + 5.186 + static bool has_super(InstanceKlass* cls) { 5.187 + return cls->super() != NULL && !cls->is_interface(); 5.188 + } 5.189 + 5.190 + Node* node_at_depth(int i) const { 5.191 + return (i >= _path.length()) ? NULL : _path.at(_path.length() - i - 1); 5.192 + } 5.193 + 5.194 + protected: 5.195 + 5.196 + // Accessors available to the algorithm 5.197 + int current_depth() const { return _path.length() - 1; } 5.198 + 5.199 + InstanceKlass* class_at_depth(int i) { 5.200 + Node* n = node_at_depth(i); 5.201 + return n == NULL ? NULL : n->_class; 5.202 + } 5.203 + InstanceKlass* current_class() { return class_at_depth(0); } 5.204 + 5.205 + void* data_at_depth(int i) { 5.206 + Node* n = node_at_depth(i); 5.207 + return n == NULL ? NULL : n->_algorithm_data; 5.208 + } 5.209 + void* current_data() { return data_at_depth(0); } 5.210 + 5.211 + void cancel_iteration() { _cancelled = true; } 5.212 + 5.213 + public: 5.214 + 5.215 + void run(InstanceKlass* root) { 5.216 + ALGO* algo = static_cast<ALGO*>(this); 5.217 + 5.218 + reset_iteration(); 5.219 + 5.220 + void* algo_data = algo->new_node_data(root); 5.221 + push(root, algo_data); 5.222 + bool top_needs_visit = true; 5.223 + 5.224 + do { 5.225 + Node* top = current_top(); 5.226 + if (top_needs_visit) { 5.227 + if (algo->visit() == false) { 5.228 + // algorithm does not want to continue along this path. Arrange 5.229 + // it so that this state is immediately popped off the stack 5.230 + top->set_super_visited(); 5.231 + top->set_all_interfaces_visited(); 5.232 + } 5.233 + top_needs_visit = false; 5.234 + } 5.235 + 5.236 + if (top->has_visited_super() && top->has_visited_all_interfaces()) { 5.237 + algo->free_node_data(top->_algorithm_data); 5.238 + pop(); 5.239 + } else { 5.240 + InstanceKlass* next = NULL; 5.241 + if (top->has_visited_super() == false) { 5.242 + next = top->next_super(); 5.243 + top->set_super_visited(); 5.244 + } else { 5.245 + next = top->next_interface(); 5.246 + top->increment_visited_interface(); 5.247 + } 5.248 + assert(next != NULL, "Otherwise we shouldn't be here"); 5.249 + algo_data = algo->new_node_data(next); 5.250 + push(next, algo_data); 5.251 + top_needs_visit = true; 5.252 + } 5.253 + } while (!is_cancelled() && has_more_nodes()); 5.254 + } 5.255 +}; 5.256 + 5.257 +#ifndef PRODUCT 5.258 +class PrintHierarchy : public HierarchyVisitor<PrintHierarchy> { 5.259 + public: 5.260 + 5.261 + bool visit() { 5.262 + InstanceKlass* cls = current_class(); 5.263 + streamIndentor si(tty, current_depth() * 2); 5.264 + tty->indent().print_cr("%s", cls->name()->as_C_string()); 5.265 + return true; 5.266 + } 5.267 + 5.268 + void* new_node_data(InstanceKlass* cls) { return NULL; } 5.269 + void free_node_data(void* data) { return; } 5.270 +}; 5.271 +#endif // ndef PRODUCT 5.272 + 5.273 +// Used to register InstanceKlass objects and all related metadata structures 5.274 +// (Methods, ConstantPools) as "in-use" by the current thread so that they can't 5.275 +// be deallocated by class redefinition while we're using them. The classes are 5.276 +// de-registered when this goes out of scope. 5.277 +// 5.278 +// Once a class is registered, we need not bother with methodHandles or 5.279 +// constantPoolHandles for it's associated metadata. 5.280 +class KeepAliveRegistrar : public StackObj { 5.281 + private: 5.282 + Thread* _thread; 5.283 + GrowableArray<ConstantPool*> _keep_alive; 5.284 + 5.285 + public: 5.286 + KeepAliveRegistrar(Thread* thread) : _thread(thread), _keep_alive(20) { 5.287 + assert(thread == Thread::current(), "Must be current thread"); 5.288 + } 5.289 + 5.290 + ~KeepAliveRegistrar() { 5.291 + for (int i = _keep_alive.length() - 1; i >= 0; --i) { 5.292 + ConstantPool* cp = _keep_alive.at(i); 5.293 + int idx = _thread->metadata_handles()->find_from_end(cp); 5.294 + assert(idx > 0, "Must be in the list"); 5.295 + _thread->metadata_handles()->remove_at(idx); 5.296 + } 5.297 + } 5.298 + 5.299 + // Register a class as 'in-use' by the thread. It's fine to register a class 5.300 + // multiple times (though perhaps inefficient) 5.301 + void register_class(InstanceKlass* ik) { 5.302 + ConstantPool* cp = ik->constants(); 5.303 + _keep_alive.push(cp); 5.304 + _thread->metadata_handles()->push(cp); 5.305 + } 5.306 +}; 5.307 + 5.308 +class KeepAliveVisitor : public HierarchyVisitor<KeepAliveVisitor> { 5.309 + private: 5.310 + KeepAliveRegistrar* _registrar; 5.311 + 5.312 + public: 5.313 + KeepAliveVisitor(KeepAliveRegistrar* registrar) : _registrar(registrar) {} 5.314 + 5.315 + void* new_node_data(InstanceKlass* cls) { return NULL; } 5.316 + void free_node_data(void* data) { return; } 5.317 + 5.318 + bool visit() { 5.319 + _registrar->register_class(current_class()); 5.320 + return true; 5.321 + } 5.322 +}; 5.323 + 5.324 +// A method family contains a set of all methods that implement a single 5.325 +// language-level method. Because of erasure, these methods may have different 5.326 +// signatures. As members of the set are collected while walking over the 5.327 +// hierarchy, they are tagged with a qualification state. The qualification 5.328 +// state for an erased method is set to disqualified if there exists a path 5.329 +// from the root of hierarchy to the method that contains an interleaving 5.330 +// language-equivalent method defined in an interface. 5.331 +class MethodFamily : public ResourceObj { 5.332 + private: 5.333 + 5.334 + generic::MethodDescriptor* _descriptor; // language-level description 5.335 + GrowableArray<Pair<Method*,QualifiedState> > _members; 5.336 + ResourceHashtable<Method*, int> _member_index; 5.337 + 5.338 + Method* _selected_target; // Filled in later, if a unique target exists 5.339 + Symbol* _exception_message; // If no unique target is found 5.340 + 5.341 + bool contains_method(Method* method) { 5.342 + int* lookup = _member_index.get(method); 5.343 + return lookup != NULL; 5.344 + } 5.345 + 5.346 + void add_method(Method* method, QualifiedState state) { 5.347 + Pair<Method*,QualifiedState> entry(method, state); 5.348 + _member_index.put(method, _members.length()); 5.349 + _members.append(entry); 5.350 + } 5.351 + 5.352 + void disqualify_method(Method* method) { 5.353 + int* index = _member_index.get(method); 5.354 + assert(index != NULL && *index >= 0 && *index < _members.length(), "bad index"); 5.355 + _members.at(*index).second = DISQUALIFIED; 5.356 + } 5.357 + 5.358 + Symbol* generate_no_defaults_message(TRAPS) const; 5.359 + Symbol* generate_abstract_method_message(Method* method, TRAPS) const; 5.360 + Symbol* generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const; 5.361 + 5.362 + public: 5.363 + 5.364 + MethodFamily(generic::MethodDescriptor* canonical_desc) 5.365 + : _descriptor(canonical_desc), _selected_target(NULL), 5.366 + _exception_message(NULL) {} 5.367 + 5.368 + generic::MethodDescriptor* descriptor() const { return _descriptor; } 5.369 + 5.370 + bool descriptor_matches(generic::MethodDescriptor* md, generic::Context* ctx) { 5.371 + return descriptor()->covariant_match(md, ctx); 5.372 + } 5.373 + 5.374 + void set_target_if_empty(Method* m) { 5.375 + if (_selected_target == NULL && !m->is_overpass()) { 5.376 + _selected_target = m; 5.377 + } 5.378 + } 5.379 + 5.380 + void record_qualified_method(Method* m) { 5.381 + // If the method already exists in the set as qualified, this operation is 5.382 + // redundant. If it already exists as disqualified, then we leave it as 5.383 + // disqualfied. Thus we only add to the set if it's not already in the 5.384 + // set. 5.385 + if (!contains_method(m)) { 5.386 + add_method(m, QUALIFIED); 5.387 + } 5.388 + } 5.389 + 5.390 + void record_disqualified_method(Method* m) { 5.391 + // If not in the set, add it as disqualified. If it's already in the set, 5.392 + // then set the state to disqualified no matter what the previous state was. 5.393 + if (!contains_method(m)) { 5.394 + add_method(m, DISQUALIFIED); 5.395 + } else { 5.396 + disqualify_method(m); 5.397 + } 5.398 + } 5.399 + 5.400 + bool has_target() const { return _selected_target != NULL; } 5.401 + bool throws_exception() { return _exception_message != NULL; } 5.402 + 5.403 + Method* get_selected_target() { return _selected_target; } 5.404 + Symbol* get_exception_message() { return _exception_message; } 5.405 + 5.406 + // Either sets the target or the exception error message 5.407 + void determine_target(InstanceKlass* root, TRAPS) { 5.408 + if (has_target() || throws_exception()) { 5.409 + return; 5.410 + } 5.411 + 5.412 + GrowableArray<Method*> qualified_methods; 5.413 + for (int i = 0; i < _members.length(); ++i) { 5.414 + Pair<Method*,QualifiedState> entry = _members.at(i); 5.415 + if (entry.second == QUALIFIED) { 5.416 + qualified_methods.append(entry.first); 5.417 + } 5.418 + } 5.419 + 5.420 + if (qualified_methods.length() == 0) { 5.421 + _exception_message = generate_no_defaults_message(CHECK); 5.422 + } else if (qualified_methods.length() == 1) { 5.423 + Method* method = qualified_methods.at(0); 5.424 + if (method->is_abstract()) { 5.425 + _exception_message = generate_abstract_method_message(method, CHECK); 5.426 + } else { 5.427 + _selected_target = qualified_methods.at(0); 5.428 + } 5.429 + } else { 5.430 + _exception_message = generate_conflicts_message(&qualified_methods,CHECK); 5.431 + } 5.432 + 5.433 + assert((has_target() ^ throws_exception()) == 1, 5.434 + "One and only one must be true"); 5.435 + } 5.436 + 5.437 + bool contains_signature(Symbol* query) { 5.438 + for (int i = 0; i < _members.length(); ++i) { 5.439 + if (query == _members.at(i).first->signature()) { 5.440 + return true; 5.441 + } 5.442 + } 5.443 + return false; 5.444 + } 5.445 + 5.446 +#ifndef PRODUCT 5.447 + void print_on(outputStream* str) const { 5.448 + print_on(str, 0); 5.449 + } 5.450 + 5.451 + void print_on(outputStream* str, int indent) const { 5.452 + streamIndentor si(str, indent * 2); 5.453 + 5.454 + generic::Context ctx(NULL); // empty, as _descriptor already canonicalized 5.455 + TempNewSymbol family = descriptor()->reify_signature(&ctx, Thread::current()); 5.456 + str->indent().print_cr("Logical Method %s:", family->as_C_string()); 5.457 + 5.458 + streamIndentor si2(str); 5.459 + for (int i = 0; i < _members.length(); ++i) { 5.460 + str->indent(); 5.461 + print_method(str, _members.at(i).first); 5.462 + if (_members.at(i).second == DISQUALIFIED) { 5.463 + str->print(" (disqualified)"); 5.464 + } 5.465 + str->print_cr(""); 5.466 + } 5.467 + 5.468 + if (_selected_target != NULL) { 5.469 + print_selected(str, 1); 5.470 + } 5.471 + } 5.472 + 5.473 + void print_selected(outputStream* str, int indent) const { 5.474 + assert(has_target(), "Should be called otherwise"); 5.475 + streamIndentor si(str, indent * 2); 5.476 + str->indent().print("Selected method: "); 5.477 + print_method(str, _selected_target); 5.478 + str->print_cr(""); 5.479 + } 5.480 + 5.481 + void print_exception(outputStream* str, int indent) { 5.482 + assert(throws_exception(), "Should be called otherwise"); 5.483 + streamIndentor si(str, indent * 2); 5.484 + str->indent().print_cr("%s", _exception_message->as_C_string()); 5.485 + } 5.486 +#endif // ndef PRODUCT 5.487 +}; 5.488 + 5.489 +Symbol* MethodFamily::generate_no_defaults_message(TRAPS) const { 5.490 + return SymbolTable::new_symbol("No qualifying defaults found", CHECK_NULL); 5.491 +} 5.492 + 5.493 +Symbol* MethodFamily::generate_abstract_method_message(Method* method, TRAPS) const { 5.494 + Symbol* klass = method->klass_name(); 5.495 + Symbol* name = method->name(); 5.496 + Symbol* sig = method->signature(); 5.497 + stringStream ss; 5.498 + ss.print("Method "); 5.499 + ss.write((const char*)klass->bytes(), klass->utf8_length()); 5.500 + ss.print("."); 5.501 + ss.write((const char*)name->bytes(), name->utf8_length()); 5.502 + ss.write((const char*)sig->bytes(), sig->utf8_length()); 5.503 + ss.print(" is abstract"); 5.504 + return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL); 5.505 +} 5.506 + 5.507 +Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const { 5.508 + stringStream ss; 5.509 + ss.print("Conflicting default methods:"); 5.510 + for (int i = 0; i < methods->length(); ++i) { 5.511 + Method* method = methods->at(i); 5.512 + Symbol* klass = method->klass_name(); 5.513 + Symbol* name = method->name(); 5.514 + ss.print(" "); 5.515 + ss.write((const char*)klass->bytes(), klass->utf8_length()); 5.516 + ss.print("."); 5.517 + ss.write((const char*)name->bytes(), name->utf8_length()); 5.518 + } 5.519 + return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL); 5.520 +} 5.521 + 5.522 +class StateRestorer; 5.523 + 5.524 +// StatefulMethodFamily is a wrapper around MethodFamily that maintains the 5.525 +// qualification state during hierarchy visitation, and applies that state 5.526 +// when adding members to the MethodFamily. 5.527 +class StatefulMethodFamily : public ResourceObj { 5.528 + friend class StateRestorer; 5.529 + private: 5.530 + MethodFamily* _method; 5.531 + QualifiedState _qualification_state; 5.532 + 5.533 + void set_qualification_state(QualifiedState state) { 5.534 + _qualification_state = state; 5.535 + } 5.536 + 5.537 + public: 5.538 + StatefulMethodFamily(generic::MethodDescriptor* md, generic::Context* ctx) { 5.539 + _method = new MethodFamily(md->canonicalize(ctx)); 5.540 + _qualification_state = QUALIFIED; 5.541 + } 5.542 + 5.543 + void set_target_if_empty(Method* m) { _method->set_target_if_empty(m); } 5.544 + 5.545 + MethodFamily* get_method_family() { return _method; } 5.546 + 5.547 + bool descriptor_matches(generic::MethodDescriptor* md, generic::Context* ctx) { 5.548 + return _method->descriptor_matches(md, ctx); 5.549 + } 5.550 + 5.551 + StateRestorer* record_method_and_dq_further(Method* mo); 5.552 +}; 5.553 + 5.554 +class StateRestorer : public PseudoScopeMark { 5.555 + private: 5.556 + StatefulMethodFamily* _method; 5.557 + QualifiedState _state_to_restore; 5.558 + public: 5.559 + StateRestorer(StatefulMethodFamily* dm, QualifiedState state) 5.560 + : _method(dm), _state_to_restore(state) {} 5.561 + ~StateRestorer() { destroy(); } 5.562 + void restore_state() { _method->set_qualification_state(_state_to_restore); } 5.563 + virtual void destroy() { restore_state(); } 5.564 +}; 5.565 + 5.566 +StateRestorer* StatefulMethodFamily::record_method_and_dq_further(Method* mo) { 5.567 + StateRestorer* mark = new StateRestorer(this, _qualification_state); 5.568 + if (_qualification_state == QUALIFIED) { 5.569 + _method->record_qualified_method(mo); 5.570 + } else { 5.571 + _method->record_disqualified_method(mo); 5.572 + } 5.573 + // Everything found "above"??? this method in the hierarchy walk is set to 5.574 + // disqualified 5.575 + set_qualification_state(DISQUALIFIED); 5.576 + return mark; 5.577 +} 5.578 + 5.579 +class StatefulMethodFamilies : public ResourceObj { 5.580 + private: 5.581 + GrowableArray<StatefulMethodFamily*> _methods; 5.582 + 5.583 + public: 5.584 + StatefulMethodFamily* find_matching( 5.585 + generic::MethodDescriptor* md, generic::Context* ctx) { 5.586 + for (int i = 0; i < _methods.length(); ++i) { 5.587 + StatefulMethodFamily* existing = _methods.at(i); 5.588 + if (existing->descriptor_matches(md, ctx)) { 5.589 + return existing; 5.590 + } 5.591 + } 5.592 + return NULL; 5.593 + } 5.594 + 5.595 + StatefulMethodFamily* find_matching_or_create( 5.596 + generic::MethodDescriptor* md, generic::Context* ctx) { 5.597 + StatefulMethodFamily* method = find_matching(md, ctx); 5.598 + if (method == NULL) { 5.599 + method = new StatefulMethodFamily(md, ctx); 5.600 + _methods.append(method); 5.601 + } 5.602 + return method; 5.603 + } 5.604 + 5.605 + void extract_families_into(GrowableArray<MethodFamily*>* array) { 5.606 + for (int i = 0; i < _methods.length(); ++i) { 5.607 + array->append(_methods.at(i)->get_method_family()); 5.608 + } 5.609 + } 5.610 +}; 5.611 + 5.612 +// Represents a location corresponding to a vtable slot for methods that 5.613 +// neither the class nor any of it's ancestors provide an implementaion. 5.614 +// Default methods may be present to fill this slot. 5.615 +class EmptyVtableSlot : public ResourceObj { 5.616 + private: 5.617 + Symbol* _name; 5.618 + Symbol* _signature; 5.619 + int _size_of_parameters; 5.620 + MethodFamily* _binding; 5.621 + 5.622 + public: 5.623 + EmptyVtableSlot(Method* method) 5.624 + : _name(method->name()), _signature(method->signature()), 5.625 + _size_of_parameters(method->size_of_parameters()), _binding(NULL) {} 5.626 + 5.627 + Symbol* name() const { return _name; } 5.628 + Symbol* signature() const { return _signature; } 5.629 + int size_of_parameters() const { return _size_of_parameters; } 5.630 + 5.631 + void bind_family(MethodFamily* lm) { _binding = lm; } 5.632 + bool is_bound() { return _binding != NULL; } 5.633 + MethodFamily* get_binding() { return _binding; } 5.634 + 5.635 +#ifndef PRODUCT 5.636 + void print_on(outputStream* str) const { 5.637 + print_slot(str, name(), signature()); 5.638 + } 5.639 +#endif // ndef PRODUCT 5.640 +}; 5.641 + 5.642 +static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots( 5.643 + InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { 5.644 + 5.645 + assert(klass != NULL, "Must be valid class"); 5.646 + 5.647 + GrowableArray<EmptyVtableSlot*>* slots = new GrowableArray<EmptyVtableSlot*>(); 5.648 + 5.649 + // All miranda methods are obvious candidates 5.650 + for (int i = 0; i < mirandas->length(); ++i) { 5.651 + EmptyVtableSlot* slot = new EmptyVtableSlot(mirandas->at(i)); 5.652 + slots->append(slot); 5.653 + } 5.654 + 5.655 + // Also any overpasses in our superclasses, that we haven't implemented. 5.656 + // (can't use the vtable because it is not guaranteed to be initialized yet) 5.657 + InstanceKlass* super = klass->java_super(); 5.658 + while (super != NULL) { 5.659 + for (int i = 0; i < super->methods()->length(); ++i) { 5.660 + Method* m = super->methods()->at(i); 5.661 + if (m->is_overpass()) { 5.662 + // m is a method that would have been a miranda if not for the 5.663 + // default method processing that occurred on behalf of our superclass, 5.664 + // so it's a method we want to re-examine in this new context. That is, 5.665 + // unless we have a real implementation of it in the current class. 5.666 + Method* impl = klass->lookup_method(m->name(), m->signature()); 5.667 + if (impl == NULL || impl->is_overpass()) { 5.668 + slots->append(new EmptyVtableSlot(m)); 5.669 + } 5.670 + } 5.671 + } 5.672 + super = super->java_super(); 5.673 + } 5.674 + 5.675 +#ifndef PRODUCT 5.676 + if (TraceDefaultMethods) { 5.677 + tty->print_cr("Slots that need filling:"); 5.678 + streamIndentor si(tty); 5.679 + for (int i = 0; i < slots->length(); ++i) { 5.680 + tty->indent(); 5.681 + slots->at(i)->print_on(tty); 5.682 + tty->print_cr(""); 5.683 + } 5.684 + } 5.685 +#endif // ndef PRODUCT 5.686 + return slots; 5.687 +} 5.688 + 5.689 +// Iterates over the type hierarchy looking for all methods with a specific 5.690 +// method name. The result of this is a set of method families each of 5.691 +// which is populated with a set of methods that implement the same 5.692 +// language-level signature. 5.693 +class FindMethodsByName : public HierarchyVisitor<FindMethodsByName> { 5.694 + private: 5.695 + // Context data 5.696 + Thread* THREAD; 5.697 + generic::DescriptorCache* _cache; 5.698 + Symbol* _method_name; 5.699 + generic::Context* _ctx; 5.700 + StatefulMethodFamilies _families; 5.701 + 5.702 + public: 5.703 + 5.704 + FindMethodsByName(generic::DescriptorCache* cache, Symbol* name, 5.705 + generic::Context* ctx, Thread* thread) : 5.706 + _cache(cache), _method_name(name), _ctx(ctx), THREAD(thread) {} 5.707 + 5.708 + void get_discovered_families(GrowableArray<MethodFamily*>* methods) { 5.709 + _families.extract_families_into(methods); 5.710 + } 5.711 + 5.712 + void* new_node_data(InstanceKlass* cls) { return new PseudoScope(); } 5.713 + void free_node_data(void* node_data) { 5.714 + PseudoScope::cast(node_data)->destroy(); 5.715 + } 5.716 + 5.717 + bool visit() { 5.718 + PseudoScope* scope = PseudoScope::cast(current_data()); 5.719 + InstanceKlass* klass = current_class(); 5.720 + InstanceKlass* sub = current_depth() > 0 ? class_at_depth(1) : NULL; 5.721 + 5.722 + ContextMark* cm = new ContextMark(_ctx->mark()); 5.723 + scope->add_mark(cm); // will restore context when scope is freed 5.724 + 5.725 + _ctx->apply_type_arguments(sub, klass, THREAD); 5.726 + 5.727 + int start, end = 0; 5.728 + start = klass->find_method_by_name(_method_name, &end); 5.729 + if (start != -1) { 5.730 + for (int i = start; i < end; ++i) { 5.731 + Method* m = klass->methods()->at(i); 5.732 + // This gets the method's parameter list with its generic type 5.733 + // parameters resolved 5.734 + generic::MethodDescriptor* md = _cache->descriptor_for(m, THREAD); 5.735 + 5.736 + // Find all methods on this hierarchy that match this method 5.737 + // (name, signature). This class collects other families of this 5.738 + // method name. 5.739 + StatefulMethodFamily* family = 5.740 + _families.find_matching_or_create(md, _ctx); 5.741 + 5.742 + if (klass->is_interface()) { 5.743 + // ??? 5.744 + StateRestorer* restorer = family->record_method_and_dq_further(m); 5.745 + scope->add_mark(restorer); 5.746 + } else { 5.747 + // This is the rule that methods in classes "win" (bad word) over 5.748 + // methods in interfaces. This works because of single inheritance 5.749 + family->set_target_if_empty(m); 5.750 + } 5.751 + } 5.752 + } 5.753 + return true; 5.754 + } 5.755 +}; 5.756 + 5.757 +#ifndef PRODUCT 5.758 +static void print_families( 5.759 + GrowableArray<MethodFamily*>* methods, Symbol* match) { 5.760 + streamIndentor si(tty, 4); 5.761 + if (methods->length() == 0) { 5.762 + tty->indent(); 5.763 + tty->print_cr("No Logical Method found"); 5.764 + } 5.765 + for (int i = 0; i < methods->length(); ++i) { 5.766 + tty->indent(); 5.767 + MethodFamily* lm = methods->at(i); 5.768 + if (lm->contains_signature(match)) { 5.769 + tty->print_cr("<Matching>"); 5.770 + } else { 5.771 + tty->print_cr("<Non-Matching>"); 5.772 + } 5.773 + lm->print_on(tty, 1); 5.774 + } 5.775 +} 5.776 +#endif // ndef PRODUCT 5.777 + 5.778 +static void merge_in_new_methods(InstanceKlass* klass, 5.779 + GrowableArray<Method*>* new_methods, TRAPS); 5.780 +static void create_overpasses( 5.781 + GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS); 5.782 + 5.783 +// This is the guts of the default methods implementation. This is called just 5.784 +// after the classfile has been parsed if some ancestor has default methods. 5.785 +// 5.786 +// First if finds any name/signature slots that need any implementation (either 5.787 +// because they are miranda or a superclass's implementation is an overpass 5.788 +// itself). For each slot, iterate over the hierarchy, using generic signature 5.789 +// information to partition any methods that match the name into method families 5.790 +// where each family contains methods whose signatures are equivalent at the 5.791 +// language level (i.e., their reified parameters match and return values are 5.792 +// covariant). Check those sets to see if they contain a signature that matches 5.793 +// the slot we're looking at (if we're lucky, there might be other empty slots 5.794 +// that we can fill using the same analysis). 5.795 +// 5.796 +// For each slot filled, we generate an overpass method that either calls the 5.797 +// unique default method candidate using invokespecial, or throws an exception 5.798 +// (in the case of no default method candidates, or more than one valid 5.799 +// candidate). These methods are then added to the class's method list. If 5.800 +// the method set we're using contains methods (qualified or not) with a 5.801 +// different runtime signature than the method we're creating, then we have to 5.802 +// create bridges with those signatures too. 5.803 +void DefaultMethods::generate_default_methods( 5.804 + InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { 5.805 + 5.806 + // This resource mark is the bound for all memory allocation that takes 5.807 + // place during default method processing. After this goes out of scope, 5.808 + // all (Resource) objects' memory will be reclaimed. Be careful if adding an 5.809 + // embedded resource mark under here as that memory can't be used outside 5.810 + // whatever scope it's in. 5.811 + ResourceMark rm(THREAD); 5.812 + 5.813 + generic::DescriptorCache cache; 5.814 + 5.815 + // Keep entire hierarchy alive for the duration of the computation 5.816 + KeepAliveRegistrar keepAlive(THREAD); 5.817 + KeepAliveVisitor loadKeepAlive(&keepAlive); 5.818 + loadKeepAlive.run(klass); 5.819 + 5.820 +#ifndef PRODUCT 5.821 + if (TraceDefaultMethods) { 5.822 + ResourceMark rm; // be careful with these! 5.823 + tty->print_cr("Class %s requires default method processing", 5.824 + klass->name()->as_klass_external_name()); 5.825 + PrintHierarchy printer; 5.826 + printer.run(klass); 5.827 + } 5.828 +#endif // ndef PRODUCT 5.829 + 5.830 + GrowableArray<EmptyVtableSlot*>* empty_slots = 5.831 + find_empty_vtable_slots(klass, mirandas, CHECK); 5.832 + 5.833 + for (int i = 0; i < empty_slots->length(); ++i) { 5.834 + EmptyVtableSlot* slot = empty_slots->at(i); 5.835 +#ifndef PRODUCT 5.836 + if (TraceDefaultMethods) { 5.837 + streamIndentor si(tty, 2); 5.838 + tty->indent().print("Looking for default methods for slot "); 5.839 + slot->print_on(tty); 5.840 + tty->print_cr(""); 5.841 + } 5.842 +#endif // ndef PRODUCT 5.843 + if (slot->is_bound()) { 5.844 +#ifndef PRODUCT 5.845 + if (TraceDefaultMethods) { 5.846 + streamIndentor si(tty, 4); 5.847 + tty->indent().print_cr("Already bound to logical method:"); 5.848 + slot->get_binding()->print_on(tty, 1); 5.849 + } 5.850 +#endif // ndef PRODUCT 5.851 + continue; // covered by previous processing 5.852 + } 5.853 + 5.854 + generic::Context ctx(&cache); 5.855 + FindMethodsByName visitor(&cache, slot->name(), &ctx, CHECK); 5.856 + visitor.run(klass); 5.857 + 5.858 + GrowableArray<MethodFamily*> discovered_families; 5.859 + visitor.get_discovered_families(&discovered_families); 5.860 + 5.861 +#ifndef PRODUCT 5.862 + if (TraceDefaultMethods) { 5.863 + print_families(&discovered_families, slot->signature()); 5.864 + } 5.865 +#endif // ndef PRODUCT 5.866 + 5.867 + // Find and populate any other slots that match the discovered families 5.868 + for (int j = i; j < empty_slots->length(); ++j) { 5.869 + EmptyVtableSlot* open_slot = empty_slots->at(j); 5.870 + 5.871 + if (slot->name() == open_slot->name()) { 5.872 + for (int k = 0; k < discovered_families.length(); ++k) { 5.873 + MethodFamily* lm = discovered_families.at(k); 5.874 + 5.875 + if (lm->contains_signature(open_slot->signature())) { 5.876 + lm->determine_target(klass, CHECK); 5.877 + open_slot->bind_family(lm); 5.878 + } 5.879 + } 5.880 + } 5.881 + } 5.882 + } 5.883 + 5.884 +#ifndef PRODUCT 5.885 + if (TraceDefaultMethods) { 5.886 + tty->print_cr("Creating overpasses..."); 5.887 + } 5.888 +#endif // ndef PRODUCT 5.889 + 5.890 + create_overpasses(empty_slots, klass, CHECK); 5.891 + 5.892 +#ifndef PRODUCT 5.893 + if (TraceDefaultMethods) { 5.894 + tty->print_cr("Default method processing complete"); 5.895 + } 5.896 +#endif // ndef PRODUCT 5.897 +} 5.898 + 5.899 + 5.900 +/** 5.901 + * Generic analysis was used upon interface '_target' and found a unique 5.902 + * default method candidate with generic signature '_method_desc'. This 5.903 + * method is only viable if it would also be in the set of default method 5.904 + * candidates if we ran a full analysis on the current class. 5.905 + * 5.906 + * The only reason that the method would not be in the set of candidates for 5.907 + * the current class is if that there's another covariantly matching method 5.908 + * which is "more specific" than the found method -- i.e., one could find a 5.909 + * path in the interface hierarchy in which the matching method appears 5.910 + * before we get to '_target'. 5.911 + * 5.912 + * In order to determine this, we examine all of the implemented 5.913 + * interfaces. If we find path that leads to the '_target' interface, then 5.914 + * we examine that path to see if there are any methods that would shadow 5.915 + * the selected method along that path. 5.916 + */ 5.917 +class ShadowChecker : public HierarchyVisitor<ShadowChecker> { 5.918 + private: 5.919 + generic::DescriptorCache* _cache; 5.920 + Thread* THREAD; 5.921 + 5.922 + InstanceKlass* _target; 5.923 + 5.924 + Symbol* _method_name; 5.925 + InstanceKlass* _method_holder; 5.926 + generic::MethodDescriptor* _method_desc; 5.927 + bool _found_shadow; 5.928 + 5.929 + bool path_has_shadow() { 5.930 + generic::Context ctx(_cache); 5.931 + 5.932 + for (int i = current_depth() - 1; i > 0; --i) { 5.933 + InstanceKlass* ik = class_at_depth(i); 5.934 + InstanceKlass* sub = class_at_depth(i + 1); 5.935 + ctx.apply_type_arguments(sub, ik, THREAD); 5.936 + 5.937 + if (ik->is_interface()) { 5.938 + int end; 5.939 + int start = ik->find_method_by_name(_method_name, &end); 5.940 + if (start != -1) { 5.941 + for (int j = start; j < end; ++j) { 5.942 + Method* mo = ik->methods()->at(j); 5.943 + generic::MethodDescriptor* md = _cache->descriptor_for(mo, THREAD); 5.944 + if (_method_desc->covariant_match(md, &ctx)) { 5.945 + return true; 5.946 + } 5.947 + } 5.948 + } 5.949 + } 5.950 + } 5.951 + return false; 5.952 + } 5.953 + 5.954 + public: 5.955 + 5.956 + ShadowChecker(generic::DescriptorCache* cache, Thread* thread, 5.957 + Symbol* name, InstanceKlass* holder, generic::MethodDescriptor* desc, 5.958 + InstanceKlass* target) 5.959 + : _cache(cache), THREAD(thread), _method_name(name), _method_holder(holder), 5.960 + _method_desc(desc), _target(target), _found_shadow(false) {} 5.961 + 5.962 + void* new_node_data(InstanceKlass* cls) { return NULL; } 5.963 + void free_node_data(void* data) { return; } 5.964 + 5.965 + bool visit() { 5.966 + InstanceKlass* ik = current_class(); 5.967 + if (ik == _target && current_depth() == 1) { 5.968 + return false; // This was the specified super -- no need to search it 5.969 + } 5.970 + if (ik == _method_holder || ik == _target) { 5.971 + // We found a path that should be examined to see if it shadows _method 5.972 + if (path_has_shadow()) { 5.973 + _found_shadow = true; 5.974 + cancel_iteration(); 5.975 + } 5.976 + return false; // no need to continue up hierarchy 5.977 + } 5.978 + return true; 5.979 + } 5.980 + 5.981 + bool found_shadow() { return _found_shadow; } 5.982 +}; 5.983 + 5.984 +// This is called during linktime when we find an invokespecial call that 5.985 +// refers to a direct superinterface. It indicates that we should find the 5.986 +// default method in the hierarchy of that superinterface, and if that method 5.987 +// would have been a candidate from the point of view of 'this' class, then we 5.988 +// return that method. 5.989 +Method* DefaultMethods::find_super_default( 5.990 + Klass* cls, Klass* super, Symbol* method_name, Symbol* sig, TRAPS) { 5.991 + 5.992 + ResourceMark rm(THREAD); 5.993 + 5.994 + assert(cls != NULL && super != NULL, "Need real classes"); 5.995 + 5.996 + InstanceKlass* current_class = InstanceKlass::cast(cls); 5.997 + InstanceKlass* direction = InstanceKlass::cast(super); 5.998 + 5.999 + // Keep entire hierarchy alive for the duration of the computation 5.1000 + KeepAliveRegistrar keepAlive(THREAD); 5.1001 + KeepAliveVisitor loadKeepAlive(&keepAlive); 5.1002 + loadKeepAlive.run(current_class); 5.1003 + 5.1004 +#ifndef PRODUCT 5.1005 + if (TraceDefaultMethods) { 5.1006 + tty->print_cr("Finding super default method %s.%s%s from %s", 5.1007 + direction->name()->as_C_string(), 5.1008 + method_name->as_C_string(), sig->as_C_string(), 5.1009 + current_class->name()->as_C_string()); 5.1010 + } 5.1011 +#endif // ndef PRODUCT 5.1012 + 5.1013 + if (!direction->is_interface()) { 5.1014 + // We should not be here 5.1015 + return NULL; 5.1016 + } 5.1017 + 5.1018 + generic::DescriptorCache cache; 5.1019 + generic::Context ctx(&cache); 5.1020 + 5.1021 + // Prime the initial generic context for current -> direction 5.1022 + ctx.apply_type_arguments(current_class, direction, CHECK_NULL); 5.1023 + 5.1024 + FindMethodsByName visitor(&cache, method_name, &ctx, CHECK_NULL); 5.1025 + visitor.run(direction); 5.1026 + 5.1027 + GrowableArray<MethodFamily*> families; 5.1028 + visitor.get_discovered_families(&families); 5.1029 + 5.1030 +#ifndef PRODUCT 5.1031 + if (TraceDefaultMethods) { 5.1032 + print_families(&families, sig); 5.1033 + } 5.1034 +#endif // ndef PRODUCT 5.1035 + 5.1036 + MethodFamily* selected_family = NULL; 5.1037 + 5.1038 + for (int i = 0; i < families.length(); ++i) { 5.1039 + MethodFamily* lm = families.at(i); 5.1040 + if (lm->contains_signature(sig)) { 5.1041 + lm->determine_target(current_class, CHECK_NULL); 5.1042 + selected_family = lm; 5.1043 + } 5.1044 + } 5.1045 + 5.1046 + if (selected_family->has_target()) { 5.1047 + Method* target = selected_family->get_selected_target(); 5.1048 + InstanceKlass* holder = InstanceKlass::cast(target->method_holder()); 5.1049 + 5.1050 + // Verify that the identified method is valid from the context of 5.1051 + // the current class 5.1052 + ShadowChecker checker(&cache, THREAD, target->name(), 5.1053 + holder, selected_family->descriptor(), direction); 5.1054 + checker.run(current_class); 5.1055 + 5.1056 + if (checker.found_shadow()) { 5.1057 +#ifndef PRODUCT 5.1058 + if (TraceDefaultMethods) { 5.1059 + tty->print_cr(" Only candidate found was shadowed."); 5.1060 + } 5.1061 +#endif // ndef PRODUCT 5.1062 + THROW_MSG_(vmSymbols::java_lang_AbstractMethodError(), 5.1063 + "Accessible default method not found", NULL); 5.1064 + } else { 5.1065 +#ifndef PRODUCT 5.1066 + if (TraceDefaultMethods) { 5.1067 + tty->print(" Returning "); 5.1068 + print_method(tty, target, true); 5.1069 + tty->print_cr(""); 5.1070 + } 5.1071 +#endif // ndef PRODUCT 5.1072 + return target; 5.1073 + } 5.1074 + } else { 5.1075 + assert(selected_family->throws_exception(), "must have target or throw"); 5.1076 + THROW_MSG_(vmSymbols::java_lang_AbstractMethodError(), 5.1077 + selected_family->get_exception_message()->as_C_string(), NULL); 5.1078 + } 5.1079 +} 5.1080 + 5.1081 + 5.1082 +static int assemble_redirect( 5.1083 + BytecodeConstantPool* cp, BytecodeBuffer* buffer, 5.1084 + Symbol* incoming, Method* target, TRAPS) { 5.1085 + 5.1086 + BytecodeAssembler assem(buffer, cp); 5.1087 + 5.1088 + SignatureStream in(incoming, true); 5.1089 + SignatureStream out(target->signature(), true); 5.1090 + u2 parameter_count = 0; 5.1091 + 5.1092 + assem.aload(parameter_count++); // load 'this' 5.1093 + 5.1094 + while (!in.at_return_type()) { 5.1095 + assert(!out.at_return_type(), "Parameter counts do not match"); 5.1096 + BasicType bt = in.type(); 5.1097 + assert(out.type() == bt, "Parameter types are not compatible"); 5.1098 + assem.load(bt, parameter_count); 5.1099 + if (in.is_object() && in.as_symbol(THREAD) != out.as_symbol(THREAD)) { 5.1100 + assem.checkcast(out.as_symbol(THREAD)); 5.1101 + } else if (bt == T_LONG || bt == T_DOUBLE) { 5.1102 + ++parameter_count; // longs and doubles use two slots 5.1103 + } 5.1104 + ++parameter_count; 5.1105 + in.next(); 5.1106 + out.next(); 5.1107 + } 5.1108 + assert(out.at_return_type(), "Parameter counts do not match"); 5.1109 + assert(in.type() == out.type(), "Return types are not compatible"); 5.1110 + 5.1111 + if (parameter_count == 1 && (in.type() == T_LONG || in.type() == T_DOUBLE)) { 5.1112 + ++parameter_count; // need room for return value 5.1113 + } 5.1114 + if (target->method_holder()->is_interface()) { 5.1115 + assem.invokespecial(target); 5.1116 + } else { 5.1117 + assem.invokevirtual(target); 5.1118 + } 5.1119 + 5.1120 + if (in.is_object() && in.as_symbol(THREAD) != out.as_symbol(THREAD)) { 5.1121 + assem.checkcast(in.as_symbol(THREAD)); 5.1122 + } 5.1123 + assem._return(in.type()); 5.1124 + return parameter_count; 5.1125 +} 5.1126 + 5.1127 +static int assemble_abstract_method_error( 5.1128 + BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* message, TRAPS) { 5.1129 + 5.1130 + Symbol* errorName = vmSymbols::java_lang_AbstractMethodError(); 5.1131 + Symbol* init = vmSymbols::object_initializer_name(); 5.1132 + Symbol* sig = vmSymbols::string_void_signature(); 5.1133 + 5.1134 + BytecodeAssembler assem(buffer, cp); 5.1135 + 5.1136 + assem._new(errorName); 5.1137 + assem.dup(); 5.1138 + assem.load_string(message); 5.1139 + assem.invokespecial(errorName, init, sig); 5.1140 + assem.athrow(); 5.1141 + 5.1142 + return 3; // max stack size: [ exception, exception, string ] 5.1143 +} 5.1144 + 5.1145 +static Method* new_method( 5.1146 + BytecodeConstantPool* cp, BytecodeBuffer* bytecodes, Symbol* name, 5.1147 + Symbol* sig, AccessFlags flags, int max_stack, int params, 5.1148 + ConstMethod::MethodType mt, TRAPS) { 5.1149 + 5.1150 + address code_start = static_cast<address>(bytecodes->adr_at(0)); 5.1151 + int code_length = bytecodes->length(); 5.1152 + 5.1153 + Method* m = Method::allocate(cp->pool_holder()->class_loader_data(), 5.1154 + code_length, flags, 0, 0, 0, 0, mt, CHECK_NULL); 5.1155 + 5.1156 + m->set_constants(NULL); // This will get filled in later 5.1157 + m->set_name_index(cp->utf8(name)); 5.1158 + m->set_signature_index(cp->utf8(sig)); 5.1159 + m->set_generic_signature_index(0); 5.1160 +#ifdef CC_INTERP 5.1161 + ResultTypeFinder rtf(sig); 5.1162 + m->set_result_index(rtf.type()); 5.1163 +#endif 5.1164 + m->set_size_of_parameters(params); 5.1165 + m->set_max_stack(max_stack); 5.1166 + m->set_max_locals(params); 5.1167 + m->constMethod()->set_stackmap_data(NULL); 5.1168 + m->set_code(code_start); 5.1169 + m->set_force_inline(true); 5.1170 + 5.1171 + return m; 5.1172 +} 5.1173 + 5.1174 +static void switchover_constant_pool(BytecodeConstantPool* bpool, 5.1175 + InstanceKlass* klass, GrowableArray<Method*>* new_methods, TRAPS) { 5.1176 + 5.1177 + if (new_methods->length() > 0) { 5.1178 + ConstantPool* cp = bpool->create_constant_pool(CHECK); 5.1179 + if (cp != klass->constants()) { 5.1180 + klass->class_loader_data()->add_to_deallocate_list(klass->constants()); 5.1181 + klass->set_constants(cp); 5.1182 + cp->set_pool_holder(klass); 5.1183 + 5.1184 + for (int i = 0; i < new_methods->length(); ++i) { 5.1185 + new_methods->at(i)->set_constants(cp); 5.1186 + } 5.1187 + for (int i = 0; i < klass->methods()->length(); ++i) { 5.1188 + Method* mo = klass->methods()->at(i); 5.1189 + mo->set_constants(cp); 5.1190 + } 5.1191 + } 5.1192 + } 5.1193 +} 5.1194 + 5.1195 +// A "bridge" is a method created by javac to bridge the gap between 5.1196 +// an implementation and a generically-compatible, but different, signature. 5.1197 +// Bridges have actual bytecode implementation in classfiles. 5.1198 +// An "overpass", on the other hand, performs the same function as a bridge 5.1199 +// but does not occur in a classfile; the VM creates overpass itself, 5.1200 +// when it needs a path to get from a call site to an default method, and 5.1201 +// a bridge doesn't exist. 5.1202 +static void create_overpasses( 5.1203 + GrowableArray<EmptyVtableSlot*>* slots, 5.1204 + InstanceKlass* klass, TRAPS) { 5.1205 + 5.1206 + GrowableArray<Method*> overpasses; 5.1207 + BytecodeConstantPool bpool(klass->constants()); 5.1208 + 5.1209 + for (int i = 0; i < slots->length(); ++i) { 5.1210 + EmptyVtableSlot* slot = slots->at(i); 5.1211 + 5.1212 + if (slot->is_bound()) { 5.1213 + MethodFamily* method = slot->get_binding(); 5.1214 + int max_stack = 0; 5.1215 + BytecodeBuffer buffer; 5.1216 + 5.1217 +#ifndef PRODUCT 5.1218 + if (TraceDefaultMethods) { 5.1219 + tty->print("for slot: "); 5.1220 + slot->print_on(tty); 5.1221 + tty->print_cr(""); 5.1222 + if (method->has_target()) { 5.1223 + method->print_selected(tty, 1); 5.1224 + } else { 5.1225 + method->print_exception(tty, 1); 5.1226 + } 5.1227 + } 5.1228 +#endif // ndef PRODUCT 5.1229 + if (method->has_target()) { 5.1230 + Method* selected = method->get_selected_target(); 5.1231 + max_stack = assemble_redirect( 5.1232 + &bpool, &buffer, slot->signature(), selected, CHECK); 5.1233 + } else if (method->throws_exception()) { 5.1234 + max_stack = assemble_abstract_method_error( 5.1235 + &bpool, &buffer, method->get_exception_message(), CHECK); 5.1236 + } 5.1237 + AccessFlags flags = accessFlags_from( 5.1238 + JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE); 5.1239 + Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(), 5.1240 + flags, max_stack, slot->size_of_parameters(), 5.1241 + ConstMethod::OVERPASS, CHECK); 5.1242 + if (m != NULL) { 5.1243 + overpasses.push(m); 5.1244 + } 5.1245 + } 5.1246 + } 5.1247 + 5.1248 +#ifndef PRODUCT 5.1249 + if (TraceDefaultMethods) { 5.1250 + tty->print_cr("Created %d overpass methods", overpasses.length()); 5.1251 + } 5.1252 +#endif // ndef PRODUCT 5.1253 + 5.1254 + switchover_constant_pool(&bpool, klass, &overpasses, CHECK); 5.1255 + merge_in_new_methods(klass, &overpasses, CHECK); 5.1256 +} 5.1257 + 5.1258 +static void sort_methods(GrowableArray<Method*>* methods) { 5.1259 + // Note that this must sort using the same key as is used for sorting 5.1260 + // methods in InstanceKlass. 5.1261 + bool sorted = true; 5.1262 + for (int i = methods->length() - 1; i > 0; --i) { 5.1263 + for (int j = 0; j < i; ++j) { 5.1264 + Method* m1 = methods->at(j); 5.1265 + Method* m2 = methods->at(j + 1); 5.1266 + if ((uintptr_t)m1->name() > (uintptr_t)m2->name()) { 5.1267 + methods->at_put(j, m2); 5.1268 + methods->at_put(j + 1, m1); 5.1269 + sorted = false; 5.1270 + } 5.1271 + } 5.1272 + if (sorted) break; 5.1273 + sorted = true; 5.1274 + } 5.1275 +#ifdef ASSERT 5.1276 + uintptr_t prev = 0; 5.1277 + for (int i = 0; i < methods->length(); ++i) { 5.1278 + Method* mh = methods->at(i); 5.1279 + uintptr_t nv = (uintptr_t)mh->name(); 5.1280 + assert(nv >= prev, "Incorrect overpass method ordering"); 5.1281 + prev = nv; 5.1282 + } 5.1283 +#endif 5.1284 +} 5.1285 + 5.1286 +static void merge_in_new_methods(InstanceKlass* klass, 5.1287 + GrowableArray<Method*>* new_methods, TRAPS) { 5.1288 + 5.1289 + enum { ANNOTATIONS, PARAMETERS, DEFAULTS, NUM_ARRAYS }; 5.1290 + 5.1291 + Array<AnnotationArray*>* original_annots[NUM_ARRAYS]; 5.1292 + 5.1293 + Array<Method*>* original_methods = klass->methods(); 5.1294 + Annotations* annots = klass->annotations(); 5.1295 + original_annots[ANNOTATIONS] = annots->methods_annotations(); 5.1296 + original_annots[PARAMETERS] = annots->methods_parameter_annotations(); 5.1297 + original_annots[DEFAULTS] = annots->methods_default_annotations(); 5.1298 + 5.1299 + Array<int>* original_ordering = klass->method_ordering(); 5.1300 + Array<int>* merged_ordering = Universe::the_empty_int_array(); 5.1301 + 5.1302 + int new_size = klass->methods()->length() + new_methods->length(); 5.1303 + 5.1304 + Array<AnnotationArray*>* merged_annots[NUM_ARRAYS]; 5.1305 + 5.1306 + Array<Method*>* merged_methods = MetadataFactory::new_array<Method*>( 5.1307 + klass->class_loader_data(), new_size, NULL, CHECK); 5.1308 + for (int i = 0; i < NUM_ARRAYS; ++i) { 5.1309 + if (original_annots[i] != NULL) { 5.1310 + merged_annots[i] = MetadataFactory::new_array<AnnotationArray*>( 5.1311 + klass->class_loader_data(), new_size, CHECK); 5.1312 + } else { 5.1313 + merged_annots[i] = NULL; 5.1314 + } 5.1315 + } 5.1316 + if (original_ordering != NULL && original_ordering->length() > 0) { 5.1317 + merged_ordering = MetadataFactory::new_array<int>( 5.1318 + klass->class_loader_data(), new_size, CHECK); 5.1319 + } 5.1320 + int method_order_index = klass->methods()->length(); 5.1321 + 5.1322 + sort_methods(new_methods); 5.1323 + 5.1324 + // Perform grand merge of existing methods and new methods 5.1325 + int orig_idx = 0; 5.1326 + int new_idx = 0; 5.1327 + 5.1328 + for (int i = 0; i < new_size; ++i) { 5.1329 + Method* orig_method = NULL; 5.1330 + Method* new_method = NULL; 5.1331 + if (orig_idx < original_methods->length()) { 5.1332 + orig_method = original_methods->at(orig_idx); 5.1333 + } 5.1334 + if (new_idx < new_methods->length()) { 5.1335 + new_method = new_methods->at(new_idx); 5.1336 + } 5.1337 + 5.1338 + if (orig_method != NULL && 5.1339 + (new_method == NULL || orig_method->name() < new_method->name())) { 5.1340 + merged_methods->at_put(i, orig_method); 5.1341 + original_methods->at_put(orig_idx, NULL); 5.1342 + for (int j = 0; j < NUM_ARRAYS; ++j) { 5.1343 + if (merged_annots[j] != NULL) { 5.1344 + merged_annots[j]->at_put(i, original_annots[j]->at(orig_idx)); 5.1345 + original_annots[j]->at_put(orig_idx, NULL); 5.1346 + } 5.1347 + } 5.1348 + if (merged_ordering->length() > 0) { 5.1349 + merged_ordering->at_put(i, original_ordering->at(orig_idx)); 5.1350 + } 5.1351 + ++orig_idx; 5.1352 + } else { 5.1353 + merged_methods->at_put(i, new_method); 5.1354 + if (merged_ordering->length() > 0) { 5.1355 + merged_ordering->at_put(i, method_order_index++); 5.1356 + } 5.1357 + ++new_idx; 5.1358 + } 5.1359 + // update idnum for new location 5.1360 + merged_methods->at(i)->set_method_idnum(i); 5.1361 + } 5.1362 + 5.1363 + // Verify correct order 5.1364 +#ifdef ASSERT 5.1365 + uintptr_t prev = 0; 5.1366 + for (int i = 0; i < merged_methods->length(); ++i) { 5.1367 + Method* mo = merged_methods->at(i); 5.1368 + uintptr_t nv = (uintptr_t)mo->name(); 5.1369 + assert(nv >= prev, "Incorrect method ordering"); 5.1370 + prev = nv; 5.1371 + } 5.1372 +#endif 5.1373 + 5.1374 + // Replace klass methods with new merged lists 5.1375 + klass->set_methods(merged_methods); 5.1376 + annots->set_methods_annotations(merged_annots[ANNOTATIONS]); 5.1377 + annots->set_methods_parameter_annotations(merged_annots[PARAMETERS]); 5.1378 + annots->set_methods_default_annotations(merged_annots[DEFAULTS]); 5.1379 + 5.1380 + ClassLoaderData* cld = klass->class_loader_data(); 5.1381 + MetadataFactory::free_array(cld, original_methods); 5.1382 + for (int i = 0; i < NUM_ARRAYS; ++i) { 5.1383 + MetadataFactory::free_array(cld, original_annots[i]); 5.1384 + } 5.1385 + if (original_ordering->length() > 0) { 5.1386 + klass->set_method_ordering(merged_ordering); 5.1387 + MetadataFactory::free_array(cld, original_ordering); 5.1388 + } 5.1389 +} 5.1390 +
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/src/share/vm/classfile/defaultMethods.hpp Fri Nov 02 17:18:16 2012 -0700 6.3 @@ -0,0 +1,58 @@ 6.4 +/* 6.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 + * 6.8 + * This code is free software; you can redistribute it and/or modify it 6.9 + * under the terms of the GNU General Public License version 2 only, as 6.10 + * published by the Free Software Foundation. 6.11 + * 6.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 6.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.15 + * version 2 for more details (a copy is included in the LICENSE file that 6.16 + * accompanied this code). 6.17 + * 6.18 + * You should have received a copy of the GNU General Public License version 6.19 + * 2 along with this work; if not, write to the Free Software Foundation, 6.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.21 + * 6.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.23 + * or visit www.oracle.com if you need additional information or have any 6.24 + * questions. 6.25 + * 6.26 + */ 6.27 + 6.28 +#ifndef SHARE_VM_CLASSFILE_DEFAULTMETHODS_HPP 6.29 +#define SHARE_VM_CLASSFILE_DEFAULTMETHODS_HPP 6.30 + 6.31 +#include "runtime/handles.hpp" 6.32 +#include "utilities/growableArray.hpp" 6.33 +#include "utilities/exceptions.hpp" 6.34 + 6.35 +class InstanceKlass; 6.36 +class Symbol; 6.37 +class Method; 6.38 + 6.39 +class DefaultMethods : AllStatic { 6.40 + public: 6.41 + 6.42 + // Analyzes class and determines which default methods are inherited 6.43 + // from interfaces (and has no other implementation). For each method 6.44 + // (and each different signature the method could have), create an 6.45 + // "overpass" method that is an instance method that redirects to the 6.46 + // default method. Overpass methods are added to the methods lists for 6.47 + // the class. 6.48 + static void generate_default_methods( 6.49 + InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS); 6.50 + 6.51 + 6.52 + // Called during linking when an invokespecial to an direct interface 6.53 + // method is found. Selects and returns a method if there is a unique 6.54 + // default method in the 'super_iface' part of the hierarchy which is 6.55 + // also a candidate default for 'this_klass'. Otherwise throws an AME. 6.56 + static Method* find_super_default( 6.57 + Klass* this_klass, Klass* super_iface, 6.58 + Symbol* method_name, Symbol* method_sig, TRAPS); 6.59 +}; 6.60 + 6.61 +#endif // SHARE_VM_CLASSFILE_DEFAULTMETHODS_HPP
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/src/share/vm/classfile/genericSignatures.cpp Fri Nov 02 17:18:16 2012 -0700 7.3 @@ -0,0 +1,1272 @@ 7.4 +/* 7.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 + * 7.8 + * This code is free software; you can redistribute it and/or modify it 7.9 + * under the terms of the GNU General Public License version 2 only, as 7.10 + * published by the Free Software Foundation. 7.11 + * 7.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 7.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.15 + * version 2 for more details (a copy is included in the LICENSE file that 7.16 + * accompanied this code). 7.17 + * 7.18 + * You should have received a copy of the GNU General Public License version 7.19 + * 2 along with this work; if not, write to the Free Software Foundation, 7.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.21 + * 7.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.23 + * or visit www.oracle.com if you need additional information or have any 7.24 + * questions. 7.25 + * 7.26 + */ 7.27 + 7.28 +#include "precompiled.hpp" 7.29 + 7.30 +#include "classfile/genericSignatures.hpp" 7.31 +#include "classfile/symbolTable.hpp" 7.32 +#include "classfile/systemDictionary.hpp" 7.33 +#include "memory/resourceArea.hpp" 7.34 + 7.35 +namespace generic { 7.36 + 7.37 +// Helper class for parsing the generic signature Symbol in klass and methods 7.38 +class DescriptorStream : public ResourceObj { 7.39 + private: 7.40 + Symbol* _symbol; 7.41 + int _offset; 7.42 + int _mark; 7.43 + const char* _parse_error; 7.44 + 7.45 + void set_parse_error(const char* error) { 7.46 + assert(error != NULL, "Can't set NULL error string"); 7.47 + _parse_error = error; 7.48 + } 7.49 + 7.50 + public: 7.51 + DescriptorStream(Symbol* sym) 7.52 + : _symbol(sym), _offset(0), _mark(-1), _parse_error(NULL) {} 7.53 + 7.54 + const char* parse_error() const { 7.55 + return _parse_error; 7.56 + } 7.57 + 7.58 + bool at_end() { return _offset >= _symbol->utf8_length(); } 7.59 + 7.60 + char peek() { 7.61 + if (at_end()) { 7.62 + set_parse_error("Peeking past end of signature"); 7.63 + return '\0'; 7.64 + } else { 7.65 + return _symbol->byte_at(_offset); 7.66 + } 7.67 + } 7.68 + 7.69 + char read() { 7.70 + if (at_end()) { 7.71 + set_parse_error("Reading past end of signature"); 7.72 + return '\0'; 7.73 + } else { 7.74 + return _symbol->byte_at(_offset++); 7.75 + } 7.76 + } 7.77 + 7.78 + void read(char expected) { 7.79 + char c = read(); 7.80 + assert_char(c, expected, 0); 7.81 + } 7.82 + 7.83 + void assert_char(char c, char expected, int pos = -1) { 7.84 + if (c != expected) { 7.85 + const char* fmt = "Parse error at %d: expected %c but got %c"; 7.86 + size_t len = strlen(fmt) + 5; 7.87 + char* buffer = NEW_RESOURCE_ARRAY(char, len); 7.88 + jio_snprintf(buffer, len, fmt, _offset + pos, expected, c); 7.89 + set_parse_error(buffer); 7.90 + } 7.91 + } 7.92 + 7.93 + void push(char c) { 7.94 + assert(c == _symbol->byte_at(_offset - 1), "Pushing back wrong value"); 7.95 + --_offset; 7.96 + } 7.97 + 7.98 + void expect_end() { 7.99 + if (!at_end()) { 7.100 + set_parse_error("Unexpected data trailing signature"); 7.101 + } 7.102 + } 7.103 + 7.104 + bool has_mark() { return _mark != -1; } 7.105 + 7.106 + void set_mark() { 7.107 + _mark = _offset; 7.108 + } 7.109 + 7.110 + Identifier* identifier_from_mark() { 7.111 + assert(has_mark(), "Mark should be set"); 7.112 + if (!has_mark()) { 7.113 + set_parse_error("Expected mark to be set"); 7.114 + return NULL; 7.115 + } else { 7.116 + Identifier* id = new Identifier(_symbol, _mark, _offset - 1); 7.117 + _mark = -1; 7.118 + return id; 7.119 + } 7.120 + } 7.121 +}; 7.122 + 7.123 + 7.124 +#define CHECK_FOR_PARSE_ERROR() \ 7.125 + if (STREAM->parse_error() != NULL) { \ 7.126 + if (VerifyGenericSignatures) { \ 7.127 + fatal(STREAM->parse_error()); \ 7.128 + } \ 7.129 + return NULL; \ 7.130 + } 0 7.131 + 7.132 +#define READ() STREAM->read(); CHECK_FOR_PARSE_ERROR() 7.133 +#define PEEK() STREAM->peek(); CHECK_FOR_PARSE_ERROR() 7.134 +#define PUSH(c) STREAM->push(c) 7.135 +#define EXPECT(c) STREAM->read(c); CHECK_FOR_PARSE_ERROR() 7.136 +#define EXPECTED(c, ch) STREAM->assert_char(c, ch); CHECK_FOR_PARSE_ERROR() 7.137 +#define EXPECT_END() STREAM->expect_end(); CHECK_FOR_PARSE_ERROR() 7.138 + 7.139 +#define CHECK_STREAM STREAM); CHECK_FOR_PARSE_ERROR(); (0 7.140 + 7.141 +#ifndef PRODUCT 7.142 +void Identifier::print_on(outputStream* str) const { 7.143 + for (int i = _begin; i < _end; ++i) { 7.144 + str->print("%c", (char)_sym->byte_at(i)); 7.145 + } 7.146 +} 7.147 +#endif // ndef PRODUCT 7.148 + 7.149 +bool Identifier::equals(Identifier* other) { 7.150 + if (_sym == other->_sym && _begin == other->_begin && _end == other->_end) { 7.151 + return true; 7.152 + } else if (_end - _begin != other->_end - other->_begin) { 7.153 + return false; 7.154 + } else { 7.155 + size_t len = _end - _begin; 7.156 + char* addr = ((char*)_sym->bytes()) + _begin; 7.157 + char* oaddr = ((char*)other->_sym->bytes()) + other->_begin; 7.158 + return strncmp(addr, oaddr, len) == 0; 7.159 + } 7.160 +} 7.161 + 7.162 +bool Identifier::equals(Symbol* sym) { 7.163 + Identifier id(sym, 0, sym->utf8_length()); 7.164 + return equals(&id); 7.165 +} 7.166 + 7.167 +/** 7.168 + * A formal type parameter may be found in the the enclosing class, but it could 7.169 + * also come from an enclosing method or outer class, in the case of inner-outer 7.170 + * classes or anonymous classes. For example: 7.171 + * 7.172 + * class Outer<T,V> { 7.173 + * class Inner<W> { 7.174 + * void m(T t, V v, W w); 7.175 + * } 7.176 + * } 7.177 + * 7.178 + * In this case, the type variables in m()'s signature are not all found in the 7.179 + * immediate enclosing class (Inner). class Inner has only type parameter W, 7.180 + * but it's outer_class field will reference Outer's descriptor which contains 7.181 + * T & V (no outer_method in this case). 7.182 + * 7.183 + * If you have an anonymous class, it has both an enclosing method *and* an 7.184 + * enclosing class where type parameters can be declared: 7.185 + * 7.186 + * class MOuter<T> { 7.187 + * <V> void bar(V v) { 7.188 + * Runnable r = new Runnable() { 7.189 + * public void run() {} 7.190 + * public void foo(T t, V v) { ... } 7.191 + * }; 7.192 + * } 7.193 + * } 7.194 + * 7.195 + * In this case, foo will be a member of some class, Runnable$1, which has no 7.196 + * formal parameters itself, but has an outer_method (bar()) which provides 7.197 + * type parameter V, and an outer class MOuter with type parameter T. 7.198 + * 7.199 + * It is also possible that the outer class is itself an inner class to some 7.200 + * other class (or an anonymous class with an enclosing method), so we need to 7.201 + * follow the outer_class/outer_method chain to it's end when looking for a 7.202 + * type parameter. 7.203 + */ 7.204 +TypeParameter* Descriptor::find_type_parameter(Identifier* id, int* depth) { 7.205 + 7.206 + int current_depth = 0; 7.207 + 7.208 + MethodDescriptor* outer_method = as_method_signature(); 7.209 + ClassDescriptor* outer_class = as_class_signature(); 7.210 + 7.211 + if (outer_class == NULL) { // 'this' is a method signature; use the holder 7.212 + outer_class = outer_method->outer_class(); 7.213 + } 7.214 + 7.215 + while (outer_method != NULL || outer_class != NULL) { 7.216 + if (outer_method != NULL) { 7.217 + for (int i = 0; i < outer_method->type_parameters().length(); ++i) { 7.218 + TypeParameter* p = outer_method->type_parameters().at(i); 7.219 + if (p->identifier()->equals(id)) { 7.220 + *depth = -1; // indicates this this is a method parameter 7.221 + return p; 7.222 + } 7.223 + } 7.224 + } 7.225 + if (outer_class != NULL) { 7.226 + for (int i = 0; i < outer_class->type_parameters().length(); ++i) { 7.227 + TypeParameter* p = outer_class->type_parameters().at(i); 7.228 + if (p->identifier()->equals(id)) { 7.229 + *depth = current_depth; 7.230 + return p; 7.231 + } 7.232 + } 7.233 + outer_method = outer_class->outer_method(); 7.234 + outer_class = outer_class->outer_class(); 7.235 + ++current_depth; 7.236 + } 7.237 + } 7.238 + 7.239 + if (VerifyGenericSignatures) { 7.240 + fatal("Could not resolve identifier"); 7.241 + } 7.242 + 7.243 + return NULL; 7.244 +} 7.245 + 7.246 +ClassDescriptor* ClassDescriptor::parse_generic_signature(Klass* klass, TRAPS) { 7.247 + return parse_generic_signature(klass, NULL, CHECK_NULL); 7.248 +} 7.249 + 7.250 +ClassDescriptor* ClassDescriptor::parse_generic_signature( 7.251 + Klass* klass, Symbol* original_name, TRAPS) { 7.252 + 7.253 + InstanceKlass* ik = InstanceKlass::cast(klass); 7.254 + Symbol* sym = ik->generic_signature(); 7.255 + 7.256 + ClassDescriptor* spec; 7.257 + 7.258 + if (sym == NULL || (spec = ClassDescriptor::parse_generic_signature(sym)) == NULL) { 7.259 + spec = ClassDescriptor::placeholder(ik); 7.260 + } 7.261 + 7.262 + u2 outer_index = get_outer_class_index(ik, CHECK_NULL); 7.263 + if (outer_index != 0) { 7.264 + if (original_name == NULL) { 7.265 + original_name = ik->name(); 7.266 + } 7.267 + Handle class_loader = Handle(THREAD, ik->class_loader()); 7.268 + Handle protection_domain = Handle(THREAD, ik->protection_domain()); 7.269 + 7.270 + Symbol* outer_name = ik->constants()->klass_name_at(outer_index); 7.271 + Klass* outer = SystemDictionary::find( 7.272 + outer_name, class_loader, protection_domain, CHECK_NULL); 7.273 + if (outer == NULL && !THREAD->is_Compiler_thread()) { 7.274 + outer = SystemDictionary::resolve_super_or_fail(original_name, 7.275 + outer_name, class_loader, protection_domain, false, CHECK_NULL); 7.276 + } 7.277 + 7.278 + InstanceKlass* outer_ik; 7.279 + ClassDescriptor* outer_spec = NULL; 7.280 + if (outer == NULL) { 7.281 + outer_spec = ClassDescriptor::placeholder(ik); 7.282 + assert(false, "Outer class not loaded and not loadable from here"); 7.283 + } else { 7.284 + outer_ik = InstanceKlass::cast(outer); 7.285 + outer_spec = parse_generic_signature(outer, original_name, CHECK_NULL); 7.286 + } 7.287 + spec->set_outer_class(outer_spec); 7.288 + 7.289 + u2 encl_method_idx = ik->enclosing_method_method_index(); 7.290 + if (encl_method_idx != 0 && outer_ik != NULL) { 7.291 + ConstantPool* cp = ik->constants(); 7.292 + u2 name_index = cp->name_ref_index_at(encl_method_idx); 7.293 + u2 sig_index = cp->signature_ref_index_at(encl_method_idx); 7.294 + Symbol* name = cp->symbol_at(name_index); 7.295 + Symbol* sig = cp->symbol_at(sig_index); 7.296 + Method* m = outer_ik->find_method(name, sig); 7.297 + if (m != NULL) { 7.298 + Symbol* gsig = m->generic_signature(); 7.299 + if (gsig != NULL) { 7.300 + MethodDescriptor* gms = MethodDescriptor::parse_generic_signature(gsig, outer_spec); 7.301 + spec->set_outer_method(gms); 7.302 + } 7.303 + } else if (VerifyGenericSignatures) { 7.304 + ResourceMark rm; 7.305 + stringStream ss; 7.306 + ss.print("Could not find method %s %s in class %s", 7.307 + name->as_C_string(), sig->as_C_string(), outer_name->as_C_string()); 7.308 + fatal(ss.as_string()); 7.309 + } 7.310 + } 7.311 + } 7.312 + 7.313 + spec->bind_variables_to_parameters(); 7.314 + return spec; 7.315 +} 7.316 + 7.317 +ClassDescriptor* ClassDescriptor::placeholder(InstanceKlass* klass) { 7.318 + GrowableArray<TypeParameter*> formals; 7.319 + GrowableArray<ClassType*> interfaces; 7.320 + ClassType* super_type = NULL; 7.321 + 7.322 + Klass* super_klass = klass->super(); 7.323 + if (super_klass != NULL) { 7.324 + InstanceKlass* super = InstanceKlass::cast(super_klass); 7.325 + super_type = ClassType::from_symbol(super->name()); 7.326 + } 7.327 + 7.328 + for (int i = 0; i < klass->local_interfaces()->length(); ++i) { 7.329 + InstanceKlass* iface = InstanceKlass::cast(klass->local_interfaces()->at(i)); 7.330 + interfaces.append(ClassType::from_symbol(iface->name())); 7.331 + } 7.332 + return new ClassDescriptor(formals, super_type, interfaces); 7.333 +} 7.334 + 7.335 +ClassDescriptor* ClassDescriptor::parse_generic_signature(Symbol* sym) { 7.336 + 7.337 + DescriptorStream ds(sym); 7.338 + DescriptorStream* STREAM = &ds; 7.339 + 7.340 + GrowableArray<TypeParameter*> parameters(8); 7.341 + char c = READ(); 7.342 + if (c == '<') { 7.343 + c = READ(); 7.344 + while (c != '>') { 7.345 + PUSH(c); 7.346 + TypeParameter* ftp = TypeParameter::parse_generic_signature(CHECK_STREAM); 7.347 + parameters.append(ftp); 7.348 + c = READ(); 7.349 + } 7.350 + } else { 7.351 + PUSH(c); 7.352 + } 7.353 + 7.354 + EXPECT('L'); 7.355 + ClassType* super = ClassType::parse_generic_signature(CHECK_STREAM); 7.356 + 7.357 + GrowableArray<ClassType*> signatures(2); 7.358 + while (!STREAM->at_end()) { 7.359 + EXPECT('L'); 7.360 + ClassType* iface = ClassType::parse_generic_signature(CHECK_STREAM); 7.361 + signatures.append(iface); 7.362 + } 7.363 + 7.364 + EXPECT_END(); 7.365 + 7.366 + return new ClassDescriptor(parameters, super, signatures); 7.367 +} 7.368 + 7.369 +#ifndef PRODUCT 7.370 +void ClassDescriptor::print_on(outputStream* str) const { 7.371 + str->indent().print_cr("ClassDescriptor {"); 7.372 + { 7.373 + streamIndentor si(str); 7.374 + if (_type_parameters.length() > 0) { 7.375 + str->indent().print_cr("Formals {"); 7.376 + { 7.377 + streamIndentor si(str); 7.378 + for (int i = 0; i < _type_parameters.length(); ++i) { 7.379 + _type_parameters.at(i)->print_on(str); 7.380 + } 7.381 + } 7.382 + str->indent().print_cr("}"); 7.383 + } 7.384 + if (_super != NULL) { 7.385 + str->indent().print_cr("Superclass: "); 7.386 + { 7.387 + streamIndentor si(str); 7.388 + _super->print_on(str); 7.389 + } 7.390 + } 7.391 + if (_interfaces.length() > 0) { 7.392 + str->indent().print_cr("SuperInterfaces: {"); 7.393 + { 7.394 + streamIndentor si(str); 7.395 + for (int i = 0; i < _interfaces.length(); ++i) { 7.396 + _interfaces.at(i)->print_on(str); 7.397 + } 7.398 + } 7.399 + str->indent().print_cr("}"); 7.400 + } 7.401 + if (_outer_method != NULL) { 7.402 + str->indent().print_cr("Outer Method: {"); 7.403 + { 7.404 + streamIndentor si(str); 7.405 + _outer_method->print_on(str); 7.406 + } 7.407 + str->indent().print_cr("}"); 7.408 + } 7.409 + if (_outer_class != NULL) { 7.410 + str->indent().print_cr("Outer Class: {"); 7.411 + { 7.412 + streamIndentor si(str); 7.413 + _outer_class->print_on(str); 7.414 + } 7.415 + str->indent().print_cr("}"); 7.416 + } 7.417 + } 7.418 + str->indent().print_cr("}"); 7.419 +} 7.420 +#endif // ndef PRODUCT 7.421 + 7.422 +ClassType* ClassDescriptor::interface_desc(Symbol* sym) { 7.423 + for (int i = 0; i < _interfaces.length(); ++i) { 7.424 + if (_interfaces.at(i)->identifier()->equals(sym)) { 7.425 + return _interfaces.at(i); 7.426 + } 7.427 + } 7.428 + if (VerifyGenericSignatures) { 7.429 + fatal("Did not find expected interface"); 7.430 + } 7.431 + return NULL; 7.432 +} 7.433 + 7.434 +void ClassDescriptor::bind_variables_to_parameters() { 7.435 + if (_outer_class != NULL) { 7.436 + _outer_class->bind_variables_to_parameters(); 7.437 + } 7.438 + if (_outer_method != NULL) { 7.439 + _outer_method->bind_variables_to_parameters(); 7.440 + } 7.441 + for (int i = 0; i < _type_parameters.length(); ++i) { 7.442 + _type_parameters.at(i)->bind_variables_to_parameters(this, i); 7.443 + } 7.444 + if (_super != NULL) { 7.445 + _super->bind_variables_to_parameters(this); 7.446 + } 7.447 + for (int i = 0; i < _interfaces.length(); ++i) { 7.448 + _interfaces.at(i)->bind_variables_to_parameters(this); 7.449 + } 7.450 +} 7.451 + 7.452 +ClassDescriptor* ClassDescriptor::canonicalize(Context* ctx) { 7.453 + 7.454 + GrowableArray<TypeParameter*> type_params(_type_parameters.length()); 7.455 + for (int i = 0; i < _type_parameters.length(); ++i) { 7.456 + type_params.append(_type_parameters.at(i)->canonicalize(ctx, 0)); 7.457 + } 7.458 + 7.459 + ClassDescriptor* outer = _outer_class == NULL ? NULL : 7.460 + _outer_class->canonicalize(ctx); 7.461 + 7.462 + ClassType* super = _super == NULL ? NULL : _super->canonicalize(ctx, 0); 7.463 + 7.464 + GrowableArray<ClassType*> interfaces(_interfaces.length()); 7.465 + for (int i = 0; i < _interfaces.length(); ++i) { 7.466 + interfaces.append(_interfaces.at(i)->canonicalize(ctx, 0)); 7.467 + } 7.468 + 7.469 + MethodDescriptor* md = _outer_method == NULL ? NULL : 7.470 + _outer_method->canonicalize(ctx); 7.471 + 7.472 + return new ClassDescriptor(type_params, super, interfaces, outer, md); 7.473 +} 7.474 + 7.475 +u2 ClassDescriptor::get_outer_class_index(InstanceKlass* klass, TRAPS) { 7.476 + int inner_index = InstanceKlass::inner_class_inner_class_info_offset; 7.477 + int outer_index = InstanceKlass::inner_class_outer_class_info_offset; 7.478 + int name_offset = InstanceKlass::inner_class_inner_name_offset; 7.479 + int next_offset = InstanceKlass::inner_class_next_offset; 7.480 + 7.481 + if (klass->inner_classes() == NULL || klass->inner_classes()->length() == 0) { 7.482 + // No inner class info => no declaring class 7.483 + return 0; 7.484 + } 7.485 + 7.486 + Array<u2>* i_icls = klass->inner_classes(); 7.487 + ConstantPool* i_cp = klass->constants(); 7.488 + int i_length = i_icls->length(); 7.489 + 7.490 + // Find inner_klass attribute 7.491 + for (int i = 0; i + next_offset < i_length; i += next_offset) { 7.492 + u2 ioff = i_icls->at(i + inner_index); 7.493 + u2 ooff = i_icls->at(i + outer_index); 7.494 + u2 noff = i_icls->at(i + name_offset); 7.495 + if (ioff != 0) { 7.496 + // Check to see if the name matches the class we're looking for 7.497 + // before attempting to find the class. 7.498 + if (i_cp->klass_name_at_matches(klass, ioff) && ooff != 0) { 7.499 + return ooff; 7.500 + } 7.501 + } 7.502 + } 7.503 + 7.504 + // It may be anonymous; try for that. 7.505 + u2 encl_method_class_idx = klass->enclosing_method_class_index(); 7.506 + if (encl_method_class_idx != 0) { 7.507 + return encl_method_class_idx; 7.508 + } 7.509 + 7.510 + return 0; 7.511 +} 7.512 + 7.513 +MethodDescriptor* MethodDescriptor::parse_generic_signature(Method* m, ClassDescriptor* outer) { 7.514 + Symbol* generic_sig = m->generic_signature(); 7.515 + MethodDescriptor* md = NULL; 7.516 + if (generic_sig == NULL || (md = parse_generic_signature(generic_sig, outer)) == NULL) { 7.517 + md = parse_generic_signature(m->signature(), outer); 7.518 + } 7.519 + assert(md != NULL, "Could not parse method signature"); 7.520 + md->bind_variables_to_parameters(); 7.521 + return md; 7.522 +} 7.523 + 7.524 +MethodDescriptor* MethodDescriptor::parse_generic_signature(Symbol* sym, ClassDescriptor* outer) { 7.525 + 7.526 + DescriptorStream ds(sym); 7.527 + DescriptorStream* STREAM = &ds; 7.528 + 7.529 + GrowableArray<TypeParameter*> params(8); 7.530 + char c = READ(); 7.531 + if (c == '<') { 7.532 + c = READ(); 7.533 + while (c != '>') { 7.534 + PUSH(c); 7.535 + TypeParameter* ftp = TypeParameter::parse_generic_signature(CHECK_STREAM); 7.536 + params.append(ftp); 7.537 + c = READ(); 7.538 + } 7.539 + } else { 7.540 + PUSH(c); 7.541 + } 7.542 + 7.543 + EXPECT('('); 7.544 + 7.545 + GrowableArray<Type*> parameters(8); 7.546 + c = READ(); 7.547 + while (c != ')') { 7.548 + PUSH(c); 7.549 + Type* arg = Type::parse_generic_signature(CHECK_STREAM); 7.550 + parameters.append(arg); 7.551 + c = READ(); 7.552 + } 7.553 + 7.554 + Type* rt = Type::parse_generic_signature(CHECK_STREAM); 7.555 + 7.556 + GrowableArray<Type*> throws; 7.557 + while (!STREAM->at_end()) { 7.558 + EXPECT('^'); 7.559 + Type* spec = Type::parse_generic_signature(CHECK_STREAM); 7.560 + throws.append(spec); 7.561 + } 7.562 + 7.563 + return new MethodDescriptor(params, outer, parameters, rt, throws); 7.564 +} 7.565 + 7.566 +void MethodDescriptor::bind_variables_to_parameters() { 7.567 + for (int i = 0; i < _type_parameters.length(); ++i) { 7.568 + _type_parameters.at(i)->bind_variables_to_parameters(this, i); 7.569 + } 7.570 + for (int i = 0; i < _parameters.length(); ++i) { 7.571 + _parameters.at(i)->bind_variables_to_parameters(this); 7.572 + } 7.573 + _return_type->bind_variables_to_parameters(this); 7.574 + for (int i = 0; i < _throws.length(); ++i) { 7.575 + _throws.at(i)->bind_variables_to_parameters(this); 7.576 + } 7.577 +} 7.578 + 7.579 +bool MethodDescriptor::covariant_match(MethodDescriptor* other, Context* ctx) { 7.580 + 7.581 + if (_parameters.length() == other->_parameters.length()) { 7.582 + for (int i = 0; i < _parameters.length(); ++i) { 7.583 + if (!_parameters.at(i)->covariant_match(other->_parameters.at(i), ctx)) { 7.584 + return false; 7.585 + } 7.586 + } 7.587 + 7.588 + if (_return_type->as_primitive() != NULL) { 7.589 + return _return_type->covariant_match(other->_return_type, ctx); 7.590 + } else { 7.591 + // return type is a reference 7.592 + return other->_return_type->as_class() != NULL || 7.593 + other->_return_type->as_variable() != NULL || 7.594 + other->_return_type->as_array() != NULL; 7.595 + } 7.596 + } else { 7.597 + return false; 7.598 + } 7.599 +} 7.600 + 7.601 +MethodDescriptor* MethodDescriptor::canonicalize(Context* ctx) { 7.602 + 7.603 + GrowableArray<TypeParameter*> type_params(_type_parameters.length()); 7.604 + for (int i = 0; i < _type_parameters.length(); ++i) { 7.605 + type_params.append(_type_parameters.at(i)->canonicalize(ctx, 0)); 7.606 + } 7.607 + 7.608 + ClassDescriptor* outer = _outer_class == NULL ? NULL : 7.609 + _outer_class->canonicalize(ctx); 7.610 + 7.611 + GrowableArray<Type*> params(_parameters.length()); 7.612 + for (int i = 0; i < _parameters.length(); ++i) { 7.613 + params.append(_parameters.at(i)->canonicalize(ctx, 0)); 7.614 + } 7.615 + 7.616 + Type* rt = _return_type->canonicalize(ctx, 0); 7.617 + 7.618 + GrowableArray<Type*> throws(_throws.length()); 7.619 + for (int i = 0; i < _throws.length(); ++i) { 7.620 + throws.append(_throws.at(i)->canonicalize(ctx, 0)); 7.621 + } 7.622 + 7.623 + return new MethodDescriptor(type_params, outer, params, rt, throws); 7.624 +} 7.625 + 7.626 +#ifndef PRODUCT 7.627 +TempNewSymbol MethodDescriptor::reify_signature(Context* ctx, TRAPS) { 7.628 + stringStream ss(256); 7.629 + 7.630 + ss.print("("); 7.631 + for (int i = 0; i < _parameters.length(); ++i) { 7.632 + _parameters.at(i)->reify_signature(&ss, ctx); 7.633 + } 7.634 + ss.print(")"); 7.635 + _return_type->reify_signature(&ss, ctx); 7.636 + return SymbolTable::new_symbol(ss.base(), (int)ss.size(), THREAD); 7.637 +} 7.638 + 7.639 +void MethodDescriptor::print_on(outputStream* str) const { 7.640 + str->indent().print_cr("MethodDescriptor {"); 7.641 + { 7.642 + streamIndentor si(str); 7.643 + if (_type_parameters.length() > 0) { 7.644 + str->indent().print_cr("Formals: {"); 7.645 + { 7.646 + streamIndentor si(str); 7.647 + for (int i = 0; i < _type_parameters.length(); ++i) { 7.648 + _type_parameters.at(i)->print_on(str); 7.649 + } 7.650 + } 7.651 + str->indent().print_cr("}"); 7.652 + } 7.653 + str->indent().print_cr("Parameters: {"); 7.654 + { 7.655 + streamIndentor si(str); 7.656 + for (int i = 0; i < _parameters.length(); ++i) { 7.657 + _parameters.at(i)->print_on(str); 7.658 + } 7.659 + } 7.660 + str->indent().print_cr("}"); 7.661 + str->indent().print_cr("Return Type: "); 7.662 + { 7.663 + streamIndentor si(str); 7.664 + _return_type->print_on(str); 7.665 + } 7.666 + 7.667 + if (_throws.length() > 0) { 7.668 + str->indent().print_cr("Throws: {"); 7.669 + { 7.670 + streamIndentor si(str); 7.671 + for (int i = 0; i < _throws.length(); ++i) { 7.672 + _throws.at(i)->print_on(str); 7.673 + } 7.674 + } 7.675 + str->indent().print_cr("}"); 7.676 + } 7.677 + } 7.678 + str->indent().print_cr("}"); 7.679 +} 7.680 +#endif // ndef PRODUCT 7.681 + 7.682 +TypeParameter* TypeParameter::parse_generic_signature(DescriptorStream* STREAM) { 7.683 + STREAM->set_mark(); 7.684 + char c = READ(); 7.685 + while (c != ':') { 7.686 + c = READ(); 7.687 + } 7.688 + 7.689 + Identifier* id = STREAM->identifier_from_mark(); 7.690 + 7.691 + ClassType* class_bound = NULL; 7.692 + GrowableArray<ClassType*> interface_bounds(8); 7.693 + 7.694 + c = READ(); 7.695 + if (c != '>') { 7.696 + if (c != ':') { 7.697 + EXPECTED(c, 'L'); 7.698 + class_bound = ClassType::parse_generic_signature(CHECK_STREAM); 7.699 + c = READ(); 7.700 + } 7.701 + 7.702 + while (c == ':') { 7.703 + EXPECT('L'); 7.704 + ClassType* fts = ClassType::parse_generic_signature(CHECK_STREAM); 7.705 + interface_bounds.append(fts); 7.706 + c = READ(); 7.707 + } 7.708 + } 7.709 + PUSH(c); 7.710 + 7.711 + return new TypeParameter(id, class_bound, interface_bounds); 7.712 +} 7.713 + 7.714 +void TypeParameter::bind_variables_to_parameters(Descriptor* sig, int position) { 7.715 + if (_class_bound != NULL) { 7.716 + _class_bound->bind_variables_to_parameters(sig); 7.717 + } 7.718 + for (int i = 0; i < _interface_bounds.length(); ++i) { 7.719 + _interface_bounds.at(i)->bind_variables_to_parameters(sig); 7.720 + } 7.721 + _position = position; 7.722 +} 7.723 + 7.724 +Type* TypeParameter::resolve( 7.725 + Context* ctx, int inner_depth, int ctx_depth) { 7.726 + 7.727 + if (inner_depth == -1) { 7.728 + // This indicates that the parameter is a method type parameter, which 7.729 + // isn't resolveable using the class hierarchy context 7.730 + return bound(); 7.731 + } 7.732 + 7.733 + ClassType* provider = ctx->at_depth(ctx_depth); 7.734 + if (provider != NULL) { 7.735 + for (int i = 0; i < inner_depth && provider != NULL; ++i) { 7.736 + provider = provider->outer_class(); 7.737 + } 7.738 + if (provider != NULL) { 7.739 + TypeArgument* arg = provider->type_argument_at(_position); 7.740 + if (arg != NULL) { 7.741 + Type* value = arg->lower_bound(); 7.742 + return value->canonicalize(ctx, ctx_depth + 1); 7.743 + } 7.744 + } 7.745 + } 7.746 + 7.747 + return bound(); 7.748 +} 7.749 + 7.750 +TypeParameter* TypeParameter::canonicalize(Context* ctx, int ctx_depth) { 7.751 + ClassType* bound = _class_bound == NULL ? NULL : 7.752 + _class_bound->canonicalize(ctx, ctx_depth); 7.753 + 7.754 + GrowableArray<ClassType*> ifaces(_interface_bounds.length()); 7.755 + for (int i = 0; i < _interface_bounds.length(); ++i) { 7.756 + ifaces.append(_interface_bounds.at(i)->canonicalize(ctx, ctx_depth)); 7.757 + } 7.758 + 7.759 + TypeParameter* ret = new TypeParameter(_identifier, bound, ifaces); 7.760 + ret->_position = _position; 7.761 + return ret; 7.762 +} 7.763 + 7.764 +ClassType* TypeParameter::bound() { 7.765 + if (_class_bound != NULL) { 7.766 + return _class_bound; 7.767 + } 7.768 + 7.769 + if (_interface_bounds.length() == 1) { 7.770 + return _interface_bounds.at(0); 7.771 + } 7.772 + 7.773 + return ClassType::java_lang_Object(); // TODO: investigate this case 7.774 +} 7.775 + 7.776 +#ifndef PRODUCT 7.777 +void TypeParameter::print_on(outputStream* str) const { 7.778 + str->indent().print_cr("Formal: {"); 7.779 + { 7.780 + streamIndentor si(str); 7.781 + 7.782 + str->indent().print("Identifier: "); 7.783 + _identifier->print_on(str); 7.784 + str->print_cr(""); 7.785 + if (_class_bound != NULL) { 7.786 + str->indent().print_cr("Class Bound: "); 7.787 + streamIndentor si(str); 7.788 + _class_bound->print_on(str); 7.789 + } 7.790 + if (_interface_bounds.length() > 0) { 7.791 + str->indent().print_cr("Interface Bounds: {"); 7.792 + { 7.793 + streamIndentor si(str); 7.794 + for (int i = 0; i < _interface_bounds.length(); ++i) { 7.795 + _interface_bounds.at(i)->print_on(str); 7.796 + } 7.797 + } 7.798 + str->indent().print_cr("}"); 7.799 + } 7.800 + str->indent().print_cr("Ordinal Position: %d", _position); 7.801 + } 7.802 + str->indent().print_cr("}"); 7.803 +} 7.804 +#endif // ndef PRODUCT 7.805 + 7.806 +Type* Type::parse_generic_signature(DescriptorStream* STREAM) { 7.807 + char c = READ(); 7.808 + switch (c) { 7.809 + case 'L': 7.810 + return ClassType::parse_generic_signature(CHECK_STREAM); 7.811 + case 'T': 7.812 + return TypeVariable::parse_generic_signature(CHECK_STREAM); 7.813 + case '[': 7.814 + return ArrayType::parse_generic_signature(CHECK_STREAM); 7.815 + default: 7.816 + return new PrimitiveType(c); 7.817 + } 7.818 +} 7.819 + 7.820 +Identifier* ClassType::parse_generic_signature_simple(GrowableArray<TypeArgument*>* args, 7.821 + bool* has_inner, DescriptorStream* STREAM) { 7.822 + STREAM->set_mark(); 7.823 + 7.824 + char c = READ(); 7.825 + while (c != ';' && c != '.' && c != '<') { c = READ(); } 7.826 + Identifier* id = STREAM->identifier_from_mark(); 7.827 + 7.828 + if (c == '<') { 7.829 + c = READ(); 7.830 + while (c != '>') { 7.831 + PUSH(c); 7.832 + TypeArgument* arg = TypeArgument::parse_generic_signature(CHECK_STREAM); 7.833 + args->append(arg); 7.834 + c = READ(); 7.835 + } 7.836 + c = READ(); 7.837 + } 7.838 + 7.839 + *has_inner = (c == '.'); 7.840 + if (!(*has_inner)) { 7.841 + EXPECTED(c, ';'); 7.842 + } 7.843 + 7.844 + return id; 7.845 +} 7.846 + 7.847 +ClassType* ClassType::parse_generic_signature(DescriptorStream* STREAM) { 7.848 + return parse_generic_signature(NULL, CHECK_STREAM); 7.849 +} 7.850 + 7.851 +ClassType* ClassType::parse_generic_signature(ClassType* outer, DescriptorStream* STREAM) { 7.852 + GrowableArray<TypeArgument*> args; 7.853 + ClassType* gct = NULL; 7.854 + bool has_inner = false; 7.855 + 7.856 + Identifier* id = parse_generic_signature_simple(&args, &has_inner, STREAM); 7.857 + if (id != NULL) { 7.858 + gct = new ClassType(id, args, outer); 7.859 + 7.860 + if (has_inner) { 7.861 + gct = parse_generic_signature(gct, CHECK_STREAM); 7.862 + } 7.863 + } 7.864 + return gct; 7.865 +} 7.866 + 7.867 +ClassType* ClassType::from_symbol(Symbol* sym) { 7.868 + assert(sym != NULL, "Must not be null"); 7.869 + GrowableArray<TypeArgument*> args; 7.870 + Identifier* id = new Identifier(sym, 0, sym->utf8_length()); 7.871 + return new ClassType(id, args, NULL); 7.872 +} 7.873 + 7.874 +ClassType* ClassType::java_lang_Object() { 7.875 + return from_symbol(vmSymbols::java_lang_Object()); 7.876 +} 7.877 + 7.878 +void ClassType::bind_variables_to_parameters(Descriptor* sig) { 7.879 + for (int i = 0; i < _type_arguments.length(); ++i) { 7.880 + _type_arguments.at(i)->bind_variables_to_parameters(sig); 7.881 + } 7.882 + if (_outer_class != NULL) { 7.883 + _outer_class->bind_variables_to_parameters(sig); 7.884 + } 7.885 +} 7.886 + 7.887 +TypeArgument* ClassType::type_argument_at(int i) { 7.888 + if (i >= 0 && i < _type_arguments.length()) { 7.889 + return _type_arguments.at(i); 7.890 + } else { 7.891 + return NULL; 7.892 + } 7.893 +} 7.894 + 7.895 +#ifndef PRODUCT 7.896 +void ClassType::reify_signature(stringStream* ss, Context* ctx) { 7.897 + ss->print("L"); 7.898 + _identifier->print_on(ss); 7.899 + ss->print(";"); 7.900 +} 7.901 + 7.902 +void ClassType::print_on(outputStream* str) const { 7.903 + str->indent().print_cr("Class {"); 7.904 + { 7.905 + streamIndentor si(str); 7.906 + str->indent().print("Name: "); 7.907 + _identifier->print_on(str); 7.908 + str->print_cr(""); 7.909 + if (_type_arguments.length() != 0) { 7.910 + str->indent().print_cr("Type Arguments: {"); 7.911 + { 7.912 + streamIndentor si(str); 7.913 + for (int j = 0; j < _type_arguments.length(); ++j) { 7.914 + _type_arguments.at(j)->print_on(str); 7.915 + } 7.916 + } 7.917 + str->indent().print_cr("}"); 7.918 + } 7.919 + if (_outer_class != NULL) { 7.920 + str->indent().print_cr("Outer Class: "); 7.921 + streamIndentor sir(str); 7.922 + _outer_class->print_on(str); 7.923 + } 7.924 + } 7.925 + str->indent().print_cr("}"); 7.926 +} 7.927 +#endif // ndef PRODUCT 7.928 + 7.929 +bool ClassType::covariant_match(Type* other, Context* ctx) { 7.930 + 7.931 + if (other == this) { 7.932 + return true; 7.933 + } 7.934 + 7.935 + TypeVariable* variable = other->as_variable(); 7.936 + if (variable != NULL) { 7.937 + other = variable->resolve(ctx, 0); 7.938 + } 7.939 + 7.940 + ClassType* outer = outer_class(); 7.941 + ClassType* other_class = other->as_class(); 7.942 + 7.943 + if (other_class == NULL || 7.944 + (outer == NULL) != (other_class->outer_class() == NULL)) { 7.945 + return false; 7.946 + } 7.947 + 7.948 + if (!_identifier->equals(other_class->_identifier)) { 7.949 + return false; 7.950 + } 7.951 + 7.952 + if (outer != NULL && !outer->covariant_match(other_class->outer_class(), ctx)) { 7.953 + return false; 7.954 + } 7.955 + 7.956 + return true; 7.957 +} 7.958 + 7.959 +ClassType* ClassType::canonicalize(Context* ctx, int ctx_depth) { 7.960 + 7.961 + GrowableArray<TypeArgument*> args(_type_arguments.length()); 7.962 + for (int i = 0; i < _type_arguments.length(); ++i) { 7.963 + args.append(_type_arguments.at(i)->canonicalize(ctx, ctx_depth)); 7.964 + } 7.965 + 7.966 + ClassType* outer = _outer_class == NULL ? NULL : 7.967 + _outer_class->canonicalize(ctx, ctx_depth); 7.968 + 7.969 + return new ClassType(_identifier, args, outer); 7.970 +} 7.971 + 7.972 +TypeVariable* TypeVariable::parse_generic_signature(DescriptorStream* STREAM) { 7.973 + STREAM->set_mark(); 7.974 + char c = READ(); 7.975 + while (c != ';') { 7.976 + c = READ(); 7.977 + } 7.978 + Identifier* id = STREAM->identifier_from_mark(); 7.979 + 7.980 + return new TypeVariable(id); 7.981 +} 7.982 + 7.983 +void TypeVariable::bind_variables_to_parameters(Descriptor* sig) { 7.984 + _parameter = sig->find_type_parameter(_id, &_inner_depth); 7.985 + if (VerifyGenericSignatures && _parameter == NULL) { 7.986 + fatal("Could not find formal parameter"); 7.987 + } 7.988 +} 7.989 + 7.990 +Type* TypeVariable::resolve(Context* ctx, int ctx_depth) { 7.991 + if (parameter() != NULL) { 7.992 + return parameter()->resolve(ctx, inner_depth(), ctx_depth); 7.993 + } else { 7.994 + if (VerifyGenericSignatures) { 7.995 + fatal("Type variable matches no parameter"); 7.996 + } 7.997 + return NULL; 7.998 + } 7.999 +} 7.1000 + 7.1001 +bool TypeVariable::covariant_match(Type* other, Context* ctx) { 7.1002 + 7.1003 + if (other == this) { 7.1004 + return true; 7.1005 + } 7.1006 + 7.1007 + Context my_context(NULL); // empty, results in erasure 7.1008 + Type* my_type = resolve(&my_context, 0); 7.1009 + if (my_type == NULL) { 7.1010 + return false; 7.1011 + } 7.1012 + 7.1013 + return my_type->covariant_match(other, ctx); 7.1014 +} 7.1015 + 7.1016 +Type* TypeVariable::canonicalize(Context* ctx, int ctx_depth) { 7.1017 + return resolve(ctx, ctx_depth); 7.1018 +} 7.1019 + 7.1020 +#ifndef PRODUCT 7.1021 +void TypeVariable::reify_signature(stringStream* ss, Context* ctx) { 7.1022 + Type* type = resolve(ctx, 0); 7.1023 + if (type != NULL) { 7.1024 + type->reify_signature(ss, ctx); 7.1025 + } 7.1026 +} 7.1027 + 7.1028 +void TypeVariable::print_on(outputStream* str) const { 7.1029 + str->indent().print_cr("Type Variable {"); 7.1030 + { 7.1031 + streamIndentor si(str); 7.1032 + str->indent().print("Name: "); 7.1033 + _id->print_on(str); 7.1034 + str->print_cr(""); 7.1035 + str->indent().print_cr("Inner depth: %d", _inner_depth); 7.1036 + } 7.1037 + str->indent().print_cr("}"); 7.1038 +} 7.1039 +#endif // ndef PRODUCT 7.1040 + 7.1041 +ArrayType* ArrayType::parse_generic_signature(DescriptorStream* STREAM) { 7.1042 + Type* base = Type::parse_generic_signature(CHECK_STREAM); 7.1043 + return new ArrayType(base); 7.1044 +} 7.1045 + 7.1046 +void ArrayType::bind_variables_to_parameters(Descriptor* sig) { 7.1047 + assert(_base != NULL, "Invalid base"); 7.1048 + _base->bind_variables_to_parameters(sig); 7.1049 +} 7.1050 + 7.1051 +bool ArrayType::covariant_match(Type* other, Context* ctx) { 7.1052 + assert(_base != NULL, "Invalid base"); 7.1053 + 7.1054 + if (other == this) { 7.1055 + return true; 7.1056 + } 7.1057 + 7.1058 + ArrayType* other_array = other->as_array(); 7.1059 + return (other_array != NULL && _base->covariant_match(other_array->_base, ctx)); 7.1060 +} 7.1061 + 7.1062 +ArrayType* ArrayType::canonicalize(Context* ctx, int ctx_depth) { 7.1063 + assert(_base != NULL, "Invalid base"); 7.1064 + return new ArrayType(_base->canonicalize(ctx, ctx_depth)); 7.1065 +} 7.1066 + 7.1067 +#ifndef PRODUCT 7.1068 +void ArrayType::reify_signature(stringStream* ss, Context* ctx) { 7.1069 + assert(_base != NULL, "Invalid base"); 7.1070 + ss->print("["); 7.1071 + _base->reify_signature(ss, ctx); 7.1072 +} 7.1073 + 7.1074 +void ArrayType::print_on(outputStream* str) const { 7.1075 + str->indent().print_cr("Array {"); 7.1076 + { 7.1077 + streamIndentor si(str); 7.1078 + _base->print_on(str); 7.1079 + } 7.1080 + str->indent().print_cr("}"); 7.1081 +} 7.1082 +#endif // ndef PRODUCT 7.1083 + 7.1084 +bool PrimitiveType::covariant_match(Type* other, Context* ctx) { 7.1085 + 7.1086 + PrimitiveType* other_prim = other->as_primitive(); 7.1087 + return (other_prim != NULL && _type == other_prim->_type); 7.1088 +} 7.1089 + 7.1090 +PrimitiveType* PrimitiveType::canonicalize(Context* ctx, int ctxd) { 7.1091 + return this; 7.1092 +} 7.1093 + 7.1094 +#ifndef PRODUCT 7.1095 +void PrimitiveType::reify_signature(stringStream* ss, Context* ctx) { 7.1096 + ss->print("%c", _type); 7.1097 +} 7.1098 + 7.1099 +void PrimitiveType::print_on(outputStream* str) const { 7.1100 + str->indent().print_cr("Primitive: '%c'", _type); 7.1101 +} 7.1102 +#endif // ndef PRODUCT 7.1103 + 7.1104 +void PrimitiveType::bind_variables_to_parameters(Descriptor* sig) { 7.1105 +} 7.1106 + 7.1107 +TypeArgument* TypeArgument::parse_generic_signature(DescriptorStream* STREAM) { 7.1108 + char c = READ(); 7.1109 + Type* type = NULL; 7.1110 + 7.1111 + switch (c) { 7.1112 + case '*': 7.1113 + return new TypeArgument(ClassType::java_lang_Object(), NULL); 7.1114 + break; 7.1115 + default: 7.1116 + PUSH(c); 7.1117 + // fall-through 7.1118 + case '+': 7.1119 + case '-': 7.1120 + type = Type::parse_generic_signature(CHECK_STREAM); 7.1121 + if (c == '+') { 7.1122 + return new TypeArgument(type, NULL); 7.1123 + } else if (c == '-') { 7.1124 + return new TypeArgument(ClassType::java_lang_Object(), type); 7.1125 + } else { 7.1126 + return new TypeArgument(type, type); 7.1127 + } 7.1128 + } 7.1129 +} 7.1130 + 7.1131 +void TypeArgument::bind_variables_to_parameters(Descriptor* sig) { 7.1132 + assert(_lower_bound != NULL, "Invalid lower bound"); 7.1133 + _lower_bound->bind_variables_to_parameters(sig); 7.1134 + if (_upper_bound != NULL && _upper_bound != _lower_bound) { 7.1135 + _upper_bound->bind_variables_to_parameters(sig); 7.1136 + } 7.1137 +} 7.1138 + 7.1139 +bool TypeArgument::covariant_match(TypeArgument* other, Context* ctx) { 7.1140 + assert(_lower_bound != NULL, "Invalid lower bound"); 7.1141 + 7.1142 + if (other == this) { 7.1143 + return true; 7.1144 + } 7.1145 + 7.1146 + if (!_lower_bound->covariant_match(other->lower_bound(), ctx)) { 7.1147 + return false; 7.1148 + } 7.1149 + return true; 7.1150 +} 7.1151 + 7.1152 +TypeArgument* TypeArgument::canonicalize(Context* ctx, int ctx_depth) { 7.1153 + assert(_lower_bound != NULL, "Invalid lower bound"); 7.1154 + Type* lower = _lower_bound->canonicalize(ctx, ctx_depth); 7.1155 + Type* upper = NULL; 7.1156 + 7.1157 + if (_upper_bound == _lower_bound) { 7.1158 + upper = lower; 7.1159 + } else if (_upper_bound != NULL) { 7.1160 + upper = _upper_bound->canonicalize(ctx, ctx_depth); 7.1161 + } 7.1162 + 7.1163 + return new TypeArgument(lower, upper); 7.1164 +} 7.1165 + 7.1166 +#ifndef PRODUCT 7.1167 +void TypeArgument::print_on(outputStream* str) const { 7.1168 + str->indent().print_cr("TypeArgument {"); 7.1169 + { 7.1170 + streamIndentor si(str); 7.1171 + if (_lower_bound != NULL) { 7.1172 + str->indent().print("Lower bound: "); 7.1173 + _lower_bound->print_on(str); 7.1174 + } 7.1175 + if (_upper_bound != NULL) { 7.1176 + str->indent().print("Upper bound: "); 7.1177 + _upper_bound->print_on(str); 7.1178 + } 7.1179 + } 7.1180 + str->indent().print_cr("}"); 7.1181 +} 7.1182 +#endif // ndef PRODUCT 7.1183 + 7.1184 +void Context::Mark::destroy() { 7.1185 + if (is_active()) { 7.1186 + _context->reset_to_mark(_marked_size); 7.1187 + } 7.1188 + deactivate(); 7.1189 +} 7.1190 + 7.1191 +void Context::apply_type_arguments( 7.1192 + InstanceKlass* current, InstanceKlass* super, TRAPS) { 7.1193 + assert(_cache != NULL, "Cannot use an empty context"); 7.1194 + ClassType* spec = NULL; 7.1195 + if (current != NULL) { 7.1196 + ClassDescriptor* descriptor = _cache->descriptor_for(current, CHECK); 7.1197 + if (super == current->super()) { 7.1198 + spec = descriptor->super(); 7.1199 + } else { 7.1200 + spec = descriptor->interface_desc(super->name()); 7.1201 + } 7.1202 + if (spec != NULL) { 7.1203 + _type_arguments.push(spec); 7.1204 + } 7.1205 + } 7.1206 +} 7.1207 + 7.1208 +void Context::reset_to_mark(int size) { 7.1209 + _type_arguments.trunc_to(size); 7.1210 +} 7.1211 + 7.1212 +ClassType* Context::at_depth(int i) const { 7.1213 + if (i < _type_arguments.length()) { 7.1214 + return _type_arguments.at(_type_arguments.length() - 1 - i); 7.1215 + } 7.1216 + return NULL; 7.1217 +} 7.1218 + 7.1219 +#ifndef PRODUCT 7.1220 +void Context::print_on(outputStream* str) const { 7.1221 + str->indent().print_cr("Context {"); 7.1222 + for (int i = 0; i < _type_arguments.length(); ++i) { 7.1223 + streamIndentor si(str); 7.1224 + str->indent().print("leval %d: ", i); 7.1225 + ClassType* ct = at_depth(i); 7.1226 + if (ct == NULL) { 7.1227 + str->print_cr("<empty>"); 7.1228 + continue; 7.1229 + } else { 7.1230 + str->print_cr("{"); 7.1231 + } 7.1232 + 7.1233 + for (int j = 0; j < ct->type_arguments_length(); ++j) { 7.1234 + streamIndentor si(str); 7.1235 + TypeArgument* ta = ct->type_argument_at(j); 7.1236 + Type* bound = ta->lower_bound(); 7.1237 + bound->print_on(str); 7.1238 + } 7.1239 + str->indent().print_cr("}"); 7.1240 + } 7.1241 + str->indent().print_cr("}"); 7.1242 +} 7.1243 +#endif // ndef PRODUCT 7.1244 + 7.1245 +ClassDescriptor* DescriptorCache::descriptor_for(InstanceKlass* ik, TRAPS) { 7.1246 + 7.1247 + ClassDescriptor** existing = _class_descriptors.get(ik); 7.1248 + if (existing == NULL) { 7.1249 + ClassDescriptor* cd = ClassDescriptor::parse_generic_signature(ik, CHECK_NULL); 7.1250 + _class_descriptors.put(ik, cd); 7.1251 + return cd; 7.1252 + } else { 7.1253 + return *existing; 7.1254 + } 7.1255 +} 7.1256 + 7.1257 +MethodDescriptor* DescriptorCache::descriptor_for( 7.1258 + Method* mh, ClassDescriptor* cd, TRAPS) { 7.1259 + assert(mh != NULL && cd != NULL, "Should not be NULL"); 7.1260 + MethodDescriptor** existing = _method_descriptors.get(mh); 7.1261 + if (existing == NULL) { 7.1262 + MethodDescriptor* md = MethodDescriptor::parse_generic_signature(mh, cd); 7.1263 + _method_descriptors.put(mh, md); 7.1264 + return md; 7.1265 + } else { 7.1266 + return *existing; 7.1267 + } 7.1268 +} 7.1269 +MethodDescriptor* DescriptorCache::descriptor_for(Method* mh, TRAPS) { 7.1270 + ClassDescriptor* cd = descriptor_for( 7.1271 + InstanceKlass::cast(mh->method_holder()), CHECK_NULL); 7.1272 + return descriptor_for(mh, cd, THREAD); 7.1273 +} 7.1274 + 7.1275 +} // namespace generic
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/src/share/vm/classfile/genericSignatures.hpp Fri Nov 02 17:18:16 2012 -0700 8.3 @@ -0,0 +1,467 @@ 8.4 +/* 8.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. 8.11 + * 8.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.15 + * version 2 for more details (a copy is included in the LICENSE file that 8.16 + * accompanied this code). 8.17 + * 8.18 + * You should have received a copy of the GNU General Public License version 8.19 + * 2 along with this work; if not, write to the Free Software Foundation, 8.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.21 + * 8.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.23 + * or visit www.oracle.com if you need additional information or have any 8.24 + * questions. 8.25 + * 8.26 + */ 8.27 + 8.28 +#ifndef SHARE_VM_CLASSFILE_GENERICSIGNATURES_HPP 8.29 +#define SHARE_VM_CLASSFILE_GENERICSIGNATURES_HPP 8.30 + 8.31 +#include "classfile/symbolTable.hpp" 8.32 +#include "memory/allocation.hpp" 8.33 +#include "runtime/signature.hpp" 8.34 +#include "utilities/growableArray.hpp" 8.35 +#include "utilities/resourceHash.hpp" 8.36 + 8.37 +class stringStream; 8.38 + 8.39 +namespace generic { 8.40 + 8.41 +class Identifier; 8.42 +class ClassDescriptor; 8.43 +class MethodDescriptor; 8.44 + 8.45 +class TypeParameter; // a formal type parameter declared in generic signatures 8.46 +class TypeArgument; // The "type value" passed to fill parameters in supertypes 8.47 +class TypeVariable; // A usage of a type parameter as a value 8.48 +/** 8.49 + * Example: 8.50 + * 8.51 + * <T, V> class Foo extends Bar<String> { int m(V v) {} } 8.52 + * ^^^^^^ ^^^^^^ ^^ 8.53 + * type parameters type argument type variable 8.54 + * 8.55 + * Note that a type variable could be passed as an argument too: 8.56 + * <T, V> class Foo extends Bar<T> { int m(V v) {} } 8.57 + * ^^^ 8.58 + * type argument's value is a type variable 8.59 + */ 8.60 + 8.61 + 8.62 +class Type; 8.63 +class ClassType; 8.64 +class ArrayType; 8.65 +class PrimitiveType; 8.66 +class Context; 8.67 +class DescriptorCache; 8.68 + 8.69 +class DescriptorStream; 8.70 + 8.71 +class Identifier : public ResourceObj { 8.72 + private: 8.73 + Symbol* _sym; 8.74 + int _begin; 8.75 + int _end; 8.76 + 8.77 + public: 8.78 + Identifier(Symbol* sym, int begin, int end) : 8.79 + _sym(sym), _begin(begin), _end(end) {} 8.80 + 8.81 + bool equals(Identifier* other); 8.82 + bool equals(Symbol* sym); 8.83 + 8.84 +#ifndef PRODUCT 8.85 + void print_on(outputStream* str) const; 8.86 +#endif // ndef PRODUCT 8.87 +}; 8.88 + 8.89 +class Descriptor : public ResourceObj { 8.90 + protected: 8.91 + GrowableArray<TypeParameter*> _type_parameters; 8.92 + ClassDescriptor* _outer_class; 8.93 + 8.94 + Descriptor(GrowableArray<TypeParameter*>& params, 8.95 + ClassDescriptor* outer) 8.96 + : _type_parameters(params), _outer_class(outer) {} 8.97 + 8.98 + public: 8.99 + 8.100 + ClassDescriptor* outer_class() { return _outer_class; } 8.101 + void set_outer_class(ClassDescriptor* sig) { _outer_class = sig; } 8.102 + 8.103 + virtual ClassDescriptor* as_class_signature() { return NULL; } 8.104 + virtual MethodDescriptor* as_method_signature() { return NULL; } 8.105 + 8.106 + bool is_class_signature() { return as_class_signature() != NULL; } 8.107 + bool is_method_signature() { return as_method_signature() != NULL; } 8.108 + 8.109 + GrowableArray<TypeParameter*>& type_parameters() { 8.110 + return _type_parameters; 8.111 + } 8.112 + 8.113 + TypeParameter* find_type_parameter(Identifier* id, int* param_depth); 8.114 + 8.115 + virtual void bind_variables_to_parameters() = 0; 8.116 + 8.117 +#ifndef PRODUCT 8.118 + virtual void print_on(outputStream* str) const = 0; 8.119 +#endif 8.120 +}; 8.121 + 8.122 +class ClassDescriptor : public Descriptor { 8.123 + private: 8.124 + ClassType* _super; 8.125 + GrowableArray<ClassType*> _interfaces; 8.126 + MethodDescriptor* _outer_method; 8.127 + 8.128 + ClassDescriptor(GrowableArray<TypeParameter*>& ftp, ClassType* scs, 8.129 + GrowableArray<ClassType*>& sis, ClassDescriptor* outer_class = NULL, 8.130 + MethodDescriptor* outer_method = NULL) 8.131 + : Descriptor(ftp, outer_class), _super(scs), _interfaces(sis), 8.132 + _outer_method(outer_method) {} 8.133 + 8.134 + static u2 get_outer_class_index(InstanceKlass* k, TRAPS); 8.135 + static ClassDescriptor* parse_generic_signature(Klass* k, Symbol* original_name, TRAPS); 8.136 + 8.137 + public: 8.138 + 8.139 + virtual ClassDescriptor* as_class_signature() { return this; } 8.140 + 8.141 + MethodDescriptor* outer_method() { return _outer_method; } 8.142 + void set_outer_method(MethodDescriptor* m) { _outer_method = m; } 8.143 + 8.144 + ClassType* super() { return _super; } 8.145 + ClassType* interface_desc(Symbol* sym); 8.146 + 8.147 + static ClassDescriptor* parse_generic_signature(Klass* k, TRAPS); 8.148 + static ClassDescriptor* parse_generic_signature(Symbol* sym); 8.149 + 8.150 + // For use in superclass chains in positions where this is no generic info 8.151 + static ClassDescriptor* placeholder(InstanceKlass* klass); 8.152 + 8.153 +#ifndef PRODUCT 8.154 + void print_on(outputStream* str) const; 8.155 +#endif 8.156 + 8.157 + ClassDescriptor* canonicalize(Context* ctx); 8.158 + 8.159 + // Linking sets the position index in any contained TypeVariable type 8.160 + // to correspond to the location of that identifier in the formal type 8.161 + // parameters. 8.162 + void bind_variables_to_parameters(); 8.163 +}; 8.164 + 8.165 +class MethodDescriptor : public Descriptor { 8.166 + private: 8.167 + GrowableArray<Type*> _parameters; 8.168 + Type* _return_type; 8.169 + GrowableArray<Type*> _throws; 8.170 + 8.171 + MethodDescriptor(GrowableArray<TypeParameter*>& ftp, ClassDescriptor* outer, 8.172 + GrowableArray<Type*>& sigs, Type* rt, GrowableArray<Type*>& throws) 8.173 + : Descriptor(ftp, outer), _parameters(sigs), _return_type(rt), 8.174 + _throws(throws) {} 8.175 + 8.176 + public: 8.177 + 8.178 + static MethodDescriptor* parse_generic_signature(Method* m, ClassDescriptor* outer); 8.179 + static MethodDescriptor* parse_generic_signature(Symbol* sym, ClassDescriptor* outer); 8.180 + 8.181 + MethodDescriptor* as_method_signature() { return this; } 8.182 + 8.183 + // Performs generic analysis on the method parameters to determine 8.184 + // if both methods refer to the same argument types. 8.185 + bool covariant_match(MethodDescriptor* other, Context* ctx); 8.186 + 8.187 + // Returns a new method descriptor with all generic variables 8.188 + // removed and replaced with whatever is indicated using the Context. 8.189 + MethodDescriptor* canonicalize(Context* ctx); 8.190 + 8.191 + void bind_variables_to_parameters(); 8.192 + 8.193 +#ifndef PRODUCT 8.194 + TempNewSymbol reify_signature(Context* ctx, TRAPS); 8.195 + void print_on(outputStream* str) const; 8.196 +#endif 8.197 +}; 8.198 + 8.199 +class TypeParameter : public ResourceObj { 8.200 + private: 8.201 + Identifier* _identifier; 8.202 + ClassType* _class_bound; 8.203 + GrowableArray<ClassType*> _interface_bounds; 8.204 + 8.205 + // The position is the ordinal location of the parameter within the 8.206 + // formal parameter list (excluding outer classes). It is only set for 8.207 + // formal type parameters that are associated with a class -- method 8.208 + // type parameters are left as -1. When resolving a generic variable to 8.209 + // find the actual type, this index is used to access the generic type 8.210 + // argument in the provided context object. 8.211 + int _position; // Assigned during variable linking 8.212 + 8.213 + TypeParameter(Identifier* id, ClassType* class_bound, 8.214 + GrowableArray<ClassType*>& interface_bounds) : 8.215 + _identifier(id), _class_bound(class_bound), 8.216 + _interface_bounds(interface_bounds), _position(-1) {} 8.217 + 8.218 + public: 8.219 + static TypeParameter* parse_generic_signature(DescriptorStream* str); 8.220 + 8.221 + ClassType* bound(); 8.222 + int position() { return _position; } 8.223 + 8.224 + void bind_variables_to_parameters(Descriptor* sig, int position); 8.225 + Identifier* identifier() { return _identifier; } 8.226 + 8.227 + Type* resolve(Context* ctx, int inner_depth, int ctx_depth); 8.228 + TypeParameter* canonicalize(Context* ctx, int ctx_depth); 8.229 + 8.230 +#ifndef PRODUCT 8.231 + void print_on(outputStream* str) const; 8.232 +#endif 8.233 +}; 8.234 + 8.235 +class Type : public ResourceObj { 8.236 + public: 8.237 + static Type* parse_generic_signature(DescriptorStream* str); 8.238 + 8.239 + virtual ClassType* as_class() { return NULL; } 8.240 + virtual TypeVariable* as_variable() { return NULL; } 8.241 + virtual ArrayType* as_array() { return NULL; } 8.242 + virtual PrimitiveType* as_primitive() { return NULL; } 8.243 + 8.244 + virtual bool covariant_match(Type* gt, Context* ctx) = 0; 8.245 + virtual Type* canonicalize(Context* ctx, int ctx_depth) = 0; 8.246 + 8.247 + virtual void bind_variables_to_parameters(Descriptor* sig) = 0; 8.248 + 8.249 +#ifndef PRODUCT 8.250 + virtual void reify_signature(stringStream* ss, Context* ctx) = 0; 8.251 + virtual void print_on(outputStream* str) const = 0; 8.252 +#endif 8.253 +}; 8.254 + 8.255 +class ClassType : public Type { 8.256 + friend class ClassDescriptor; 8.257 + protected: 8.258 + Identifier* _identifier; 8.259 + GrowableArray<TypeArgument*> _type_arguments; 8.260 + ClassType* _outer_class; 8.261 + 8.262 + ClassType(Identifier* identifier, 8.263 + GrowableArray<TypeArgument*>& args, 8.264 + ClassType* outer) 8.265 + : _identifier(identifier), _type_arguments(args), _outer_class(outer) {} 8.266 + 8.267 + // Returns true if there are inner classes to read 8.268 + static Identifier* parse_generic_signature_simple( 8.269 + GrowableArray<TypeArgument*>* args, 8.270 + bool* has_inner, DescriptorStream* str); 8.271 + 8.272 + static ClassType* parse_generic_signature(ClassType* outer, 8.273 + DescriptorStream* str); 8.274 + static ClassType* from_symbol(Symbol* sym); 8.275 + 8.276 + public: 8.277 + ClassType* as_class() { return this; } 8.278 + 8.279 + static ClassType* parse_generic_signature(DescriptorStream* str); 8.280 + static ClassType* java_lang_Object(); 8.281 + 8.282 + Identifier* identifier() { return _identifier; } 8.283 + int type_arguments_length() { return _type_arguments.length(); } 8.284 + TypeArgument* type_argument_at(int i); 8.285 + 8.286 + virtual ClassType* outer_class() { return _outer_class; } 8.287 + 8.288 + bool covariant_match(Type* gt, Context* ctx); 8.289 + ClassType* canonicalize(Context* ctx, int context_depth); 8.290 + 8.291 + void bind_variables_to_parameters(Descriptor* sig); 8.292 + 8.293 +#ifndef PRODUCT 8.294 + void reify_signature(stringStream* ss, Context* ctx); 8.295 + void print_on(outputStream* str) const; 8.296 +#endif 8.297 +}; 8.298 + 8.299 +class TypeVariable : public Type { 8.300 + private: 8.301 + Identifier* _id; 8.302 + TypeParameter* _parameter; // assigned during linking 8.303 + 8.304 + // how many steps "out" from inner classes, -1 if method 8.305 + int _inner_depth; 8.306 + 8.307 + TypeVariable(Identifier* id) 8.308 + : _id(id), _parameter(NULL), _inner_depth(0) {} 8.309 + 8.310 + public: 8.311 + TypeVariable* as_variable() { return this; } 8.312 + 8.313 + static TypeVariable* parse_generic_signature(DescriptorStream* str); 8.314 + 8.315 + Identifier* identifier() { return _id; } 8.316 + TypeParameter* parameter() { return _parameter; } 8.317 + int inner_depth() { return _inner_depth; } 8.318 + 8.319 + void bind_variables_to_parameters(Descriptor* sig); 8.320 + 8.321 + Type* resolve(Context* ctx, int ctx_depth); 8.322 + bool covariant_match(Type* gt, Context* ctx); 8.323 + Type* canonicalize(Context* ctx, int ctx_depth); 8.324 + 8.325 +#ifndef PRODUCT 8.326 + void reify_signature(stringStream* ss, Context* ctx); 8.327 + void print_on(outputStream* str) const; 8.328 +#endif 8.329 +}; 8.330 + 8.331 +class ArrayType : public Type { 8.332 + private: 8.333 + Type* _base; 8.334 + 8.335 + ArrayType(Type* base) : _base(base) {} 8.336 + 8.337 + public: 8.338 + ArrayType* as_array() { return this; } 8.339 + 8.340 + static ArrayType* parse_generic_signature(DescriptorStream* str); 8.341 + 8.342 + bool covariant_match(Type* gt, Context* ctx); 8.343 + ArrayType* canonicalize(Context* ctx, int ctx_depth); 8.344 + 8.345 + void bind_variables_to_parameters(Descriptor* sig); 8.346 + 8.347 +#ifndef PRODUCT 8.348 + void reify_signature(stringStream* ss, Context* ctx); 8.349 + void print_on(outputStream* str) const; 8.350 +#endif 8.351 +}; 8.352 + 8.353 +class PrimitiveType : public Type { 8.354 + friend class Type; 8.355 + private: 8.356 + char _type; // includes V for void 8.357 + 8.358 + PrimitiveType(char& type) : _type(type) {} 8.359 + 8.360 + public: 8.361 + PrimitiveType* as_primitive() { return this; } 8.362 + 8.363 + bool covariant_match(Type* gt, Context* ctx); 8.364 + PrimitiveType* canonicalize(Context* ctx, int ctx_depth); 8.365 + 8.366 + void bind_variables_to_parameters(Descriptor* sig); 8.367 + 8.368 +#ifndef PRODUCT 8.369 + void reify_signature(stringStream* ss, Context* ctx); 8.370 + void print_on(outputStream* str) const; 8.371 +#endif 8.372 +}; 8.373 + 8.374 +class TypeArgument : public ResourceObj { 8.375 + private: 8.376 + Type* _lower_bound; 8.377 + Type* _upper_bound; // may be null or == _lower_bound 8.378 + 8.379 + TypeArgument(Type* lower_bound, Type* upper_bound) 8.380 + : _lower_bound(lower_bound), _upper_bound(upper_bound) {} 8.381 + 8.382 + public: 8.383 + 8.384 + static TypeArgument* parse_generic_signature(DescriptorStream* str); 8.385 + 8.386 + Type* lower_bound() { return _lower_bound; } 8.387 + Type* upper_bound() { return _upper_bound; } 8.388 + 8.389 + void bind_variables_to_parameters(Descriptor* sig); 8.390 + TypeArgument* canonicalize(Context* ctx, int ctx_depth); 8.391 + 8.392 + bool covariant_match(TypeArgument* a, Context* ctx); 8.393 + 8.394 +#ifndef PRODUCT 8.395 + void print_on(outputStream* str) const; 8.396 +#endif 8.397 +}; 8.398 + 8.399 + 8.400 +class Context : public ResourceObj { 8.401 + private: 8.402 + DescriptorCache* _cache; 8.403 + GrowableArray<ClassType*> _type_arguments; 8.404 + 8.405 + void reset_to_mark(int size); 8.406 + 8.407 + public: 8.408 + // When this object goes out of scope or 'destroy' is 8.409 + // called, then the application of the type to the 8.410 + // context is wound-back (unless it's been deactivated). 8.411 + class Mark : public StackObj { 8.412 + private: 8.413 + mutable Context* _context; 8.414 + int _marked_size; 8.415 + 8.416 + bool is_active() const { return _context != NULL; } 8.417 + void deactivate() const { _context = NULL; } 8.418 + 8.419 + public: 8.420 + Mark() : _context(NULL), _marked_size(0) {} 8.421 + Mark(Context* ctx, int sz) : _context(ctx), _marked_size(sz) {} 8.422 + Mark(const Mark& m) : _context(m._context), _marked_size(m._marked_size) { 8.423 + m.deactivate(); // Ownership is transferred 8.424 + } 8.425 + 8.426 + Mark& operator=(const Mark& cm) { 8.427 + destroy(); 8.428 + _context = cm._context; 8.429 + _marked_size = cm._marked_size; 8.430 + cm.deactivate(); 8.431 + return *this; 8.432 + } 8.433 + 8.434 + void destroy(); 8.435 + ~Mark() { destroy(); } 8.436 + }; 8.437 + 8.438 + Context(DescriptorCache* cache) : _cache(cache) {} 8.439 + 8.440 + Mark mark() { return Mark(this, _type_arguments.length()); } 8.441 + void apply_type_arguments(InstanceKlass* current, InstanceKlass* super,TRAPS); 8.442 + 8.443 + ClassType* at_depth(int i) const; 8.444 + 8.445 +#ifndef PRODUCT 8.446 + void print_on(outputStream* str) const; 8.447 +#endif 8.448 +}; 8.449 + 8.450 +/** 8.451 + * Contains a cache of descriptors for classes and methods so they can be 8.452 + * looked-up instead of reparsing each time they are needed. 8.453 + */ 8.454 +class DescriptorCache : public ResourceObj { 8.455 + private: 8.456 + ResourceHashtable<InstanceKlass*, ClassDescriptor*> _class_descriptors; 8.457 + ResourceHashtable<Method*, MethodDescriptor*> _method_descriptors; 8.458 + 8.459 + public: 8.460 + ClassDescriptor* descriptor_for(InstanceKlass* ikh, TRAPS); 8.461 + 8.462 + MethodDescriptor* descriptor_for(Method* mh, ClassDescriptor* cd, TRAPS); 8.463 + // Class descriptor derived from method holder 8.464 + MethodDescriptor* descriptor_for(Method* mh, TRAPS); 8.465 +}; 8.466 + 8.467 +} // namespace generic 8.468 + 8.469 +#endif // SHARE_VM_CLASSFILE_GENERICSIGNATURES_HPP 8.470 +
9.1 --- a/src/share/vm/classfile/systemDictionary.hpp Fri Nov 02 13:30:47 2012 -0700 9.2 +++ b/src/share/vm/classfile/systemDictionary.hpp Fri Nov 02 17:18:16 2012 -0700 9.3 @@ -137,6 +137,7 @@ 9.4 /* NOTE: needed too early in bootstrapping process to have checks based on JDK version */ \ 9.5 /* Universe::is_gte_jdk14x_version() is not set up by this point. */ \ 9.6 /* It's okay if this turns out to be NULL in non-1.4 JDKs. */ \ 9.7 + do_klass(lambda_MagicLambdaImpl_klass, java_lang_invoke_MagicLambdaImpl, Opt ) \ 9.8 do_klass(reflect_MagicAccessorImpl_klass, sun_reflect_MagicAccessorImpl, Opt ) \ 9.9 do_klass(reflect_MethodAccessorImpl_klass, sun_reflect_MethodAccessorImpl, Opt_Only_JDK14NewRef) \ 9.10 do_klass(reflect_ConstructorAccessorImpl_klass, sun_reflect_ConstructorAccessorImpl, Opt_Only_JDK14NewRef) \
10.1 --- a/src/share/vm/classfile/verifier.cpp Fri Nov 02 13:30:47 2012 -0700 10.2 +++ b/src/share/vm/classfile/verifier.cpp Fri Nov 02 17:18:16 2012 -0700 10.3 @@ -555,9 +555,10 @@ 10.4 if (was_recursively_verified()) return; 10.5 10.6 Method* m = methods->at(index); 10.7 - if (m->is_native() || m->is_abstract()) { 10.8 + if (m->is_native() || m->is_abstract() || m->is_overpass()) { 10.9 // If m is native or abstract, skip it. It is checked in class file 10.10 - // parser that methods do not override a final method. 10.11 + // parser that methods do not override a final method. Overpass methods 10.12 + // are trusted since the VM generates them. 10.13 continue; 10.14 } 10.15 verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); 10.16 @@ -2304,11 +2305,21 @@ 10.17 // Make sure the constant pool item is the right type 10.18 u2 index = bcs->get_index_u2(); 10.19 Bytecodes::Code opcode = bcs->raw_code(); 10.20 - unsigned int types = (opcode == Bytecodes::_invokeinterface 10.21 - ? 1 << JVM_CONSTANT_InterfaceMethodref 10.22 - : opcode == Bytecodes::_invokedynamic 10.23 - ? 1 << JVM_CONSTANT_InvokeDynamic 10.24 - : 1 << JVM_CONSTANT_Methodref); 10.25 + unsigned int types; 10.26 + switch (opcode) { 10.27 + case Bytecodes::_invokeinterface: 10.28 + types = 1 << JVM_CONSTANT_InterfaceMethodref; 10.29 + break; 10.30 + case Bytecodes::_invokedynamic: 10.31 + types = 1 << JVM_CONSTANT_InvokeDynamic; 10.32 + break; 10.33 + case Bytecodes::_invokespecial: 10.34 + types = (1 << JVM_CONSTANT_InterfaceMethodref) | 10.35 + (1 << JVM_CONSTANT_Methodref); 10.36 + break; 10.37 + default: 10.38 + types = 1 << JVM_CONSTANT_Methodref; 10.39 + } 10.40 verify_cp_type(bcs->bci(), index, cp, types, CHECK_VERIFY(this)); 10.41 10.42 // Get method name and signature
11.1 --- a/src/share/vm/classfile/vmSymbols.hpp Fri Nov 02 13:30:47 2012 -0700 11.2 +++ b/src/share/vm/classfile/vmSymbols.hpp Fri Nov 02 17:18:16 2012 -0700 11.3 @@ -259,6 +259,7 @@ 11.4 template(java_lang_invoke_DontInline_signature, "Ljava/lang/invoke/DontInline;") \ 11.5 template(java_lang_invoke_LambdaForm_Compiled_signature, "Ljava/lang/invoke/LambdaForm$Compiled;") \ 11.6 template(java_lang_invoke_LambdaForm_Hidden_signature, "Ljava/lang/invoke/LambdaForm$Hidden;") \ 11.7 + template(java_lang_invoke_MagicLambdaImpl, "java/lang/invoke/MagicLambdaImpl") \ 11.8 /* internal up-calls made only by the JVM, via class sun.invoke.MethodHandleNatives: */ \ 11.9 template(findMethodHandleType_name, "findMethodHandleType") \ 11.10 template(findMethodHandleType_signature, "(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/invoke/MethodType;") \
12.1 --- a/src/share/vm/code/dependencies.cpp Fri Nov 02 13:30:47 2012 -0700 12.2 +++ b/src/share/vm/code/dependencies.cpp Fri Nov 02 17:18:16 2012 -0700 12.3 @@ -1160,7 +1160,11 @@ 12.4 12.5 // We could also return false if m does not yet appear to be 12.6 // executed, if the VM version supports this distinction also. 12.7 - return !m->is_abstract(); 12.8 + return !m->is_abstract() && 12.9 + !InstanceKlass::cast(m->method_holder())->is_interface(); 12.10 + // TODO: investigate whether default methods should be 12.11 + // considered as "concrete" in this situation. For now they 12.12 + // are not. 12.13 } 12.14 12.15
13.1 --- a/src/share/vm/interpreter/linkResolver.cpp Fri Nov 02 13:30:47 2012 -0700 13.2 +++ b/src/share/vm/interpreter/linkResolver.cpp Fri Nov 02 17:18:16 2012 -0700 13.3 @@ -23,6 +23,7 @@ 13.4 */ 13.5 13.6 #include "precompiled.hpp" 13.7 +#include "classfile/defaultMethods.hpp" 13.8 #include "classfile/systemDictionary.hpp" 13.9 #include "classfile/vmSymbols.hpp" 13.10 #include "compiler/compileBroker.hpp" 13.11 @@ -404,21 +405,13 @@ 13.12 Symbol* method_name, Symbol* method_signature, 13.13 KlassHandle current_klass, bool check_access, TRAPS) { 13.14 13.15 - // 1. check if klass is not interface 13.16 - if (resolved_klass->is_interface()) { 13.17 - ResourceMark rm(THREAD); 13.18 - char buf[200]; 13.19 - jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected", Klass::cast(resolved_klass())->external_name()); 13.20 - THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 13.21 - } 13.22 - 13.23 Handle nested_exception; 13.24 13.25 - // 2. lookup method in resolved klass and its super klasses 13.26 + // 1. lookup method in resolved klass and its super klasses 13.27 lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK); 13.28 13.29 if (resolved_method.is_null()) { // not found in the class hierarchy 13.30 - // 3. lookup method in all the interfaces implemented by the resolved klass 13.31 + // 2. lookup method in all the interfaces implemented by the resolved klass 13.32 lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); 13.33 13.34 if (resolved_method.is_null()) { 13.35 @@ -432,7 +425,7 @@ 13.36 } 13.37 13.38 if (resolved_method.is_null()) { 13.39 - // 4. method lookup failed 13.40 + // 3. method lookup failed 13.41 ResourceMark rm(THREAD); 13.42 THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(), 13.43 Method::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 13.44 @@ -442,6 +435,15 @@ 13.45 } 13.46 } 13.47 13.48 + // 4. check if klass is not interface 13.49 + if (resolved_klass->is_interface() && resolved_method->is_abstract()) { 13.50 + ResourceMark rm(THREAD); 13.51 + char buf[200]; 13.52 + jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected", 13.53 + resolved_klass()->external_name()); 13.54 + THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 13.55 + } 13.56 + 13.57 // 5. check if method is concrete 13.58 if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) { 13.59 ResourceMark rm(THREAD); 13.60 @@ -743,6 +745,27 @@ 13.61 Symbol* method_name, Symbol* method_signature, 13.62 KlassHandle current_klass, bool check_access, TRAPS) { 13.63 13.64 + if (resolved_klass->is_interface() && current_klass() != NULL) { 13.65 + // If the target class is a direct interface, treat this as a "super" 13.66 + // default call. 13.67 + // 13.68 + // If the current method is an overpass that happens to call a direct 13.69 + // super-interface's method, then we'll end up rerunning the default method 13.70 + // analysis even though we don't need to, but that's ok since it will end 13.71 + // up with the same answer. 13.72 + InstanceKlass* ik = InstanceKlass::cast(current_klass()); 13.73 + Array<Klass*>* interfaces = ik->local_interfaces(); 13.74 + int num_interfaces = interfaces->length(); 13.75 + for (int index = 0; index < num_interfaces; index++) { 13.76 + if (interfaces->at(index) == resolved_klass()) { 13.77 + Method* method = DefaultMethods::find_super_default(current_klass(), 13.78 + resolved_klass(), method_name, method_signature, CHECK); 13.79 + resolved_method = methodHandle(THREAD, method); 13.80 + return; 13.81 + } 13.82 + } 13.83 + } 13.84 + 13.85 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 13.86 13.87 // check if method name is <init>, that it is found in same klass as static type 13.88 @@ -784,11 +807,17 @@ 13.89 { KlassHandle method_klass = KlassHandle(THREAD, 13.90 resolved_method->method_holder()); 13.91 13.92 - if (check_access && 13.93 + const bool direct_calling_default_method = 13.94 + resolved_klass() != NULL && resolved_method() != NULL && 13.95 + resolved_klass->is_interface() && !resolved_method->is_abstract(); 13.96 + 13.97 + if (!direct_calling_default_method && 13.98 + check_access && 13.99 // a) check if ACC_SUPER flag is set for the current class 13.100 current_klass->is_super() && 13.101 // b) check if the method class is a superclass of the current class (superclass relation is not reflexive!) 13.102 - current_klass->is_subtype_of(method_klass()) && current_klass() != method_klass() && 13.103 + current_klass->is_subtype_of(method_klass()) && 13.104 + current_klass() != method_klass() && 13.105 // c) check if the method is not <init> 13.106 resolved_method->name() != vmSymbols::object_initializer_name()) { 13.107 // Lookup super method
14.1 --- a/src/share/vm/oops/constMethod.cpp Fri Nov 02 13:30:47 2012 -0700 14.2 +++ b/src/share/vm/oops/constMethod.cpp Fri Nov 02 17:18:16 2012 -0700 14.3 @@ -34,29 +34,30 @@ 14.4 const u2 ConstMethod::UNSET_IDNUM = 0xFFFF; 14.5 14.6 ConstMethod* ConstMethod::allocate(ClassLoaderData* loader_data, 14.7 - int byte_code_size, 14.8 - int compressed_line_number_size, 14.9 - int localvariable_table_length, 14.10 - int exception_table_length, 14.11 - int checked_exceptions_length, 14.12 - TRAPS) { 14.13 + int byte_code_size, 14.14 + int compressed_line_number_size, 14.15 + int localvariable_table_length, 14.16 + int exception_table_length, 14.17 + int checked_exceptions_length, 14.18 + MethodType method_type, 14.19 + TRAPS) { 14.20 int size = ConstMethod::size(byte_code_size, 14.21 compressed_line_number_size, 14.22 localvariable_table_length, 14.23 exception_table_length, 14.24 checked_exceptions_length); 14.25 return new (loader_data, size, true, THREAD) ConstMethod( 14.26 - byte_code_size, compressed_line_number_size, 14.27 - localvariable_table_length, exception_table_length, 14.28 - checked_exceptions_length, size); 14.29 + byte_code_size, compressed_line_number_size, localvariable_table_length, 14.30 + exception_table_length, checked_exceptions_length, method_type, size); 14.31 } 14.32 14.33 ConstMethod::ConstMethod(int byte_code_size, 14.34 - int compressed_line_number_size, 14.35 - int localvariable_table_length, 14.36 - int exception_table_length, 14.37 - int checked_exceptions_length, 14.38 - int size) { 14.39 + int compressed_line_number_size, 14.40 + int localvariable_table_length, 14.41 + int exception_table_length, 14.42 + int checked_exceptions_length, 14.43 + MethodType method_type, 14.44 + int size) { 14.45 14.46 No_Safepoint_Verifier no_safepoint; 14.47 set_interpreter_kind(Interpreter::invalid); 14.48 @@ -69,6 +70,7 @@ 14.49 compressed_line_number_size, 14.50 localvariable_table_length, 14.51 exception_table_length); 14.52 + set_method_type(method_type); 14.53 assert(this->size() == size, "wrong size for object"); 14.54 } 14.55
15.1 --- a/src/share/vm/oops/constMethod.hpp Fri Nov 02 13:30:47 2012 -0700 15.2 +++ b/src/share/vm/oops/constMethod.hpp Fri Nov 02 17:18:16 2012 -0700 15.3 @@ -108,12 +108,17 @@ 15.4 15.5 class ConstMethod : public MetaspaceObj { 15.6 friend class VMStructs; 15.7 + 15.8 +public: 15.9 + typedef enum { NORMAL, OVERPASS } MethodType; 15.10 + 15.11 private: 15.12 enum { 15.13 _has_linenumber_table = 1, 15.14 _has_checked_exceptions = 2, 15.15 _has_localvariable_table = 4, 15.16 - _has_exception_table = 8 15.17 + _has_exception_table = 8, 15.18 + _is_overpass = 16 15.19 }; 15.20 15.21 // Bit vector of signature 15.22 @@ -145,19 +150,22 @@ 15.23 15.24 // Constructor 15.25 ConstMethod(int byte_code_size, 15.26 - int compressed_line_number_size, 15.27 - int localvariable_table_length, 15.28 - int exception_table_length, 15.29 - int checked_exceptions_length, 15.30 - int size); 15.31 + int compressed_line_number_size, 15.32 + int localvariable_table_length, 15.33 + int exception_table_length, 15.34 + int checked_exceptions_length, 15.35 + MethodType is_overpass, 15.36 + int size); 15.37 public: 15.38 + 15.39 static ConstMethod* allocate(ClassLoaderData* loader_data, 15.40 - int byte_code_size, 15.41 - int compressed_line_number_size, 15.42 - int localvariable_table_length, 15.43 - int exception_table_length, 15.44 - int checked_exceptions_length, 15.45 - TRAPS); 15.46 + int byte_code_size, 15.47 + int compressed_line_number_size, 15.48 + int localvariable_table_length, 15.49 + int exception_table_length, 15.50 + int checked_exceptions_length, 15.51 + MethodType mt, 15.52 + TRAPS); 15.53 15.54 bool is_constMethod() const { return true; } 15.55 15.56 @@ -179,6 +187,19 @@ 15.57 bool has_exception_handler() const 15.58 { return (_flags & _has_exception_table) != 0; } 15.59 15.60 + MethodType method_type() const { 15.61 + return ((_flags & _is_overpass) == 0) ? NORMAL : OVERPASS; 15.62 + } 15.63 + 15.64 + void set_method_type(MethodType mt) { 15.65 + if (mt == NORMAL) { 15.66 + _flags &= ~(_is_overpass); 15.67 + } else { 15.68 + _flags |= _is_overpass; 15.69 + } 15.70 + } 15.71 + 15.72 + 15.73 void set_interpreter_kind(int kind) { _interpreter_kind = kind; } 15.74 int interpreter_kind(void) const { return _interpreter_kind; } 15.75
16.1 --- a/src/share/vm/oops/constantPool.cpp Fri Nov 02 13:30:47 2012 -0700 16.2 +++ b/src/share/vm/oops/constantPool.cpp Fri Nov 02 17:18:16 2012 -0700 16.3 @@ -1143,16 +1143,21 @@ 16.4 int from_oplen = operand_array_length(from_cp->operands()); 16.5 int old_oplen = operand_array_length(to_cp->operands()); 16.6 if (from_oplen != 0) { 16.7 + ClassLoaderData* loader_data = to_cp->pool_holder()->class_loader_data(); 16.8 // append my operands to the target's operands array 16.9 if (old_oplen == 0) { 16.10 - to_cp->set_operands(from_cp->operands()); // reuse; do not merge 16.11 + // Can't just reuse from_cp's operand list because of deallocation issues 16.12 + int len = from_cp->operands()->length(); 16.13 + Array<u2>* new_ops = MetadataFactory::new_array<u2>(loader_data, len, CHECK); 16.14 + Copy::conjoint_memory_atomic( 16.15 + from_cp->operands()->adr_at(0), new_ops->adr_at(0), len * sizeof(u2)); 16.16 + to_cp->set_operands(new_ops); 16.17 } else { 16.18 int old_len = to_cp->operands()->length(); 16.19 int from_len = from_cp->operands()->length(); 16.20 int old_off = old_oplen * sizeof(u2); 16.21 int from_off = from_oplen * sizeof(u2); 16.22 // Use the metaspace for the destination constant pool 16.23 - ClassLoaderData* loader_data = to_cp->pool_holder()->class_loader_data(); 16.24 Array<u2>* new_operands = MetadataFactory::new_array<u2>(loader_data, old_len + from_len, CHECK); 16.25 int fillp = 0, len = 0; 16.26 // first part of dest
17.1 --- a/src/share/vm/oops/instanceKlass.cpp Fri Nov 02 13:30:47 2012 -0700 17.2 +++ b/src/share/vm/oops/instanceKlass.cpp Fri Nov 02 17:18:16 2012 -0700 17.3 @@ -743,6 +743,35 @@ 17.4 } 17.5 } 17.6 17.7 + if (this_oop->has_default_methods()) { 17.8 + // Step 7.5: initialize any interfaces which have default methods 17.9 + for (int i = 0; i < this_oop->local_interfaces()->length(); ++i) { 17.10 + Klass* iface = this_oop->local_interfaces()->at(i); 17.11 + InstanceKlass* ik = InstanceKlass::cast(iface); 17.12 + if (ik->has_default_methods() && ik->should_be_initialized()) { 17.13 + ik->initialize(THREAD); 17.14 + 17.15 + if (HAS_PENDING_EXCEPTION) { 17.16 + Handle e(THREAD, PENDING_EXCEPTION); 17.17 + CLEAR_PENDING_EXCEPTION; 17.18 + { 17.19 + EXCEPTION_MARK; 17.20 + // Locks object, set state, and notify all waiting threads 17.21 + this_oop->set_initialization_state_and_notify( 17.22 + initialization_error, THREAD); 17.23 + 17.24 + // ignore any exception thrown, superclass initialization error is 17.25 + // thrown below 17.26 + CLEAR_PENDING_EXCEPTION; 17.27 + } 17.28 + DTRACE_CLASSINIT_PROBE_WAIT( 17.29 + super__failed, InstanceKlass::cast(this_oop()), -1, wait); 17.30 + THROW_OOP(e()); 17.31 + } 17.32 + } 17.33 + } 17.34 + } 17.35 + 17.36 // Step 8 17.37 { 17.38 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); 17.39 @@ -1252,11 +1281,7 @@ 17.40 } 17.41 #endif 17.42 17.43 -Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { 17.44 - return InstanceKlass::find_method(methods(), name, signature); 17.45 -} 17.46 - 17.47 -Method* InstanceKlass::find_method(Array<Method*>* methods, Symbol* name, Symbol* signature) { 17.48 +static int binary_search(Array<Method*>* methods, Symbol* name) { 17.49 int len = methods->length(); 17.50 // methods are sorted, so do binary search 17.51 int l = 0; 17.52 @@ -1267,43 +1292,70 @@ 17.53 assert(m->is_method(), "must be method"); 17.54 int res = m->name()->fast_compare(name); 17.55 if (res == 0) { 17.56 - // found matching name; do linear search to find matching signature 17.57 - // first, quick check for common case 17.58 - if (m->signature() == signature) return m; 17.59 - // search downwards through overloaded methods 17.60 - int i; 17.61 - for (i = mid - 1; i >= l; i--) { 17.62 - Method* m = methods->at(i); 17.63 - assert(m->is_method(), "must be method"); 17.64 - if (m->name() != name) break; 17.65 - if (m->signature() == signature) return m; 17.66 - } 17.67 - // search upwards 17.68 - for (i = mid + 1; i <= h; i++) { 17.69 - Method* m = methods->at(i); 17.70 - assert(m->is_method(), "must be method"); 17.71 - if (m->name() != name) break; 17.72 - if (m->signature() == signature) return m; 17.73 - } 17.74 - // not found 17.75 -#ifdef ASSERT 17.76 - int index = linear_search(methods, name, signature); 17.77 - assert(index == -1, err_msg("binary search should have found entry %d", index)); 17.78 -#endif 17.79 - return NULL; 17.80 + return mid; 17.81 } else if (res < 0) { 17.82 l = mid + 1; 17.83 } else { 17.84 h = mid - 1; 17.85 } 17.86 } 17.87 + return -1; 17.88 +} 17.89 + 17.90 +Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { 17.91 + return InstanceKlass::find_method(methods(), name, signature); 17.92 +} 17.93 + 17.94 +Method* InstanceKlass::find_method( 17.95 + Array<Method*>* methods, Symbol* name, Symbol* signature) { 17.96 + int hit = binary_search(methods, name); 17.97 + if (hit != -1) { 17.98 + Method* m = methods->at(hit); 17.99 + // Do linear search to find matching signature. First, quick check 17.100 + // for common case 17.101 + if (m->signature() == signature) return m; 17.102 + // search downwards through overloaded methods 17.103 + int i; 17.104 + for (i = hit - 1; i >= 0; --i) { 17.105 + Method* m = methods->at(i); 17.106 + assert(m->is_method(), "must be method"); 17.107 + if (m->name() != name) break; 17.108 + if (m->signature() == signature) return m; 17.109 + } 17.110 + // search upwards 17.111 + for (i = hit + 1; i < methods->length(); ++i) { 17.112 + Method* m = methods->at(i); 17.113 + assert(m->is_method(), "must be method"); 17.114 + if (m->name() != name) break; 17.115 + if (m->signature() == signature) return m; 17.116 + } 17.117 + // not found 17.118 #ifdef ASSERT 17.119 - int index = linear_search(methods, name, signature); 17.120 - assert(index == -1, err_msg("binary search should have found entry %d", index)); 17.121 + int index = linear_search(methods, name, signature); 17.122 + assert(index == -1, err_msg("binary search should have found entry %d", index)); 17.123 #endif 17.124 + } 17.125 return NULL; 17.126 } 17.127 17.128 +int InstanceKlass::find_method_by_name(Symbol* name, int* end) { 17.129 + return find_method_by_name(methods(), name, end); 17.130 +} 17.131 + 17.132 +int InstanceKlass::find_method_by_name( 17.133 + Array<Method*>* methods, Symbol* name, int* end_ptr) { 17.134 + assert(end_ptr != NULL, "just checking"); 17.135 + int start = binary_search(methods, name); 17.136 + int end = start + 1; 17.137 + if (start != -1) { 17.138 + while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start; 17.139 + while (end < methods->length() && (methods->at(end))->name() == name) ++end; 17.140 + *end_ptr = end; 17.141 + return start; 17.142 + } 17.143 + return -1; 17.144 +} 17.145 + 17.146 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { 17.147 Klass* klass = const_cast<InstanceKlass*>(this); 17.148 while (klass != NULL) {
18.1 --- a/src/share/vm/oops/instanceKlass.hpp Fri Nov 02 13:30:47 2012 -0700 18.2 +++ b/src/share/vm/oops/instanceKlass.hpp Fri Nov 02 17:18:16 2012 -0700 18.3 @@ -245,6 +245,10 @@ 18.4 unsigned char * _cached_class_file_bytes; // JVMTI: cached class file, before retransformable agent modified it in CFLH 18.5 jint _cached_class_file_len; // JVMTI: length of above 18.6 JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration 18.7 + 18.8 + // true if class, superclass, or implemented interfaces have default methods 18.9 + bool _has_default_methods; 18.10 + 18.11 volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change 18.12 // Method array. 18.13 Array<Method*>* _methods; 18.14 @@ -492,6 +496,13 @@ 18.15 // (returns NULL if not found) 18.16 Method* lookup_method_in_all_interfaces(Symbol* name, Symbol* signature) const; 18.17 18.18 + // Find method indices by name. If a method with the specified name is 18.19 + // found the index to the first method is returned, and 'end' is filled in 18.20 + // with the index of first non-name-matching method. If no method is found 18.21 + // -1 is returned. 18.22 + int find_method_by_name(Symbol* name, int* end); 18.23 + static int find_method_by_name(Array<Method*>* methods, Symbol* name, int* end); 18.24 + 18.25 // constant pool 18.26 ConstantPool* constants() const { return _constants; } 18.27 void set_constants(ConstantPool* c) { _constants = c; } 18.28 @@ -592,6 +603,9 @@ 18.29 return _jvmti_cached_class_field_map; 18.30 } 18.31 18.32 + bool has_default_methods() const { return _has_default_methods; } 18.33 + void set_has_default_methods(bool b) { _has_default_methods = b; } 18.34 + 18.35 // for adding methods, ConstMethod::UNSET_IDNUM means no more ids available 18.36 inline u2 next_method_idnum(); 18.37 void set_initial_method_idnum(u2 value) { _idnum_allocated_count = value; } 18.38 @@ -728,7 +742,6 @@ 18.39 GrowableArray<Klass*>* compute_secondary_supers(int num_extra_slots); 18.40 bool compute_is_subtype_of(Klass* k); 18.41 bool can_be_primary_super_slow() const; 18.42 - Klass* java_super() const { return super(); } 18.43 int oop_size(oop obj) const { return size_helper(); } 18.44 bool oop_is_instance_slow() const { return true; } 18.45 18.46 @@ -750,6 +763,10 @@ 18.47 return (InstanceKlass*) k; 18.48 } 18.49 18.50 + InstanceKlass* java_super() const { 18.51 + return (super() == NULL) ? NULL : cast(super()); 18.52 + } 18.53 + 18.54 // Sizing (in words) 18.55 static int header_size() { return align_object_offset(sizeof(InstanceKlass)/HeapWordSize); } 18.56 static int size(int vtable_length, int itable_length,
19.1 --- a/src/share/vm/oops/klassVtable.cpp Fri Nov 02 13:30:47 2012 -0700 19.2 +++ b/src/share/vm/oops/klassVtable.cpp Fri Nov 02 17:18:16 2012 -0700 19.3 @@ -54,22 +54,16 @@ 19.4 // the same name and signature as m), then m is a Miranda method which is 19.5 // entered as a public abstract method in C's vtable. From then on it should 19.6 // treated as any other public method in C for method over-ride purposes. 19.7 -void klassVtable::compute_vtable_size_and_num_mirandas(int &vtable_length, 19.8 - int &num_miranda_methods, 19.9 - Klass* super, 19.10 - Array<Method*>* methods, 19.11 - AccessFlags class_flags, 19.12 - Handle classloader, 19.13 - Symbol* classname, 19.14 - Array<Klass*>* local_interfaces, 19.15 - TRAPS 19.16 - ) { 19.17 - 19.18 +void klassVtable::compute_vtable_size_and_num_mirandas( 19.19 + int* vtable_length_ret, int* num_new_mirandas, 19.20 + GrowableArray<Method*>* all_mirandas, Klass* super, 19.21 + Array<Method*>* methods, AccessFlags class_flags, 19.22 + Handle classloader, Symbol* classname, Array<Klass*>* local_interfaces, 19.23 + TRAPS) { 19.24 No_Safepoint_Verifier nsv; 19.25 19.26 // set up default result values 19.27 - vtable_length = 0; 19.28 - num_miranda_methods = 0; 19.29 + int vtable_length = 0; 19.30 19.31 // start off with super's vtable length 19.32 InstanceKlass* sk = (InstanceKlass*)super; 19.33 @@ -86,9 +80,12 @@ 19.34 } 19.35 } 19.36 19.37 + GrowableArray<Method*> new_mirandas(20); 19.38 // compute the number of mirandas methods that must be added to the end 19.39 - num_miranda_methods = get_num_mirandas(super, methods, local_interfaces); 19.40 - vtable_length += (num_miranda_methods * vtableEntry::size()); 19.41 + get_mirandas(&new_mirandas, all_mirandas, super, methods, local_interfaces); 19.42 + *num_new_mirandas = new_mirandas.length(); 19.43 + 19.44 + vtable_length += *num_new_mirandas * vtableEntry::size(); 19.45 19.46 if (Universe::is_bootstrapping() && vtable_length == 0) { 19.47 // array classes don't have their superclass set correctly during 19.48 @@ -109,6 +106,8 @@ 19.49 "bad vtable size for class Object"); 19.50 assert(vtable_length % vtableEntry::size() == 0, "bad vtable length"); 19.51 assert(vtable_length >= Universe::base_vtable_size(), "vtable too small"); 19.52 + 19.53 + *vtable_length_ret = vtable_length; 19.54 } 19.55 19.56 int klassVtable::index_of(Method* m, int len) const { 19.57 @@ -191,7 +190,7 @@ 19.58 } 19.59 19.60 // add miranda methods; it will also update the value of initialized 19.61 - fill_in_mirandas(initialized); 19.62 + fill_in_mirandas(&initialized); 19.63 19.64 // In class hierarchies where the accessibility is not increasing (i.e., going from private -> 19.65 // package_private -> publicprotected), the vtable might actually be smaller than our initial 19.66 @@ -249,6 +248,11 @@ 19.67 return superk; 19.68 } 19.69 19.70 +// Methods that are "effectively" final don't need vtable entries. 19.71 +bool method_is_effectively_final( 19.72 + AccessFlags klass_flags, methodHandle target) { 19.73 + return target->is_final() || klass_flags.is_final() && !target->is_overpass(); 19.74 +} 19.75 19.76 // Update child's copy of super vtable for overrides 19.77 // OR return true if a new vtable entry is required 19.78 @@ -269,7 +273,7 @@ 19.79 return false; 19.80 } 19.81 19.82 - if (klass->is_final() || target_method()->is_final()) { 19.83 + if (method_is_effectively_final(klass->access_flags(), target_method)) { 19.84 // a final method never needs a new entry; final methods can be statically 19.85 // resolved and they have to be present in the vtable only if they override 19.86 // a super's method, in which case they re-use its entry 19.87 @@ -406,7 +410,8 @@ 19.88 Symbol* classname, 19.89 AccessFlags class_flags, 19.90 TRAPS) { 19.91 - if ((class_flags.is_final() || target_method()->is_final()) || 19.92 + 19.93 + if (method_is_effectively_final(class_flags, target_method) || 19.94 // a final method never needs a new entry; final methods can be statically 19.95 // resolved and they have to be present in the vtable only if they override 19.96 // a super's method, in which case they re-use its entry 19.97 @@ -502,7 +507,7 @@ 19.98 19.99 // miranda methods are interface methods in a class's vtable 19.100 if (mhk->is_interface()) { 19.101 - assert(m->is_public() && m->is_abstract(), "should be public and abstract"); 19.102 + assert(m->is_public(), "should be public"); 19.103 assert(ik()->implements_interface(method_holder) , "this class should implement the interface"); 19.104 assert(is_miranda(m, ik()->methods(), ik()->super()), "should be a miranda_method"); 19.105 return true; 19.106 @@ -532,19 +537,19 @@ 19.107 return false; 19.108 } 19.109 19.110 -void klassVtable::add_new_mirandas_to_list(GrowableArray<Method*>* list_of_current_mirandas, 19.111 - Array<Method*>* current_interface_methods, 19.112 - Array<Method*>* class_methods, 19.113 - Klass* super) { 19.114 +void klassVtable::add_new_mirandas_to_lists( 19.115 + GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas, 19.116 + Array<Method*>* current_interface_methods, Array<Method*>* class_methods, 19.117 + Klass* super) { 19.118 // iterate thru the current interface's method to see if it a miranda 19.119 int num_methods = current_interface_methods->length(); 19.120 for (int i = 0; i < num_methods; i++) { 19.121 Method* im = current_interface_methods->at(i); 19.122 bool is_duplicate = false; 19.123 - int num_of_current_mirandas = list_of_current_mirandas->length(); 19.124 + int num_of_current_mirandas = new_mirandas->length(); 19.125 // check for duplicate mirandas in different interfaces we implement 19.126 for (int j = 0; j < num_of_current_mirandas; j++) { 19.127 - Method* miranda = list_of_current_mirandas->at(j); 19.128 + Method* miranda = new_mirandas->at(j); 19.129 if ((im->name() == miranda->name()) && 19.130 (im->signature() == miranda->signature())) { 19.131 is_duplicate = true; 19.132 @@ -557,51 +562,47 @@ 19.133 InstanceKlass *sk = InstanceKlass::cast(super); 19.134 // check if it is a duplicate of a super's miranda 19.135 if (sk->lookup_method_in_all_interfaces(im->name(), im->signature()) == NULL) { 19.136 - list_of_current_mirandas->append(im); 19.137 + new_mirandas->append(im); 19.138 + } 19.139 + if (all_mirandas != NULL) { 19.140 + all_mirandas->append(im); 19.141 } 19.142 } 19.143 } 19.144 } 19.145 } 19.146 19.147 -void klassVtable::get_mirandas(GrowableArray<Method*>* mirandas, 19.148 +void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas, 19.149 + GrowableArray<Method*>* all_mirandas, 19.150 Klass* super, Array<Method*>* class_methods, 19.151 Array<Klass*>* local_interfaces) { 19.152 - assert((mirandas->length() == 0) , "current mirandas must be 0"); 19.153 + assert((new_mirandas->length() == 0) , "current mirandas must be 0"); 19.154 19.155 // iterate thru the local interfaces looking for a miranda 19.156 int num_local_ifs = local_interfaces->length(); 19.157 for (int i = 0; i < num_local_ifs; i++) { 19.158 InstanceKlass *ik = InstanceKlass::cast(local_interfaces->at(i)); 19.159 - add_new_mirandas_to_list(mirandas, ik->methods(), class_methods, super); 19.160 + add_new_mirandas_to_lists(new_mirandas, all_mirandas, 19.161 + ik->methods(), class_methods, super); 19.162 // iterate thru each local's super interfaces 19.163 Array<Klass*>* super_ifs = ik->transitive_interfaces(); 19.164 int num_super_ifs = super_ifs->length(); 19.165 for (int j = 0; j < num_super_ifs; j++) { 19.166 InstanceKlass *sik = InstanceKlass::cast(super_ifs->at(j)); 19.167 - add_new_mirandas_to_list(mirandas, sik->methods(), class_methods, super); 19.168 + add_new_mirandas_to_lists(new_mirandas, all_mirandas, 19.169 + sik->methods(), class_methods, super); 19.170 } 19.171 } 19.172 } 19.173 19.174 -// get number of mirandas 19.175 -int klassVtable::get_num_mirandas(Klass* super, Array<Method*>* class_methods, Array<Klass*>* local_interfaces) { 19.176 - ResourceMark rm; 19.177 - GrowableArray<Method*>* mirandas = new GrowableArray<Method*>(20); 19.178 - get_mirandas(mirandas, super, class_methods, local_interfaces); 19.179 - return mirandas->length(); 19.180 -} 19.181 - 19.182 // fill in mirandas 19.183 -void klassVtable::fill_in_mirandas(int& initialized) { 19.184 - ResourceMark rm; 19.185 - GrowableArray<Method*>* mirandas = new GrowableArray<Method*>(20); 19.186 - InstanceKlass *this_ik = ik(); 19.187 - get_mirandas(mirandas, this_ik->super(), this_ik->methods(), this_ik->local_interfaces()); 19.188 - int num_mirandas = mirandas->length(); 19.189 - for (int i = 0; i < num_mirandas; i++) { 19.190 - put_method_at(mirandas->at(i), initialized); 19.191 - initialized++; 19.192 +void klassVtable::fill_in_mirandas(int* initialized) { 19.193 + GrowableArray<Method*> mirandas(20); 19.194 + get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(), 19.195 + ik()->local_interfaces()); 19.196 + for (int i = 0; i < mirandas.length(); i++) { 19.197 + put_method_at(mirandas.at(i), *initialized); 19.198 + ++(*initialized); 19.199 } 19.200 } 19.201
20.1 --- a/src/share/vm/oops/klassVtable.hpp Fri Nov 02 13:30:47 2012 -0700 20.2 +++ b/src/share/vm/oops/klassVtable.hpp Fri Nov 02 17:18:16 2012 -0700 20.3 @@ -84,11 +84,11 @@ 20.4 bool is_initialized(); 20.5 20.6 // computes vtable length (in words) and the number of miranda methods 20.7 - static void compute_vtable_size_and_num_mirandas(int &vtable_length, int &num_miranda_methods, 20.8 - Klass* super, Array<Method*>* methods, 20.9 - AccessFlags class_flags, Handle classloader, 20.10 - Symbol* classname, Array<Klass*>* local_interfaces, 20.11 - TRAPS); 20.12 + static void compute_vtable_size_and_num_mirandas( 20.13 + int* vtable_length, int* num_new_mirandas, 20.14 + GrowableArray<Method*>* all_mirandas, Klass* super, 20.15 + Array<Method*>* methods, AccessFlags class_flags, Handle classloader, 20.16 + Symbol* classname, Array<Klass*>* local_interfaces, TRAPS); 20.17 20.18 // RedefineClasses() API support: 20.19 // If any entry of this vtable points to any of old_methods, 20.20 @@ -125,12 +125,17 @@ 20.21 20.22 // support for miranda methods 20.23 bool is_miranda_entry_at(int i); 20.24 - void fill_in_mirandas(int& initialized); 20.25 + void fill_in_mirandas(int* initialized); 20.26 static bool is_miranda(Method* m, Array<Method*>* class_methods, Klass* super); 20.27 - static void add_new_mirandas_to_list(GrowableArray<Method*>* list_of_current_mirandas, Array<Method*>* current_interface_methods, Array<Method*>* class_methods, Klass* super); 20.28 - static void get_mirandas(GrowableArray<Method*>* mirandas, Klass* super, Array<Method*>* class_methods, Array<Klass*>* local_interfaces); 20.29 - static int get_num_mirandas(Klass* super, Array<Method*>* class_methods, Array<Klass*>* local_interfaces); 20.30 - 20.31 + static void add_new_mirandas_to_lists( 20.32 + GrowableArray<Method*>* new_mirandas, 20.33 + GrowableArray<Method*>* all_mirandas, 20.34 + Array<Method*>* current_interface_methods, Array<Method*>* class_methods, 20.35 + Klass* super); 20.36 + static void get_mirandas( 20.37 + GrowableArray<Method*>* new_mirandas, 20.38 + GrowableArray<Method*>* all_mirandas, Klass* super, 20.39 + Array<Method*>* class_methods, Array<Klass*>* local_interfaces); 20.40 20.41 void verify_against(outputStream* st, klassVtable* vt, int index); 20.42 inline InstanceKlass* ik() const;
21.1 --- a/src/share/vm/oops/method.cpp Fri Nov 02 13:30:47 2012 -0700 21.2 +++ b/src/share/vm/oops/method.cpp Fri Nov 02 17:18:16 2012 -0700 21.3 @@ -35,6 +35,7 @@ 21.4 #include "memory/generation.hpp" 21.5 #include "memory/metadataFactory.hpp" 21.6 #include "memory/oopFactory.hpp" 21.7 +#include "oops/constMethod.hpp" 21.8 #include "oops/methodData.hpp" 21.9 #include "oops/method.hpp" 21.10 #include "oops/oop.inline.hpp" 21.11 @@ -57,22 +58,24 @@ 21.12 // Implementation of Method 21.13 21.14 Method* Method::allocate(ClassLoaderData* loader_data, 21.15 - int byte_code_size, 21.16 - AccessFlags access_flags, 21.17 - int compressed_line_number_size, 21.18 - int localvariable_table_length, 21.19 - int exception_table_length, 21.20 - int checked_exceptions_length, 21.21 - TRAPS) { 21.22 + int byte_code_size, 21.23 + AccessFlags access_flags, 21.24 + int compressed_line_number_size, 21.25 + int localvariable_table_length, 21.26 + int exception_table_length, 21.27 + int checked_exceptions_length, 21.28 + ConstMethod::MethodType method_type, 21.29 + TRAPS) { 21.30 assert(!access_flags.is_native() || byte_code_size == 0, 21.31 "native methods should not contain byte codes"); 21.32 ConstMethod* cm = ConstMethod::allocate(loader_data, 21.33 - byte_code_size, 21.34 - compressed_line_number_size, 21.35 - localvariable_table_length, 21.36 - exception_table_length, 21.37 - checked_exceptions_length, 21.38 - CHECK_NULL); 21.39 + byte_code_size, 21.40 + compressed_line_number_size, 21.41 + localvariable_table_length, 21.42 + exception_table_length, 21.43 + checked_exceptions_length, 21.44 + method_type, 21.45 + CHECK_NULL); 21.46 21.47 int size = Method::size(access_flags.is_native()); 21.48 21.49 @@ -1031,7 +1034,7 @@ 21.50 methodHandle m; 21.51 { 21.52 Method* m_oop = Method::allocate(loader_data, 0, accessFlags_from(flags_bits), 21.53 - 0, 0, 0, 0, CHECK_(empty)); 21.54 + 0, 0, 0, 0, ConstMethod::NORMAL, CHECK_(empty)); 21.55 m = methodHandle(THREAD, m_oop); 21.56 } 21.57 m->set_constants(cp()); 21.58 @@ -1083,15 +1086,16 @@ 21.59 int localvariable_len = m->localvariable_table_length(); 21.60 int exception_table_len = m->exception_table_length(); 21.61 21.62 - ClassLoaderData* loader_data = m()->method_holder()->class_loader_data(); 21.63 + ClassLoaderData* loader_data = m->method_holder()->class_loader_data(); 21.64 Method* newm_oop = Method::allocate(loader_data, 21.65 - new_code_length, 21.66 - flags, 21.67 - new_compressed_linenumber_size, 21.68 - localvariable_len, 21.69 - exception_table_len, 21.70 - checked_exceptions_len, 21.71 - CHECK_(methodHandle())); 21.72 + new_code_length, 21.73 + flags, 21.74 + new_compressed_linenumber_size, 21.75 + localvariable_len, 21.76 + exception_table_len, 21.77 + checked_exceptions_len, 21.78 + m->method_type(), 21.79 + CHECK_(methodHandle())); 21.80 methodHandle newm (THREAD, newm_oop); 21.81 int new_method_size = newm->method_size(); 21.82
22.1 --- a/src/share/vm/oops/method.hpp Fri Nov 02 13:30:47 2012 -0700 22.2 +++ b/src/share/vm/oops/method.hpp Fri Nov 02 17:18:16 2012 -0700 22.3 @@ -30,7 +30,6 @@ 22.4 #include "compiler/oopMap.hpp" 22.5 #include "interpreter/invocationCounter.hpp" 22.6 #include "oops/annotations.hpp" 22.7 -#include "oops/constMethod.hpp" 22.8 #include "oops/constantPool.hpp" 22.9 #include "oops/instanceKlass.hpp" 22.10 #include "oops/oop.hpp" 22.11 @@ -104,6 +103,7 @@ 22.12 class LocalVariableTableElement; 22.13 class AdapterHandlerEntry; 22.14 class MethodData; 22.15 +class ConstMethod; 22.16 22.17 class Method : public Metadata { 22.18 friend class VMStructs; 22.19 @@ -158,14 +158,16 @@ 22.20 // Constructor 22.21 Method(ConstMethod* xconst, AccessFlags access_flags, int size); 22.22 public: 22.23 + 22.24 static Method* allocate(ClassLoaderData* loader_data, 22.25 - int byte_code_size, 22.26 - AccessFlags access_flags, 22.27 - int compressed_line_number_size, 22.28 - int localvariable_table_length, 22.29 - int exception_table_length, 22.30 - int checked_exceptions_length, 22.31 - TRAPS); 22.32 + int byte_code_size, 22.33 + AccessFlags access_flags, 22.34 + int compressed_line_number_size, 22.35 + int localvariable_table_length, 22.36 + int exception_table_length, 22.37 + int checked_exceptions_length, 22.38 + ConstMethod::MethodType method_type, 22.39 + TRAPS); 22.40 22.41 Method() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); } 22.42 22.43 @@ -725,6 +727,10 @@ 22.44 void set_dont_inline(bool x) { _dont_inline = x; } 22.45 bool is_hidden() { return _hidden; } 22.46 void set_hidden(bool x) { _hidden = x; } 22.47 + ConstMethod::MethodType method_type() const { 22.48 + return _constMethod->method_type(); 22.49 + } 22.50 + bool is_overpass() const { return method_type() == ConstMethod::OVERPASS; } 22.51 22.52 // On-stack replacement support 22.53 bool has_osr_nmethod(int level, bool match_level) {
23.1 --- a/src/share/vm/runtime/globals.hpp Fri Nov 02 13:30:47 2012 -0700 23.2 +++ b/src/share/vm/runtime/globals.hpp Fri Nov 02 17:18:16 2012 -0700 23.3 @@ -3596,6 +3596,15 @@ 23.4 product(uintx, StringTableSize, 1009, \ 23.5 "Number of buckets in the interned String table") \ 23.6 \ 23.7 + develop(bool, TraceDefaultMethods, false, \ 23.8 + "Trace the default method processing steps") \ 23.9 + \ 23.10 + develop(bool, ParseAllGenericSignatures, false, \ 23.11 + "Parse all generic signatures while classloading") \ 23.12 + \ 23.13 + develop(bool, VerifyGenericSignatures, false, \ 23.14 + "Abort VM on erroneous or inconsistent generic signatures") \ 23.15 + \ 23.16 product(bool, UseVMInterruptibleIO, false, \ 23.17 "(Unstable, Solaris-specific) Thread interrupt before or with " \ 23.18 "EINTR for I/O operations results in OS_INTRPT. The default value"\
24.1 --- a/src/share/vm/runtime/reflection.cpp Fri Nov 02 13:30:47 2012 -0700 24.2 +++ b/src/share/vm/runtime/reflection.cpp Fri Nov 02 17:18:16 2012 -0700 24.3 @@ -472,6 +472,12 @@ 24.4 return true; 24.5 } 24.6 24.7 + // Also allow all accesses from 24.8 + // java/lang/invoke/MagicLambdaImpl subclasses to succeed trivially. 24.9 + if (current_class->is_subclass_of(SystemDictionary::lambda_MagicLambdaImpl_klass())) { 24.10 + return true; 24.11 + } 24.12 + 24.13 return can_relax_access_check_for(current_class, new_class, classloader_only); 24.14 } 24.15 24.16 @@ -564,6 +570,12 @@ 24.17 return true; 24.18 } 24.19 24.20 + // Also allow all accesses from 24.21 + // java/lang/invoke/MagicLambdaImpl subclasses to succeed trivially. 24.22 + if (current_class->is_subclass_of(SystemDictionary::lambda_MagicLambdaImpl_klass())) { 24.23 + return true; 24.24 + } 24.25 + 24.26 return can_relax_access_check_for( 24.27 current_class, field_class, classloader_only); 24.28 }
25.1 --- a/src/share/vm/utilities/growableArray.hpp Fri Nov 02 13:30:47 2012 -0700 25.2 +++ b/src/share/vm/utilities/growableArray.hpp Fri Nov 02 17:18:16 2012 -0700 25.3 @@ -217,7 +217,12 @@ 25.4 return missed; 25.5 } 25.6 25.7 - E at(int i) const { 25.8 + E& at(int i) { 25.9 + assert(0 <= i && i < _len, "illegal index"); 25.10 + return _data[i]; 25.11 + } 25.12 + 25.13 + E const& at(int i) const { 25.14 assert(0 <= i && i < _len, "illegal index"); 25.15 return _data[i]; 25.16 }
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/src/share/vm/utilities/pair.hpp Fri Nov 02 17:18:16 2012 -0700 26.3 @@ -0,0 +1,42 @@ 26.4 +/* 26.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 26.7 + * 26.8 + * This code is free software; you can redistribute it and/or modify it 26.9 + * under the terms of the GNU General Public License version 2 only, as 26.10 + * published by the Free Software Foundation. 26.11 + * 26.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 26.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26.15 + * version 2 for more details (a copy is included in the LICENSE file that 26.16 + * accompanied this code). 26.17 + * 26.18 + * You should have received a copy of the GNU General Public License version 26.19 + * 2 along with this work; if not, write to the Free Software Foundation, 26.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 26.21 + * 26.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 26.23 + * or visit www.oracle.com if you need additional information or have any 26.24 + * questions. 26.25 + * 26.26 + */ 26.27 + 26.28 +#ifndef SHARE_VM_UTILITIES_PAIR_HPP 26.29 +#define SHARE_VM_UTILITIES_PAIR_HPP 26.30 + 26.31 +#include "memory/allocation.hpp" 26.32 +#include "utilities/top.hpp" 26.33 + 26.34 +template<typename T, typename V, typename ALLOC_BASE = ResourceObj> 26.35 +class Pair : public ALLOC_BASE { 26.36 + public: 26.37 + T first; 26.38 + V second; 26.39 + 26.40 + Pair() {} 26.41 + Pair(T t, V v) : first(t), second(v) {} 26.42 +}; 26.43 + 26.44 + 26.45 +#endif // SHARE_VM_UTILITIES_PAIR_HPP
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/src/share/vm/utilities/resourceHash.hpp Fri Nov 02 17:18:16 2012 -0700 27.3 @@ -0,0 +1,134 @@ 27.4 +/* 27.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.7 + * 27.8 + * This code is free software; you can redistribute it and/or modify it 27.9 + * under the terms of the GNU General Public License version 2 only, as 27.10 + * published by the Free Software Foundation. 27.11 + * 27.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 27.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.15 + * version 2 for more details (a copy is included in the LICENSE file that 27.16 + * accompanied this code). 27.17 + * 27.18 + * You should have received a copy of the GNU General Public License version 27.19 + * 2 along with this work; if not, write to the Free Software Foundation, 27.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.21 + * 27.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 27.23 + * or visit www.oracle.com if you need additional information or have any 27.24 + * questions. 27.25 + * 27.26 + */ 27.27 + 27.28 +#ifndef SHARE_VM_UTILITIES_RESOURCEHASH_HPP 27.29 +#define SHARE_VM_UTILITIES_RESOURCEHASH_HPP 27.30 + 27.31 +#include "memory/allocation.hpp" 27.32 +#include "utilities/top.hpp" 27.33 + 27.34 +template<typename K> struct ResourceHashtableFns { 27.35 + typedef unsigned (*hash_fn)(K const&); 27.36 + typedef bool (*equals_fn)(K const&, K const&); 27.37 +}; 27.38 + 27.39 +template<typename K> unsigned primitive_hash(const K& k) { 27.40 + unsigned hash = (unsigned)((uintptr_t)k); 27.41 + return hash ^ (hash > 3); // just in case we're dealing with aligned ptrs 27.42 +} 27.43 + 27.44 +template<typename K> bool primitive_equals(const K& k0, const K& k1) { 27.45 + return k0 == k1; 27.46 +} 27.47 + 27.48 +template< 27.49 + typename K, typename V, 27.50 + typename ResourceHashtableFns<K>::hash_fn HASH = primitive_hash<K>, 27.51 + typename ResourceHashtableFns<K>::equals_fn EQUALS = primitive_equals<K>, 27.52 + unsigned SIZE = 256 27.53 + > 27.54 +class ResourceHashtable : public ResourceObj { 27.55 + private: 27.56 + 27.57 + class Node : public ResourceObj { 27.58 + public: 27.59 + unsigned _hash; 27.60 + K _key; 27.61 + V _value; 27.62 + Node* _next; 27.63 + 27.64 + Node(unsigned hash, K const& key, V const& value) : 27.65 + _hash(hash), _key(key), _value(value), _next(NULL) {} 27.66 + }; 27.67 + 27.68 + Node* _table[SIZE]; 27.69 + 27.70 + // Returns a pointer to where the node where the value would reside if 27.71 + // it's in the table. 27.72 + Node** lookup_node(unsigned hash, K const& key) { 27.73 + unsigned index = hash % SIZE; 27.74 + Node** ptr = &_table[index]; 27.75 + while (*ptr != NULL) { 27.76 + Node* node = *ptr; 27.77 + if (node->_hash == hash && EQUALS(key, node->_key)) { 27.78 + break; 27.79 + } 27.80 + ptr = &(node->_next); 27.81 + } 27.82 + return ptr; 27.83 + } 27.84 + 27.85 + Node const** lookup_node(unsigned hash, K const& key) const { 27.86 + return const_cast<Node const**>( 27.87 + const_cast<ResourceHashtable*>(this)->lookup_node(hash, key)); 27.88 + } 27.89 + 27.90 + public: 27.91 + ResourceHashtable() { memset(_table, 0, SIZE * sizeof(Node*)); } 27.92 + 27.93 + bool contains(K const& key) const { 27.94 + return get(key) != NULL; 27.95 + } 27.96 + 27.97 + V* get(K const& key) const { 27.98 + unsigned hv = HASH(key); 27.99 + Node const** ptr = lookup_node(hv, key); 27.100 + if (*ptr != NULL) { 27.101 + return const_cast<V*>(&(*ptr)->_value); 27.102 + } else { 27.103 + return NULL; 27.104 + } 27.105 + } 27.106 + 27.107 + // Inserts or replaces a value in the table 27.108 + void put(K const& key, V const& value) { 27.109 + unsigned hv = HASH(key); 27.110 + Node** ptr = lookup_node(hv, key); 27.111 + if (*ptr != NULL) { 27.112 + (*ptr)->_value = value; 27.113 + } else { 27.114 + *ptr = new Node(hv, key, value); 27.115 + } 27.116 + } 27.117 + 27.118 + // ITER contains bool do_entry(K const&, V const&), which will be 27.119 + // called for each entry in the table. If do_entry() returns false, 27.120 + // the iteration is cancelled. 27.121 + template<class ITER> 27.122 + void iterate(ITER* iter) const { 27.123 + Node* const* bucket = _table; 27.124 + while (bucket < &_table[SIZE]) { 27.125 + Node* node = *bucket; 27.126 + while (node != NULL) { 27.127 + bool cont = iter->do_entry(node->_key, node->_value); 27.128 + if (!cont) { return; } 27.129 + node = node->_next; 27.130 + } 27.131 + ++bucket; 27.132 + } 27.133 + } 27.134 +}; 27.135 + 27.136 + 27.137 +#endif // SHARE_VM_UTILITIES_RESOURCEHASH_HPP