Mercurial > hg > graal-jvmci-8
changeset 2370:048f98400b8e
Merge
author | jcoomes |
---|---|
date | Fri, 18 Mar 2011 09:03:43 -0700 |
parents | fc5ebbb2d1a8 (diff) 92da084fefc9 (current diff) |
children | e97ad5d5c990 d673ef06fe96 |
files | src/share/vm/runtime/arguments.cpp src/share/vm/runtime/globals.hpp |
diffstat | 106 files changed, 3661 insertions(+), 1598 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Thu Mar 17 10:32:46 2011 -0700 +++ b/.hgtags Fri Mar 18 09:03:43 2011 -0700 @@ -151,3 +151,6 @@ e9aa2ca89ad6c53420623d579765f9706ec523d7 jdk7-b130 0aa3b49089112d5faa77902ad680c582ab53f651 jdk7-b131 e9aa2ca89ad6c53420623d579765f9706ec523d7 hs21-b02 +0e531ab5ba04967a0e9aa6aef65e6eb3a0dcf632 jdk7-b132 +a8d643a4db47c7b58e0bcb49c77b5c3610de86a8 hs21-b03 +1b3a350709e4325d759bb453ff3fb6a463270488 jdk7-b133
--- a/make/hotspot_version Thu Mar 17 10:32:46 2011 -0700 +++ b/make/hotspot_version Fri Mar 18 09:03:43 2011 -0700 @@ -35,7 +35,7 @@ HS_MAJOR_VER=21 HS_MINOR_VER=0 -HS_BUILD_NUMBER=03 +HS_BUILD_NUMBER=04 JDK_MAJOR_VER=1 JDK_MINOR_VER=7
--- a/src/cpu/sparc/vm/assembler_sparc.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/sparc/vm/assembler_sparc.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -3179,7 +3179,7 @@ Label& wrong_method_type) { assert_different_registers(mtype_reg, mh_reg, temp_reg); // compare method type against that of the receiver - RegisterOrConstant mhtype_offset = delayed_value(java_dyn_MethodHandle::type_offset_in_bytes, temp_reg); + RegisterOrConstant mhtype_offset = delayed_value(java_lang_invoke_MethodHandle::type_offset_in_bytes, temp_reg); load_heap_oop(mh_reg, mhtype_offset, temp_reg); cmp(temp_reg, mtype_reg); br(Assembler::notEqual, false, Assembler::pn, wrong_method_type); @@ -3195,14 +3195,14 @@ Register temp_reg) { assert_different_registers(vmslots_reg, mh_reg, temp_reg); // load mh.type.form.vmslots - if (java_dyn_MethodHandle::vmslots_offset_in_bytes() != 0) { + if (java_lang_invoke_MethodHandle::vmslots_offset_in_bytes() != 0) { // hoist vmslots into every mh to avoid dependent load chain - ld( Address(mh_reg, delayed_value(java_dyn_MethodHandle::vmslots_offset_in_bytes, temp_reg)), vmslots_reg); + ld( Address(mh_reg, delayed_value(java_lang_invoke_MethodHandle::vmslots_offset_in_bytes, temp_reg)), vmslots_reg); } else { Register temp2_reg = vmslots_reg; - load_heap_oop(Address(mh_reg, delayed_value(java_dyn_MethodHandle::type_offset_in_bytes, temp_reg)), temp2_reg); - load_heap_oop(Address(temp2_reg, delayed_value(java_dyn_MethodType::form_offset_in_bytes, temp_reg)), temp2_reg); - ld( Address(temp2_reg, delayed_value(java_dyn_MethodTypeForm::vmslots_offset_in_bytes, temp_reg)), vmslots_reg); + load_heap_oop(Address(mh_reg, delayed_value(java_lang_invoke_MethodHandle::type_offset_in_bytes, temp_reg)), temp2_reg); + load_heap_oop(Address(temp2_reg, delayed_value(java_lang_invoke_MethodType::form_offset_in_bytes, temp_reg)), temp2_reg); + ld( Address(temp2_reg, delayed_value(java_lang_invoke_MethodTypeForm::vmslots_offset_in_bytes, temp_reg)), vmslots_reg); } } @@ -3213,7 +3213,7 @@ // pick out the interpreted side of the handler // NOTE: vmentry is not an oop! - ld_ptr(mh_reg, delayed_value(java_dyn_MethodHandle::vmentry_offset_in_bytes, temp_reg), temp_reg); + ld_ptr(mh_reg, delayed_value(java_lang_invoke_MethodHandle::vmentry_offset_in_bytes, temp_reg), temp_reg); // off we go... ld_ptr(temp_reg, MethodHandleEntry::from_interpreted_entry_offset_in_bytes(), temp_reg);
--- a/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -395,9 +395,9 @@ int offset = code_offset(); - __ call(Runtime1::entry_for(Runtime1::handle_exception_id), relocInfo::runtime_call_type); + __ call(Runtime1::entry_for(Runtime1::handle_exception_from_callee_id), relocInfo::runtime_call_type); __ delayed()->nop(); - debug_only(__ stop("should have gone to the caller");) + __ should_not_reach_here(); assert(code_offset() - offset <= exception_handler_size, "overflow"); __ end_a_stub();
--- a/src/cpu/sparc/vm/c1_Runtime1_sparc.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/sparc/vm/c1_Runtime1_sparc.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -148,7 +148,7 @@ static OopMap* generate_oop_map(StubAssembler* sasm, bool save_fpu_registers) { assert(frame_size_in_bytes == __ total_frame_size_in_bytes(reg_save_size_in_words), - " mismatch in calculation"); + "mismatch in calculation"); sasm->set_frame_size(frame_size_in_bytes / BytesPerWord); int frame_size_in_slots = frame_size_in_bytes / sizeof(jint); OopMap* oop_map = new OopMap(frame_size_in_slots, 0); @@ -176,9 +176,8 @@ static OopMap* save_live_registers(StubAssembler* sasm, bool save_fpu_registers = true) { assert(frame_size_in_bytes == __ total_frame_size_in_bytes(reg_save_size_in_words), - " mismatch in calculation"); + "mismatch in calculation"); __ save_frame_c1(frame_size_in_bytes); - sasm->set_frame_size(frame_size_in_bytes / BytesPerWord); // Record volatile registers as callee-save values in an OopMap so their save locations will be // propagated to the caller frame's RegisterMap during StackFrameStream construction (needed for @@ -367,23 +366,7 @@ switch (id) { case forward_exception_id: { - // we're handling an exception in the context of a compiled - // frame. The registers have been saved in the standard - // places. Perform an exception lookup in the caller and - // dispatch to the handler if found. Otherwise unwind and - // dispatch to the callers exception handler. - - oop_maps = new OopMapSet(); - OopMap* oop_map = generate_oop_map(sasm, true); - - // transfer the pending exception to the exception_oop - __ ld_ptr(G2_thread, in_bytes(JavaThread::pending_exception_offset()), Oexception); - __ ld_ptr(Oexception, 0, G0); - __ st_ptr(G0, G2_thread, in_bytes(JavaThread::pending_exception_offset())); - __ add(I7, frame::pc_return_offset, Oissuing_pc); - - generate_handle_exception(sasm, oop_maps, oop_map); - __ should_not_reach_here(); + oop_maps = generate_handle_exception(id, sasm); } break; @@ -671,15 +654,14 @@ break; case handle_exception_id: - { - __ set_info("handle_exception", dont_gc_arguments); - // make a frame and preserve the caller's caller-save registers + { __ set_info("handle_exception", dont_gc_arguments); + oop_maps = generate_handle_exception(id, sasm); + } + break; - oop_maps = new OopMapSet(); - OopMap* oop_map = save_live_registers(sasm); - __ mov(Oexception->after_save(), Oexception); - __ mov(Oissuing_pc->after_save(), Oissuing_pc); - generate_handle_exception(sasm, oop_maps, oop_map); + case handle_exception_from_callee_id: + { __ set_info("handle_exception_from_callee", dont_gc_arguments); + oop_maps = generate_handle_exception(id, sasm); } break; @@ -696,7 +678,7 @@ G2_thread, Oissuing_pc->after_save()); __ verify_not_null_oop(Oexception->after_save()); - // Restore SP from L7 if the exception PC is a MethodHandle call site. + // Restore SP from L7 if the exception PC is a method handle call site. __ mov(O0, G5); // Save the target address. __ lduw(Address(G2_thread, JavaThread::is_method_handle_return_offset()), L0); __ tst(L0); // Condition codes are preserved over the restore. @@ -1006,48 +988,89 @@ } -void Runtime1::generate_handle_exception(StubAssembler* sasm, OopMapSet* oop_maps, OopMap* oop_map, bool) { - Label no_deopt; +OopMapSet* Runtime1::generate_handle_exception(StubID id, StubAssembler* sasm) { + __ block_comment("generate_handle_exception"); + + // Save registers, if required. + OopMapSet* oop_maps = new OopMapSet(); + OopMap* oop_map = NULL; + switch (id) { + case forward_exception_id: + // We're handling an exception in the context of a compiled frame. + // The registers have been saved in the standard places. Perform + // an exception lookup in the caller and dispatch to the handler + // if found. Otherwise unwind and dispatch to the callers + // exception handler. + oop_map = generate_oop_map(sasm, true); + + // transfer the pending exception to the exception_oop + __ ld_ptr(G2_thread, in_bytes(JavaThread::pending_exception_offset()), Oexception); + __ ld_ptr(Oexception, 0, G0); + __ st_ptr(G0, G2_thread, in_bytes(JavaThread::pending_exception_offset())); + __ add(I7, frame::pc_return_offset, Oissuing_pc); + break; + case handle_exception_id: + // At this point all registers MAY be live. + oop_map = save_live_registers(sasm); + __ mov(Oexception->after_save(), Oexception); + __ mov(Oissuing_pc->after_save(), Oissuing_pc); + break; + case handle_exception_from_callee_id: + // At this point all registers except exception oop (Oexception) + // and exception pc (Oissuing_pc) are dead. + oop_map = new OopMap(frame_size_in_bytes / sizeof(jint), 0); + sasm->set_frame_size(frame_size_in_bytes / BytesPerWord); + __ save_frame_c1(frame_size_in_bytes); + __ mov(Oexception->after_save(), Oexception); + __ mov(Oissuing_pc->after_save(), Oissuing_pc); + break; + default: ShouldNotReachHere(); + } __ verify_not_null_oop(Oexception); // save the exception and issuing pc in the thread - __ st_ptr(Oexception, G2_thread, in_bytes(JavaThread::exception_oop_offset())); + __ st_ptr(Oexception, G2_thread, in_bytes(JavaThread::exception_oop_offset())); __ st_ptr(Oissuing_pc, G2_thread, in_bytes(JavaThread::exception_pc_offset())); - // save the real return address and use the throwing pc as the return address to lookup (has bci & oop map) - __ mov(I7, L0); + // use the throwing pc as the return address to lookup (has bci & oop map) __ mov(Oissuing_pc, I7); __ sub(I7, frame::pc_return_offset, I7); int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc)); + oop_maps->add_gc_map(call_offset, oop_map); // Note: if nmethod has been deoptimized then regardless of // whether it had a handler or not we will deoptimize // by entering the deopt blob with a pending exception. -#ifdef ASSERT - Label done; - __ tst(O0); - __ br(Assembler::notZero, false, Assembler::pn, done); - __ delayed()->nop(); - __ stop("should have found address"); - __ bind(done); -#endif + // Restore the registers that were saved at the beginning, remove + // the frame and jump to the exception handler. + switch (id) { + case forward_exception_id: + case handle_exception_id: + restore_live_registers(sasm); + __ jmp(O0, 0); + __ delayed()->restore(); + break; + case handle_exception_from_callee_id: + // Restore SP from L7 if the exception PC is a method handle call site. + __ mov(O0, G5); // Save the target address. + __ lduw(Address(G2_thread, JavaThread::is_method_handle_return_offset()), L0); + __ tst(L0); // Condition codes are preserved over the restore. + __ restore(); - // restore the registers that were saved at the beginning and jump to the exception handler. - restore_live_registers(sasm); + __ jmp(G5, 0); // jump to the exception handler + __ delayed()->movcc(Assembler::notZero, false, Assembler::icc, L7_mh_SP_save, SP); // Restore SP if required. + break; + default: ShouldNotReachHere(); + } - __ jmp(O0, 0); - __ delayed()->restore(); - - oop_maps->add_gc_map(call_offset, oop_map); + return oop_maps; } #undef __ -#define __ masm-> - const char *Runtime1::pd_name_for_address(address entry) { return "<unknown function>"; }
--- a/src/cpu/sparc/vm/cppInterpreter_sparc.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/sparc/vm/cppInterpreter_sparc.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1188,7 +1188,7 @@ __ st_ptr(O2, XXX_STATE(_stack)); // PREPUSH __ lduh(max_stack, O3); // Full size expression stack - guarantee(!EnableMethodHandles, "no support yet for java.dyn.MethodHandle"); //6815692 + guarantee(!EnableMethodHandles, "no support yet for java.lang.invoke.MethodHandle"); //6815692 //6815692//if (EnableMethodHandles) //6815692// __ inc(O3, methodOopDesc::extra_stack_entries()); __ sll(O3, LogBytesPerWord, O3);
--- a/src/cpu/sparc/vm/interpreter_sparc.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/sparc/vm/interpreter_sparc.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -260,7 +260,7 @@ // Method handle invoker -// Dispatch a method of the form java.dyn.MethodHandles::invoke(...) +// Dispatch a method of the form java.lang.invoke.MethodHandles::invoke(...) address InterpreterGenerator::generate_method_handle_entry(void) { if (!EnableMethodHandles) { return generate_abstract_entry();
--- a/src/cpu/sparc/vm/methodHandles_sparc.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/sparc/vm/methodHandles_sparc.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -112,8 +112,8 @@ } // given the MethodType, find out where the MH argument is buried - __ load_heap_oop(Address(O0_mtype, __ delayed_value(java_dyn_MethodType::form_offset_in_bytes, O1_scratch)), O4_argslot); - __ ldsw( Address(O4_argslot, __ delayed_value(java_dyn_MethodTypeForm::vmslots_offset_in_bytes, O1_scratch)), O4_argslot); + __ load_heap_oop(Address(O0_mtype, __ delayed_value(java_lang_invoke_MethodType::form_offset_in_bytes, O1_scratch)), O4_argslot); + __ ldsw( Address(O4_argslot, __ delayed_value(java_lang_invoke_MethodTypeForm::vmslots_offset_in_bytes, O1_scratch)), O4_argslot); __ add(Gargs, __ argument_offset(O4_argslot, 1), O4_argbase); // Note: argument_address uses its input as a scratch register! __ ld_ptr(Address(O4_argbase, -Interpreter::stackElementSize), G3_method_handle); @@ -141,10 +141,10 @@ // load up an adapter from the calling type (Java weaves this) Register O2_form = O2_scratch; Register O3_adapter = O3_scratch; - __ load_heap_oop(Address(O0_mtype, __ delayed_value(java_dyn_MethodType::form_offset_in_bytes, O1_scratch)), O2_form); - // load_heap_oop(Address(O2_form, __ delayed_value(java_dyn_MethodTypeForm::genericInvoker_offset_in_bytes, O1_scratch)), O3_adapter); + __ load_heap_oop(Address(O0_mtype, __ delayed_value(java_lang_invoke_MethodType::form_offset_in_bytes, O1_scratch)), O2_form); + // load_heap_oop(Address(O2_form, __ delayed_value(java_lang_invoke_MethodTypeForm::genericInvoker_offset_in_bytes, O1_scratch)), O3_adapter); // deal with old JDK versions: - __ add( Address(O2_form, __ delayed_value(java_dyn_MethodTypeForm::genericInvoker_offset_in_bytes, O1_scratch)), O3_adapter); + __ add( Address(O2_form, __ delayed_value(java_lang_invoke_MethodTypeForm::genericInvoker_offset_in_bytes, O1_scratch)), O3_adapter); __ cmp(O3_adapter, O2_form); Label sorry_no_invoke_generic; __ brx(Assembler::lessUnsigned, false, Assembler::pn, sorry_no_invoke_generic); @@ -376,16 +376,16 @@ // which conversion op types are implemented here? int MethodHandles::adapter_conversion_ops_supported_mask() { - return ((1<<sun_dyn_AdapterMethodHandle::OP_RETYPE_ONLY) - |(1<<sun_dyn_AdapterMethodHandle::OP_RETYPE_RAW) - |(1<<sun_dyn_AdapterMethodHandle::OP_CHECK_CAST) - |(1<<sun_dyn_AdapterMethodHandle::OP_PRIM_TO_PRIM) - |(1<<sun_dyn_AdapterMethodHandle::OP_REF_TO_PRIM) - |(1<<sun_dyn_AdapterMethodHandle::OP_SWAP_ARGS) - |(1<<sun_dyn_AdapterMethodHandle::OP_ROT_ARGS) - |(1<<sun_dyn_AdapterMethodHandle::OP_DUP_ARGS) - |(1<<sun_dyn_AdapterMethodHandle::OP_DROP_ARGS) - //|(1<<sun_dyn_AdapterMethodHandle::OP_SPREAD_ARGS) //BUG! + return ((1<<java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_PRIM) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_REF_TO_PRIM) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS) + //|(1<<java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS) //BUG! ); // FIXME: MethodHandlesTest gets a crash if we enable OP_SPREAD_ARGS. } @@ -413,21 +413,22 @@ const Register O1_actual = O1; const Register O2_required = O2; - guarantee(java_dyn_MethodHandle::vmentry_offset_in_bytes() != 0, "must have offsets"); + guarantee(java_lang_invoke_MethodHandle::vmentry_offset_in_bytes() != 0, "must have offsets"); // Some handy addresses: Address G5_method_fie( G5_method, in_bytes(methodOopDesc::from_interpreted_offset())); + Address G5_method_fce( G5_method, in_bytes(methodOopDesc::from_compiled_offset())); - Address G3_mh_vmtarget( G3_method_handle, java_dyn_MethodHandle::vmtarget_offset_in_bytes()); + Address G3_mh_vmtarget( G3_method_handle, java_lang_invoke_MethodHandle::vmtarget_offset_in_bytes()); - Address G3_dmh_vmindex( G3_method_handle, sun_dyn_DirectMethodHandle::vmindex_offset_in_bytes()); + Address G3_dmh_vmindex( G3_method_handle, java_lang_invoke_DirectMethodHandle::vmindex_offset_in_bytes()); - Address G3_bmh_vmargslot( G3_method_handle, sun_dyn_BoundMethodHandle::vmargslot_offset_in_bytes()); - Address G3_bmh_argument( G3_method_handle, sun_dyn_BoundMethodHandle::argument_offset_in_bytes()); + Address G3_bmh_vmargslot( G3_method_handle, java_lang_invoke_BoundMethodHandle::vmargslot_offset_in_bytes()); + Address G3_bmh_argument( G3_method_handle, java_lang_invoke_BoundMethodHandle::argument_offset_in_bytes()); - Address G3_amh_vmargslot( G3_method_handle, sun_dyn_AdapterMethodHandle::vmargslot_offset_in_bytes()); - Address G3_amh_argument ( G3_method_handle, sun_dyn_AdapterMethodHandle::argument_offset_in_bytes()); - Address G3_amh_conversion(G3_method_handle, sun_dyn_AdapterMethodHandle::conversion_offset_in_bytes()); + Address G3_amh_vmargslot( G3_method_handle, java_lang_invoke_AdapterMethodHandle::vmargslot_offset_in_bytes()); + Address G3_amh_argument ( G3_method_handle, java_lang_invoke_AdapterMethodHandle::argument_offset_in_bytes()); + Address G3_amh_conversion(G3_method_handle, java_lang_invoke_AdapterMethodHandle::conversion_offset_in_bytes()); const int java_mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes(); @@ -444,17 +445,15 @@ case _raise_exception: { // Not a real MH entry, but rather shared code for raising an - // exception. Since we use a C2I adapter to set up the - // interpreter state, arguments are expected in compiler - // argument registers. + // exception. Since we use the compiled entry, arguments are + // expected in compiler argument registers. assert(raise_exception_method(), "must be set"); - address c2i_entry = raise_exception_method()->get_c2i_entry(); - assert(c2i_entry, "method must be linked"); + assert(raise_exception_method()->from_compiled_entry(), "method must be linked"); __ mov(O5_savedSP, SP); // Cut the stack back to where the caller started. Label L_no_method; - // FIXME: fill in _raise_exception_method with a suitable sun.dyn method + // FIXME: fill in _raise_exception_method with a suitable java.lang.invoke method __ set(AddressLiteral((address) &_raise_exception_method), G5_method); __ ld_ptr(Address(G5_method, 0), G5_method); __ tst(G5_method); @@ -468,10 +467,9 @@ __ delayed()->nop(); __ verify_oop(G5_method); - __ jump_to(AddressLiteral(c2i_entry), O3_scratch); + __ jump_indirect_to(G5_method_fce, O3_scratch); // jump to compiled entry __ delayed()->nop(); - // If we get here, the Java runtime did not do its job of creating the exception. // Do something that is at least causes a valid throw from the interpreter. __ bind(L_no_method); __ unimplemented("call throw_WrongMethodType_entry");
--- a/src/cpu/sparc/vm/stubGenerator_sparc.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/sparc/vm/stubGenerator_sparc.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -968,19 +968,6 @@ return start; } - static address disjoint_byte_copy_entry; - static address disjoint_short_copy_entry; - static address disjoint_int_copy_entry; - static address disjoint_long_copy_entry; - static address disjoint_oop_copy_entry; - - static address byte_copy_entry; - static address short_copy_entry; - static address int_copy_entry; - static address long_copy_entry; - static address oop_copy_entry; - - static address checkcast_copy_entry; // // Verify that a register contains clean 32-bits positive value @@ -1046,31 +1033,40 @@ // // The input registers are overwritten. // - void gen_write_ref_array_pre_barrier(Register addr, Register count) { + void gen_write_ref_array_pre_barrier(Register addr, Register count, bool dest_uninitialized) { BarrierSet* bs = Universe::heap()->barrier_set(); - if (bs->has_write_ref_pre_barrier()) { - assert(bs->has_write_ref_array_pre_opt(), - "Else unsupported barrier set."); - - __ save_frame(0); - // Save the necessary global regs... will be used after. - if (addr->is_global()) { - __ mov(addr, L0); - } - if (count->is_global()) { - __ mov(count, L1); - } - __ mov(addr->after_save(), O0); - // Get the count into O1 - __ call(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre)); - __ delayed()->mov(count->after_save(), O1); - if (addr->is_global()) { - __ mov(L0, addr); - } - if (count->is_global()) { - __ mov(L1, count); - } - __ restore(); + switch (bs->kind()) { + case BarrierSet::G1SATBCT: + case BarrierSet::G1SATBCTLogging: + // With G1, don't generate the call if we statically know that the target in uninitialized + if (!dest_uninitialized) { + __ save_frame(0); + // Save the necessary global regs... will be used after. + if (addr->is_global()) { + __ mov(addr, L0); + } + if (count->is_global()) { + __ mov(count, L1); + } + __ mov(addr->after_save(), O0); + // Get the count into O1 + __ call(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre)); + __ delayed()->mov(count->after_save(), O1); + if (addr->is_global()) { + __ mov(L0, addr); + } + if (count->is_global()) { + __ mov(L1, count); + } + __ restore(); + } + break; + case BarrierSet::CardTableModRef: + case BarrierSet::CardTableExtension: + case BarrierSet::ModRef: + break; + default: + ShouldNotReachHere(); } } // @@ -1084,7 +1080,7 @@ // The input registers are overwritten. // void gen_write_ref_array_post_barrier(Register addr, Register count, - Register tmp) { + Register tmp) { BarrierSet* bs = Universe::heap()->barrier_set(); switch (bs->kind()) { @@ -1283,7 +1279,7 @@ // to: O1 // count: O2 treated as signed // - address generate_disjoint_byte_copy(bool aligned, const char * name) { + address generate_disjoint_byte_copy(bool aligned, address *entry, const char *name) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1299,9 +1295,11 @@ assert_clean_int(count, O3); // Make sure 'count' is clean int. - if (!aligned) disjoint_byte_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - if (!aligned) BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } // for short arrays, just do single element copy __ cmp(count, 23); // 16 + 7 @@ -1391,15 +1389,13 @@ // to: O1 // count: O2 treated as signed // - address generate_conjoint_byte_copy(bool aligned, const char * name) { + address generate_conjoint_byte_copy(bool aligned, address nooverlap_target, + address *entry, const char *name) { // Do reverse copy. __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); - address nooverlap_target = aligned ? - StubRoutines::arrayof_jbyte_disjoint_arraycopy() : - disjoint_byte_copy_entry; Label L_skip_alignment, L_align, L_aligned_copy; Label L_copy_byte, L_copy_byte_loop, L_exit; @@ -1412,9 +1408,11 @@ assert_clean_int(count, O3); // Make sure 'count' is clean int. - if (!aligned) byte_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - if (!aligned) BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } array_overlap_test(nooverlap_target, 0); @@ -1504,7 +1502,7 @@ // to: O1 // count: O2 treated as signed // - address generate_disjoint_short_copy(bool aligned, const char * name) { + address generate_disjoint_short_copy(bool aligned, address *entry, const char * name) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1520,9 +1518,11 @@ assert_clean_int(count, O3); // Make sure 'count' is clean int. - if (!aligned) disjoint_short_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - if (!aligned) BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } // for short arrays, just do single element copy __ cmp(count, 11); // 8 + 3 (22 bytes) @@ -1842,15 +1842,13 @@ // to: O1 // count: O2 treated as signed // - address generate_conjoint_short_copy(bool aligned, const char * name) { + address generate_conjoint_short_copy(bool aligned, address nooverlap_target, + address *entry, const char *name) { // Do reverse copy. __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); - address nooverlap_target = aligned ? - StubRoutines::arrayof_jshort_disjoint_arraycopy() : - disjoint_short_copy_entry; Label L_skip_alignment, L_skip_alignment2, L_aligned_copy; Label L_copy_2_bytes, L_copy_2_bytes_loop, L_exit; @@ -1865,9 +1863,11 @@ assert_clean_int(count, O3); // Make sure 'count' is clean int. - if (!aligned) short_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - if (!aligned) BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } array_overlap_test(nooverlap_target, 1); @@ -2072,7 +2072,7 @@ // to: O1 // count: O2 treated as signed // - address generate_disjoint_int_copy(bool aligned, const char * name) { + address generate_disjoint_int_copy(bool aligned, address *entry, const char *name) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -2080,9 +2080,11 @@ const Register count = O2; assert_clean_int(count, O3); // Make sure 'count' is clean int. - if (!aligned) disjoint_int_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - if (!aligned) BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } generate_disjoint_int_copy_core(aligned); @@ -2204,20 +2206,19 @@ // to: O1 // count: O2 treated as signed // - address generate_conjoint_int_copy(bool aligned, const char * name) { + address generate_conjoint_int_copy(bool aligned, address nooverlap_target, + address *entry, const char *name) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); - address nooverlap_target = aligned ? - StubRoutines::arrayof_jint_disjoint_arraycopy() : - disjoint_int_copy_entry; - assert_clean_int(O2, O3); // Make sure 'count' is clean int. - if (!aligned) int_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - if (!aligned) BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } array_overlap_test(nooverlap_target, 2); @@ -2336,16 +2337,18 @@ // to: O1 // count: O2 treated as signed // - address generate_disjoint_long_copy(bool aligned, const char * name) { + address generate_disjoint_long_copy(bool aligned, address *entry, const char *name) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); assert_clean_int(O2, O3); // Make sure 'count' is clean int. - if (!aligned) disjoint_long_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - if (!aligned) BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } generate_disjoint_long_copy_core(aligned); @@ -2406,19 +2409,21 @@ // to: O1 // count: O2 treated as signed // - address generate_conjoint_long_copy(bool aligned, const char * name) { + address generate_conjoint_long_copy(bool aligned, address nooverlap_target, + address *entry, const char *name) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); - assert(!aligned, "usage"); - address nooverlap_target = disjoint_long_copy_entry; + assert(aligned, "Should always be aligned"); assert_clean_int(O2, O3); // Make sure 'count' is clean int. - if (!aligned) long_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - if (!aligned) BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } array_overlap_test(nooverlap_target, 3); @@ -2439,7 +2444,8 @@ // to: O1 // count: O2 treated as signed // - address generate_disjoint_oop_copy(bool aligned, const char * name) { + address generate_disjoint_oop_copy(bool aligned, address *entry, const char *name, + bool dest_uninitialized = false) { const Register from = O0; // source array address const Register to = O1; // destination array address @@ -2451,14 +2457,16 @@ assert_clean_int(count, O3); // Make sure 'count' is clean int. - if (!aligned) disjoint_oop_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here - if (!aligned) BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here + BLOCK_COMMENT("Entry:"); + } // save arguments for barrier generation __ mov(to, G1); __ mov(count, G5); - gen_write_ref_array_pre_barrier(G1, G5); + gen_write_ref_array_pre_barrier(G1, G5, dest_uninitialized); #ifdef _LP64 assert_clean_int(count, O3); // Make sure 'count' is clean int. if (UseCompressedOops) { @@ -2487,7 +2495,9 @@ // to: O1 // count: O2 treated as signed // - address generate_conjoint_oop_copy(bool aligned, const char * name) { + address generate_conjoint_oop_copy(bool aligned, address nooverlap_target, + address *entry, const char *name, + bool dest_uninitialized = false) { const Register from = O0; // source array address const Register to = O1; // destination array address @@ -2499,21 +2509,18 @@ assert_clean_int(count, O3); // Make sure 'count' is clean int. - if (!aligned) oop_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here - if (!aligned) BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here + BLOCK_COMMENT("Entry:"); + } + + array_overlap_test(nooverlap_target, LogBytesPerHeapOop); // save arguments for barrier generation __ mov(to, G1); __ mov(count, G5); - - gen_write_ref_array_pre_barrier(G1, G5); - - address nooverlap_target = aligned ? - StubRoutines::arrayof_oop_disjoint_arraycopy() : - disjoint_oop_copy_entry; - - array_overlap_test(nooverlap_target, LogBytesPerHeapOop); + gen_write_ref_array_pre_barrier(G1, G5, dest_uninitialized); #ifdef _LP64 if (UseCompressedOops) { @@ -2582,7 +2589,7 @@ // ckval: O4 (super_klass) // ret: O0 zero for success; (-1^K) where K is partial transfer count // - address generate_checkcast_copy(const char* name) { + address generate_checkcast_copy(const char *name, address *entry, bool dest_uninitialized = false) { const Register O0_from = O0; // source array address const Register O1_to = O1; // destination array address @@ -2600,8 +2607,6 @@ StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); - gen_write_ref_array_pre_barrier(O1, O2); - #ifdef ASSERT // We sometimes save a frame (see generate_type_check below). // If this will cause trouble, let's fail now instead of later. @@ -2625,9 +2630,12 @@ } #endif //ASSERT - checkcast_copy_entry = __ pc(); - // caller can pass a 64-bit byte count here (from generic stub) - BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from generic stub) + BLOCK_COMMENT("Entry:"); + } + gen_write_ref_array_pre_barrier(O1_to, O2_count, dest_uninitialized); Label load_element, store_element, do_card_marks, fail, done; __ addcc(O2_count, 0, G1_remain); // initialize loop index, and test it @@ -2700,7 +2708,11 @@ // Examines the alignment of the operands and dispatches // to a long, int, short, or byte copy loop. // - address generate_unsafe_copy(const char* name) { + address generate_unsafe_copy(const char* name, + address byte_copy_entry, + address short_copy_entry, + address int_copy_entry, + address long_copy_entry) { const Register O0_from = O0; // source array address const Register O1_to = O1; // destination array address @@ -2796,8 +2808,13 @@ // O0 == 0 - success // O0 == -1 - need to call System.arraycopy // - address generate_generic_copy(const char *name) { - + address generate_generic_copy(const char *name, + address entry_jbyte_arraycopy, + address entry_jshort_arraycopy, + address entry_jint_arraycopy, + address entry_oop_arraycopy, + address entry_jlong_arraycopy, + address entry_checkcast_arraycopy) { Label L_failed, L_objArray; // Input registers @@ -2970,15 +2987,15 @@ BLOCK_COMMENT("choose copy loop based on element size"); __ cmp(G3_elsize, 0); - __ br(Assembler::equal,true,Assembler::pt,StubRoutines::_jbyte_arraycopy); + __ br(Assembler::equal, true, Assembler::pt, entry_jbyte_arraycopy); __ delayed()->signx(length, count); // length __ cmp(G3_elsize, LogBytesPerShort); - __ br(Assembler::equal,true,Assembler::pt,StubRoutines::_jshort_arraycopy); + __ br(Assembler::equal, true, Assembler::pt, entry_jshort_arraycopy); __ delayed()->signx(length, count); // length __ cmp(G3_elsize, LogBytesPerInt); - __ br(Assembler::equal,true,Assembler::pt,StubRoutines::_jint_arraycopy); + __ br(Assembler::equal, true, Assembler::pt, entry_jint_arraycopy); __ delayed()->signx(length, count); // length #ifdef ASSERT { Label L; @@ -2989,7 +3006,7 @@ __ bind(L); } #endif - __ br(Assembler::always,false,Assembler::pt,StubRoutines::_jlong_arraycopy); + __ br(Assembler::always, false, Assembler::pt, entry_jlong_arraycopy); __ delayed()->signx(length, count); // length // objArrayKlass @@ -3013,7 +3030,7 @@ __ add(src, src_pos, from); // src_addr __ add(dst, dst_pos, to); // dst_addr __ BIND(L_plain_copy); - __ br(Assembler::always, false, Assembler::pt,StubRoutines::_oop_arraycopy); + __ br(Assembler::always, false, Assembler::pt, entry_oop_arraycopy); __ delayed()->signx(length, count); // length __ BIND(L_checkcast_copy); @@ -3057,7 +3074,7 @@ __ ld_ptr(G4_dst_klass, ek_offset, O4); // dest elem klass // lduw(O4, sco_offset, O3); // sco of elem klass - __ br(Assembler::always, false, Assembler::pt, checkcast_copy_entry); + __ br(Assembler::always, false, Assembler::pt, entry_checkcast_arraycopy); __ delayed()->lduw(O4, sco_offset, O3); } @@ -3068,39 +3085,124 @@ } void generate_arraycopy_stubs() { - - // Note: the disjoint stubs must be generated first, some of - // the conjoint stubs use them. - StubRoutines::_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(false, "jbyte_disjoint_arraycopy"); - StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, "jshort_disjoint_arraycopy"); - StubRoutines::_jint_disjoint_arraycopy = generate_disjoint_int_copy(false, "jint_disjoint_arraycopy"); - StubRoutines::_jlong_disjoint_arraycopy = generate_disjoint_long_copy(false, "jlong_disjoint_arraycopy"); - StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_oop_copy(false, "oop_disjoint_arraycopy"); - StubRoutines::_arrayof_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(true, "arrayof_jbyte_disjoint_arraycopy"); - StubRoutines::_arrayof_jshort_disjoint_arraycopy = generate_disjoint_short_copy(true, "arrayof_jshort_disjoint_arraycopy"); - StubRoutines::_arrayof_jint_disjoint_arraycopy = generate_disjoint_int_copy(true, "arrayof_jint_disjoint_arraycopy"); - StubRoutines::_arrayof_jlong_disjoint_arraycopy = generate_disjoint_long_copy(true, "arrayof_jlong_disjoint_arraycopy"); - StubRoutines::_arrayof_oop_disjoint_arraycopy = generate_disjoint_oop_copy(true, "arrayof_oop_disjoint_arraycopy"); - - StubRoutines::_jbyte_arraycopy = generate_conjoint_byte_copy(false, "jbyte_arraycopy"); - StubRoutines::_jshort_arraycopy = generate_conjoint_short_copy(false, "jshort_arraycopy"); - StubRoutines::_jint_arraycopy = generate_conjoint_int_copy(false, "jint_arraycopy"); - StubRoutines::_jlong_arraycopy = generate_conjoint_long_copy(false, "jlong_arraycopy"); - StubRoutines::_oop_arraycopy = generate_conjoint_oop_copy(false, "oop_arraycopy"); - StubRoutines::_arrayof_jbyte_arraycopy = generate_conjoint_byte_copy(true, "arrayof_jbyte_arraycopy"); - StubRoutines::_arrayof_jshort_arraycopy = generate_conjoint_short_copy(true, "arrayof_jshort_arraycopy"); + address entry; + address entry_jbyte_arraycopy; + address entry_jshort_arraycopy; + address entry_jint_arraycopy; + address entry_oop_arraycopy; + address entry_jlong_arraycopy; + address entry_checkcast_arraycopy; + + //*** jbyte + // Always need aligned and unaligned versions + StubRoutines::_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(false, &entry, + "jbyte_disjoint_arraycopy"); + StubRoutines::_jbyte_arraycopy = generate_conjoint_byte_copy(false, entry, + &entry_jbyte_arraycopy, + "jbyte_arraycopy"); + StubRoutines::_arrayof_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(true, &entry, + "arrayof_jbyte_disjoint_arraycopy"); + StubRoutines::_arrayof_jbyte_arraycopy = generate_conjoint_byte_copy(true, entry, NULL, + "arrayof_jbyte_arraycopy"); + + //*** jshort + // Always need aligned and unaligned versions + StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, &entry, + "jshort_disjoint_arraycopy"); + StubRoutines::_jshort_arraycopy = generate_conjoint_short_copy(false, entry, + &entry_jshort_arraycopy, + "jshort_arraycopy"); + StubRoutines::_arrayof_jshort_disjoint_arraycopy = generate_disjoint_short_copy(true, &entry, + "arrayof_jshort_disjoint_arraycopy"); + StubRoutines::_arrayof_jshort_arraycopy = generate_conjoint_short_copy(true, entry, NULL, + "arrayof_jshort_arraycopy"); + + //*** jint + // Aligned versions + StubRoutines::_arrayof_jint_disjoint_arraycopy = generate_disjoint_int_copy(true, &entry, + "arrayof_jint_disjoint_arraycopy"); + StubRoutines::_arrayof_jint_arraycopy = generate_conjoint_int_copy(true, entry, &entry_jint_arraycopy, + "arrayof_jint_arraycopy"); #ifdef _LP64 - // since sizeof(jint) < sizeof(HeapWord), there's a different flavor: - StubRoutines::_arrayof_jint_arraycopy = generate_conjoint_int_copy(true, "arrayof_jint_arraycopy"); - #else - StubRoutines::_arrayof_jint_arraycopy = StubRoutines::_jint_arraycopy; + // In 64 bit we need both aligned and unaligned versions of jint arraycopy. + // entry_jint_arraycopy always points to the unaligned version (notice that we overwrite it). + StubRoutines::_jint_disjoint_arraycopy = generate_disjoint_int_copy(false, &entry, + "jint_disjoint_arraycopy"); + StubRoutines::_jint_arraycopy = generate_conjoint_int_copy(false, entry, + &entry_jint_arraycopy, + "jint_arraycopy"); +#else + // In 32 bit jints are always HeapWordSize aligned, so always use the aligned version + // (in fact in 32bit we always have a pre-loop part even in the aligned version, + // because it uses 64-bit loads/stores, so the aligned flag is actually ignored). + StubRoutines::_jint_disjoint_arraycopy = StubRoutines::_arrayof_jint_disjoint_arraycopy; + StubRoutines::_jint_arraycopy = StubRoutines::_arrayof_jint_arraycopy; #endif - StubRoutines::_arrayof_jlong_arraycopy = StubRoutines::_jlong_arraycopy; - StubRoutines::_arrayof_oop_arraycopy = StubRoutines::_oop_arraycopy; - - StubRoutines::_checkcast_arraycopy = generate_checkcast_copy("checkcast_arraycopy"); - StubRoutines::_unsafe_arraycopy = generate_unsafe_copy("unsafe_arraycopy"); - StubRoutines::_generic_arraycopy = generate_generic_copy("generic_arraycopy"); + + + //*** jlong + // It is always aligned + StubRoutines::_arrayof_jlong_disjoint_arraycopy = generate_disjoint_long_copy(true, &entry, + "arrayof_jlong_disjoint_arraycopy"); + StubRoutines::_arrayof_jlong_arraycopy = generate_conjoint_long_copy(true, entry, &entry_jlong_arraycopy, + "arrayof_jlong_arraycopy"); + StubRoutines::_jlong_disjoint_arraycopy = StubRoutines::_arrayof_jlong_disjoint_arraycopy; + StubRoutines::_jlong_arraycopy = StubRoutines::_arrayof_jlong_arraycopy; + + + //*** oops + // Aligned versions + StubRoutines::_arrayof_oop_disjoint_arraycopy = generate_disjoint_oop_copy(true, &entry, + "arrayof_oop_disjoint_arraycopy"); + StubRoutines::_arrayof_oop_arraycopy = generate_conjoint_oop_copy(true, entry, &entry_oop_arraycopy, + "arrayof_oop_arraycopy"); + // Aligned versions without pre-barriers + StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = generate_disjoint_oop_copy(true, &entry, + "arrayof_oop_disjoint_arraycopy_uninit", + /*dest_uninitialized*/true); + StubRoutines::_arrayof_oop_arraycopy_uninit = generate_conjoint_oop_copy(true, entry, NULL, + "arrayof_oop_arraycopy_uninit", + /*dest_uninitialized*/true); +#ifdef _LP64 + if (UseCompressedOops) { + // With compressed oops we need unaligned versions, notice that we overwrite entry_oop_arraycopy. + StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_oop_copy(false, &entry, + "oop_disjoint_arraycopy"); + StubRoutines::_oop_arraycopy = generate_conjoint_oop_copy(false, entry, &entry_oop_arraycopy, + "oop_arraycopy"); + // Unaligned versions without pre-barriers + StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_oop_copy(false, &entry, + "oop_disjoint_arraycopy_uninit", + /*dest_uninitialized*/true); + StubRoutines::_oop_arraycopy_uninit = generate_conjoint_oop_copy(false, entry, NULL, + "oop_arraycopy_uninit", + /*dest_uninitialized*/true); + } else +#endif + { + // oop arraycopy is always aligned on 32bit and 64bit without compressed oops + StubRoutines::_oop_disjoint_arraycopy = StubRoutines::_arrayof_oop_disjoint_arraycopy; + StubRoutines::_oop_arraycopy = StubRoutines::_arrayof_oop_arraycopy; + StubRoutines::_oop_disjoint_arraycopy_uninit = StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit; + StubRoutines::_oop_arraycopy_uninit = StubRoutines::_arrayof_oop_arraycopy_uninit; + } + + StubRoutines::_checkcast_arraycopy = generate_checkcast_copy("checkcast_arraycopy", &entry_checkcast_arraycopy); + StubRoutines::_checkcast_arraycopy_uninit = generate_checkcast_copy("checkcast_arraycopy_uninit", NULL, + /*dest_uninitialized*/true); + + StubRoutines::_unsafe_arraycopy = generate_unsafe_copy("unsafe_arraycopy", + entry_jbyte_arraycopy, + entry_jshort_arraycopy, + entry_jint_arraycopy, + entry_jlong_arraycopy); + StubRoutines::_generic_arraycopy = generate_generic_copy("generic_arraycopy", + entry_jbyte_arraycopy, + entry_jshort_arraycopy, + entry_jint_arraycopy, + entry_oop_arraycopy, + entry_jlong_arraycopy, + entry_checkcast_arraycopy); StubRoutines::_jbyte_fill = generate_fill(T_BYTE, false, "jbyte_fill"); StubRoutines::_jshort_fill = generate_fill(T_SHORT, false, "jshort_fill"); @@ -3224,21 +3326,6 @@ }; // end class declaration - -address StubGenerator::disjoint_byte_copy_entry = NULL; -address StubGenerator::disjoint_short_copy_entry = NULL; -address StubGenerator::disjoint_int_copy_entry = NULL; -address StubGenerator::disjoint_long_copy_entry = NULL; -address StubGenerator::disjoint_oop_copy_entry = NULL; - -address StubGenerator::byte_copy_entry = NULL; -address StubGenerator::short_copy_entry = NULL; -address StubGenerator::int_copy_entry = NULL; -address StubGenerator::long_copy_entry = NULL; -address StubGenerator::oop_copy_entry = NULL; - -address StubGenerator::checkcast_copy_entry = NULL; - void StubGenerator_generate(CodeBuffer* code, bool all) { StubGenerator g(code, all); }
--- a/src/cpu/sparc/vm/templateTable_sparc.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/sparc/vm/templateTable_sparc.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -3303,7 +3303,7 @@ __ sll(Rret, LogBytesPerWord, Rret); __ ld_ptr(Rtemp, Rret, Rret); // get return address - __ load_heap_oop(G5_callsite, __ delayed_value(java_dyn_CallSite::target_offset_in_bytes, Rscratch), G3_method_handle); + __ load_heap_oop(G5_callsite, __ delayed_value(java_lang_invoke_CallSite::target_offset_in_bytes, Rscratch), G3_method_handle); __ null_check(G3_method_handle); // Adjust Rret first so Llast_SP can be same as Rret
--- a/src/cpu/x86/vm/assembler_x86.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/assembler_x86.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1601,6 +1601,17 @@ emit_byte(0xC0 | encode); } +void Assembler::movdl(XMMRegister dst, Address src) { + NOT_LP64(assert(VM_Version::supports_sse2(), "")); + InstructionMark im(this); + emit_byte(0x66); + prefix(src, dst); + emit_byte(0x0F); + emit_byte(0x6E); + emit_operand(dst, src); +} + + void Assembler::movdqa(XMMRegister dst, Address src) { NOT_LP64(assert(VM_Version::supports_sse2(), "")); InstructionMark im(this); @@ -2412,7 +2423,10 @@ } void Assembler::psrlq(XMMRegister dst, int shift) { - // HMM Table D-1 says sse2 or mmx + // Shift 64 bit value logically right by specified number of bits. + // HMM Table D-1 says sse2 or mmx. + // Do not confuse it with psrldq SSE2 instruction which + // shifts 128 bit value in xmm register by number of bytes. NOT_LP64(assert(VM_Version::supports_sse(), "")); int encode = prefixq_and_encode(xmm2->encoding(), dst->encoding()); @@ -2423,6 +2437,18 @@ emit_byte(shift); } +void Assembler::psrldq(XMMRegister dst, int shift) { + // Shift 128 bit value in xmm register by number of bytes. + NOT_LP64(assert(VM_Version::supports_sse2(), "")); + + int encode = prefixq_and_encode(xmm3->encoding(), dst->encoding()); + emit_byte(0x66); + emit_byte(0x0F); + emit_byte(0x73); + emit_byte(0xC0 | encode); + emit_byte(shift); +} + void Assembler::ptest(XMMRegister dst, Address src) { assert(VM_Version::supports_sse4_1(), ""); @@ -7805,7 +7831,7 @@ void MacroAssembler::check_method_handle_type(Register mtype_reg, Register mh_reg, Register temp_reg, Label& wrong_method_type) { - Address type_addr(mh_reg, delayed_value(java_dyn_MethodHandle::type_offset_in_bytes, temp_reg)); + Address type_addr(mh_reg, delayed_value(java_lang_invoke_MethodHandle::type_offset_in_bytes, temp_reg)); // compare method type against that of the receiver if (UseCompressedOops) { load_heap_oop(temp_reg, type_addr); @@ -7825,14 +7851,14 @@ Register temp_reg) { assert_different_registers(vmslots_reg, mh_reg, temp_reg); // load mh.type.form.vmslots - if (java_dyn_MethodHandle::vmslots_offset_in_bytes() != 0) { + if (java_lang_invoke_MethodHandle::vmslots_offset_in_bytes() != 0) { // hoist vmslots into every mh to avoid dependent load chain - movl(vmslots_reg, Address(mh_reg, delayed_value(java_dyn_MethodHandle::vmslots_offset_in_bytes, temp_reg))); + movl(vmslots_reg, Address(mh_reg, delayed_value(java_lang_invoke_MethodHandle::vmslots_offset_in_bytes, temp_reg))); } else { Register temp2_reg = vmslots_reg; - load_heap_oop(temp2_reg, Address(mh_reg, delayed_value(java_dyn_MethodHandle::type_offset_in_bytes, temp_reg))); - load_heap_oop(temp2_reg, Address(temp2_reg, delayed_value(java_dyn_MethodType::form_offset_in_bytes, temp_reg))); - movl(vmslots_reg, Address(temp2_reg, delayed_value(java_dyn_MethodTypeForm::vmslots_offset_in_bytes, temp_reg))); + load_heap_oop(temp2_reg, Address(mh_reg, delayed_value(java_lang_invoke_MethodHandle::type_offset_in_bytes, temp_reg))); + load_heap_oop(temp2_reg, Address(temp2_reg, delayed_value(java_lang_invoke_MethodType::form_offset_in_bytes, temp_reg))); + movl(vmslots_reg, Address(temp2_reg, delayed_value(java_lang_invoke_MethodTypeForm::vmslots_offset_in_bytes, temp_reg))); } } @@ -7847,7 +7873,7 @@ // pick out the interpreted side of the handler // NOTE: vmentry is not an oop! - movptr(temp_reg, Address(mh_reg, delayed_value(java_dyn_MethodHandle::vmentry_offset_in_bytes, temp_reg))); + movptr(temp_reg, Address(mh_reg, delayed_value(java_lang_invoke_MethodHandle::vmentry_offset_in_bytes, temp_reg))); // off we go... jmp(Address(temp_reg, MethodHandleEntry::from_interpreted_entry_offset_in_bytes())); @@ -8567,101 +8593,418 @@ } #endif // _LP64 -// IndexOf substring. -void MacroAssembler::string_indexof(Register str1, Register str2, - Register cnt1, Register cnt2, Register result, - XMMRegister vec, Register tmp) { +// IndexOf for constant substrings with size >= 8 chars +// which don't need to be loaded through stack. +void MacroAssembler::string_indexofC8(Register str1, Register str2, + Register cnt1, Register cnt2, + int int_cnt2, Register result, + XMMRegister vec, Register tmp) { assert(UseSSE42Intrinsics, "SSE4.2 is required"); - Label RELOAD_SUBSTR, PREP_FOR_SCAN, SCAN_TO_SUBSTR, - SCAN_SUBSTR, RET_NOT_FOUND, CLEANUP; - - push(str1); // string addr - push(str2); // substr addr - push(cnt2); // substr count - jmpb(PREP_FOR_SCAN); - - // Substr count saved at sp - // Substr saved at sp+1*wordSize - // String saved at sp+2*wordSize - - // Reload substr for rescan - bind(RELOAD_SUBSTR); - movl(cnt2, Address(rsp, 0)); - movptr(str2, Address(rsp, wordSize)); - // We came here after the beginninig of the substring was - // matched but the rest of it was not so we need to search - // again. Start from the next element after the previous match. - subptr(str1, result); // Restore counter - shrl(str1, 1); - addl(cnt1, str1); - decrementl(cnt1); - lea(str1, Address(result, 2)); // Reload string - - // Load substr - bind(PREP_FOR_SCAN); - movdqu(vec, Address(str2, 0)); - addl(cnt1, 8); // prime the loop - subptr(str1, 16); - - // Scan string for substr in 16-byte vectors - bind(SCAN_TO_SUBSTR); - subl(cnt1, 8); - addptr(str1, 16); - - // pcmpestri + // This method uses pcmpestri inxtruction with bound registers // inputs: // xmm - substring // rax - substring length (elements count) - // mem - scaned string + // mem - scanned string + // rdx - string length (elements count) + // 0xd - mode: 1100 (substring search) + 01 (unsigned shorts) + // outputs: + // rcx - matched index in string + assert(cnt1 == rdx && cnt2 == rax && tmp == rcx, "pcmpestri"); + + Label RELOAD_SUBSTR, SCAN_TO_SUBSTR, SCAN_SUBSTR, + RET_FOUND, RET_NOT_FOUND, EXIT, FOUND_SUBSTR, + MATCH_SUBSTR_HEAD, RELOAD_STR, FOUND_CANDIDATE; + + // Note, inline_string_indexOf() generates checks: + // if (substr.count > string.count) return -1; + // if (substr.count == 0) return 0; + assert(int_cnt2 >= 8, "this code isused only for cnt2 >= 8 chars"); + + // Load substring. + movdqu(vec, Address(str2, 0)); + movl(cnt2, int_cnt2); + movptr(result, str1); // string addr + + if (int_cnt2 > 8) { + jmpb(SCAN_TO_SUBSTR); + + // Reload substr for rescan, this code + // is executed only for large substrings (> 8 chars) + bind(RELOAD_SUBSTR); + movdqu(vec, Address(str2, 0)); + negptr(cnt2); // Jumped here with negative cnt2, convert to positive + + bind(RELOAD_STR); + // We came here after the beginning of the substring was + // matched but the rest of it was not so we need to search + // again. Start from the next element after the previous match. + + // cnt2 is number of substring reminding elements and + // cnt1 is number of string reminding elements when cmp failed. + // Restored cnt1 = cnt1 - cnt2 + int_cnt2 + subl(cnt1, cnt2); + addl(cnt1, int_cnt2); + movl(cnt2, int_cnt2); // Now restore cnt2 + + decrementl(cnt1); // Shift to next element + cmpl(cnt1, cnt2); + jccb(Assembler::negative, RET_NOT_FOUND); // Left less then substring + + addptr(result, 2); + + } // (int_cnt2 > 8) + + // Scan string for start of substr in 16-byte vectors + bind(SCAN_TO_SUBSTR); + pcmpestri(vec, Address(result, 0), 0x0d); + jccb(Assembler::below, FOUND_CANDIDATE); // CF == 1 + subl(cnt1, 8); + jccb(Assembler::lessEqual, RET_NOT_FOUND); // Scanned full string + cmpl(cnt1, cnt2); + jccb(Assembler::negative, RET_NOT_FOUND); // Left less then substring + addptr(result, 16); + jmpb(SCAN_TO_SUBSTR); + + // Found a potential substr + bind(FOUND_CANDIDATE); + // Matched whole vector if first element matched (tmp(rcx) == 0). + if (int_cnt2 == 8) { + jccb(Assembler::overflow, RET_FOUND); // OF == 1 + } else { // int_cnt2 > 8 + jccb(Assembler::overflow, FOUND_SUBSTR); + } + // After pcmpestri tmp(rcx) contains matched element index + // Compute start addr of substr + lea(result, Address(result, tmp, Address::times_2)); + + // Make sure string is still long enough + subl(cnt1, tmp); + cmpl(cnt1, cnt2); + if (int_cnt2 == 8) { + jccb(Assembler::greaterEqual, SCAN_TO_SUBSTR); + } else { // int_cnt2 > 8 + jccb(Assembler::greaterEqual, MATCH_SUBSTR_HEAD); + } + // Left less then substring. + + bind(RET_NOT_FOUND); + movl(result, -1); + jmpb(EXIT); + + if (int_cnt2 > 8) { + // This code is optimized for the case when whole substring + // is matched if its head is matched. + bind(MATCH_SUBSTR_HEAD); + pcmpestri(vec, Address(result, 0), 0x0d); + // Reload only string if does not match + jccb(Assembler::noOverflow, RELOAD_STR); // OF == 0 + + Label CONT_SCAN_SUBSTR; + // Compare the rest of substring (> 8 chars). + bind(FOUND_SUBSTR); + // First 8 chars are already matched. + negptr(cnt2); + addptr(cnt2, 8); + + bind(SCAN_SUBSTR); + subl(cnt1, 8); + cmpl(cnt2, -8); // Do not read beyond substring + jccb(Assembler::lessEqual, CONT_SCAN_SUBSTR); + // Back-up strings to avoid reading beyond substring: + // cnt1 = cnt1 - cnt2 + 8 + addl(cnt1, cnt2); // cnt2 is negative + addl(cnt1, 8); + movl(cnt2, 8); negptr(cnt2); + bind(CONT_SCAN_SUBSTR); + if (int_cnt2 < (int)G) { + movdqu(vec, Address(str2, cnt2, Address::times_2, int_cnt2*2)); + pcmpestri(vec, Address(result, cnt2, Address::times_2, int_cnt2*2), 0x0d); + } else { + // calculate index in register to avoid integer overflow (int_cnt2*2) + movl(tmp, int_cnt2); + addptr(tmp, cnt2); + movdqu(vec, Address(str2, tmp, Address::times_2, 0)); + pcmpestri(vec, Address(result, tmp, Address::times_2, 0), 0x0d); + } + // Need to reload strings pointers if not matched whole vector + jccb(Assembler::noOverflow, RELOAD_SUBSTR); // OF == 0 + addptr(cnt2, 8); + jccb(Assembler::negative, SCAN_SUBSTR); + // Fall through if found full substring + + } // (int_cnt2 > 8) + + bind(RET_FOUND); + // Found result if we matched full small substring. + // Compute substr offset + subptr(result, str1); + shrl(result, 1); // index + bind(EXIT); + +} // string_indexofC8 + +// Small strings are loaded through stack if they cross page boundary. +void MacroAssembler::string_indexof(Register str1, Register str2, + Register cnt1, Register cnt2, + int int_cnt2, Register result, + XMMRegister vec, Register tmp) { + assert(UseSSE42Intrinsics, "SSE4.2 is required"); + // + // int_cnt2 is length of small (< 8 chars) constant substring + // or (-1) for non constant substring in which case its length + // is in cnt2 register. + // + // Note, inline_string_indexOf() generates checks: + // if (substr.count > string.count) return -1; + // if (substr.count == 0) return 0; + // + assert(int_cnt2 == -1 || (0 < int_cnt2 && int_cnt2 < 8), "should be != 0"); + + // This method uses pcmpestri inxtruction with bound registers + // inputs: + // xmm - substring + // rax - substring length (elements count) + // mem - scanned string // rdx - string length (elements count) // 0xd - mode: 1100 (substring search) + 01 (unsigned shorts) // outputs: // rcx - matched index in string assert(cnt1 == rdx && cnt2 == rax && tmp == rcx, "pcmpestri"); - pcmpestri(vec, Address(str1, 0), 0x0d); - jcc(Assembler::above, SCAN_TO_SUBSTR); // CF == 0 && ZF == 0 - jccb(Assembler::aboveEqual, RET_NOT_FOUND); // CF == 0 - - // Fallthrough: found a potential substr + Label RELOAD_SUBSTR, SCAN_TO_SUBSTR, SCAN_SUBSTR, ADJUST_STR, + RET_FOUND, RET_NOT_FOUND, CLEANUP, FOUND_SUBSTR, + FOUND_CANDIDATE; + + { //======================================================== + // We don't know where these strings are located + // and we can't read beyond them. Load them through stack. + Label BIG_STRINGS, CHECK_STR, COPY_SUBSTR, COPY_STR; + + movptr(tmp, rsp); // save old SP + + if (int_cnt2 > 0) { // small (< 8 chars) constant substring + if (int_cnt2 == 1) { // One char + load_unsigned_short(result, Address(str2, 0)); + movdl(vec, result); // move 32 bits + } else if (int_cnt2 == 2) { // Two chars + movdl(vec, Address(str2, 0)); // move 32 bits + } else if (int_cnt2 == 4) { // Four chars + movq(vec, Address(str2, 0)); // move 64 bits + } else { // cnt2 = { 3, 5, 6, 7 } + // Array header size is 12 bytes in 32-bit VM + // + 6 bytes for 3 chars == 18 bytes, + // enough space to load vec and shift. + assert(HeapWordSize*typeArrayKlass::header_size() >= 12,"sanity"); + movdqu(vec, Address(str2, (int_cnt2*2)-16)); + psrldq(vec, 16-(int_cnt2*2)); + } + } else { // not constant substring + cmpl(cnt2, 8); + jccb(Assembler::aboveEqual, BIG_STRINGS); // Both strings are big enough + + // We can read beyond string if srt+16 does not cross page boundary + // since heaps are aligned and mapped by pages. + assert(os::vm_page_size() < (int)G, "default page should be small"); + movl(result, str2); // We need only low 32 bits + andl(result, (os::vm_page_size()-1)); + cmpl(result, (os::vm_page_size()-16)); + jccb(Assembler::belowEqual, CHECK_STR); + + // Move small strings to stack to allow load 16 bytes into vec. + subptr(rsp, 16); + int stk_offset = wordSize-2; + push(cnt2); + + bind(COPY_SUBSTR); + load_unsigned_short(result, Address(str2, cnt2, Address::times_2, -2)); + movw(Address(rsp, cnt2, Address::times_2, stk_offset), result); + decrement(cnt2); + jccb(Assembler::notZero, COPY_SUBSTR); + + pop(cnt2); + movptr(str2, rsp); // New substring address + } // non constant + + bind(CHECK_STR); + cmpl(cnt1, 8); + jccb(Assembler::aboveEqual, BIG_STRINGS); + + // Check cross page boundary. + movl(result, str1); // We need only low 32 bits + andl(result, (os::vm_page_size()-1)); + cmpl(result, (os::vm_page_size()-16)); + jccb(Assembler::belowEqual, BIG_STRINGS); + + subptr(rsp, 16); + int stk_offset = -2; + if (int_cnt2 < 0) { // not constant + push(cnt2); + stk_offset += wordSize; + } + movl(cnt2, cnt1); + + bind(COPY_STR); + load_unsigned_short(result, Address(str1, cnt2, Address::times_2, -2)); + movw(Address(rsp, cnt2, Address::times_2, stk_offset), result); + decrement(cnt2); + jccb(Assembler::notZero, COPY_STR); + + if (int_cnt2 < 0) { // not constant + pop(cnt2); + } + movptr(str1, rsp); // New string address + + bind(BIG_STRINGS); + // Load substring. + if (int_cnt2 < 0) { // -1 + movdqu(vec, Address(str2, 0)); + push(cnt2); // substr count + push(str2); // substr addr + push(str1); // string addr + } else { + // Small (< 8 chars) constant substrings are loaded already. + movl(cnt2, int_cnt2); + } + push(tmp); // original SP + + } // Finished loading + + //======================================================== + // Start search + // + + movptr(result, str1); // string addr + + if (int_cnt2 < 0) { // Only for non constant substring + jmpb(SCAN_TO_SUBSTR); + + // SP saved at sp+0 + // String saved at sp+1*wordSize + // Substr saved at sp+2*wordSize + // Substr count saved at sp+3*wordSize + + // Reload substr for rescan, this code + // is executed only for large substrings (> 8 chars) + bind(RELOAD_SUBSTR); + movptr(str2, Address(rsp, 2*wordSize)); + movl(cnt2, Address(rsp, 3*wordSize)); + movdqu(vec, Address(str2, 0)); + // We came here after the beginning of the substring was + // matched but the rest of it was not so we need to search + // again. Start from the next element after the previous match. + subptr(str1, result); // Restore counter + shrl(str1, 1); + addl(cnt1, str1); + decrementl(cnt1); // Shift to next element + cmpl(cnt1, cnt2); + jccb(Assembler::negative, RET_NOT_FOUND); // Left less then substring + + addptr(result, 2); + } // non constant + + // Scan string for start of substr in 16-byte vectors + bind(SCAN_TO_SUBSTR); + assert(cnt1 == rdx && cnt2 == rax && tmp == rcx, "pcmpestri"); + pcmpestri(vec, Address(result, 0), 0x0d); + jccb(Assembler::below, FOUND_CANDIDATE); // CF == 1 + subl(cnt1, 8); + jccb(Assembler::lessEqual, RET_NOT_FOUND); // Scanned full string + cmpl(cnt1, cnt2); + jccb(Assembler::negative, RET_NOT_FOUND); // Left less then substring + addptr(result, 16); + + bind(ADJUST_STR); + cmpl(cnt1, 8); // Do not read beyond string + jccb(Assembler::greaterEqual, SCAN_TO_SUBSTR); + // Back-up string to avoid reading beyond string. + lea(result, Address(result, cnt1, Address::times_2, -16)); + movl(cnt1, 8); + jmpb(SCAN_TO_SUBSTR); + + // Found a potential substr + bind(FOUND_CANDIDATE); + // After pcmpestri tmp(rcx) contains matched element index // Make sure string is still long enough subl(cnt1, tmp); cmpl(cnt1, cnt2); - jccb(Assembler::negative, RET_NOT_FOUND); - // Compute start addr of substr - lea(str1, Address(str1, tmp, Address::times_2)); - movptr(result, str1); // save - - // Compare potential substr - addl(cnt1, 8); // prime the loop - addl(cnt2, 8); - subptr(str1, 16); - subptr(str2, 16); - - // Scan 16-byte vectors of string and substr - bind(SCAN_SUBSTR); - subl(cnt1, 8); - subl(cnt2, 8); - addptr(str1, 16); - addptr(str2, 16); - movdqu(vec, Address(str2, 0)); - pcmpestri(vec, Address(str1, 0), 0x0d); - jcc(Assembler::noOverflow, RELOAD_SUBSTR); // OF == 0 - jcc(Assembler::positive, SCAN_SUBSTR); // SF == 0 - - // Compute substr offset - subptr(result, Address(rsp, 2*wordSize)); - shrl(result, 1); // index - jmpb(CLEANUP); + jccb(Assembler::greaterEqual, FOUND_SUBSTR); + // Left less then substring. bind(RET_NOT_FOUND); movl(result, -1); + jmpb(CLEANUP); + + bind(FOUND_SUBSTR); + // Compute start addr of substr + lea(result, Address(result, tmp, Address::times_2)); + + if (int_cnt2 > 0) { // Constant substring + // Repeat search for small substring (< 8 chars) + // from new point without reloading substring. + // Have to check that we don't read beyond string. + cmpl(tmp, 8-int_cnt2); + jccb(Assembler::greater, ADJUST_STR); + // Fall through if matched whole substring. + } else { // non constant + assert(int_cnt2 == -1, "should be != 0"); + + addl(tmp, cnt2); + // Found result if we matched whole substring. + cmpl(tmp, 8); + jccb(Assembler::lessEqual, RET_FOUND); + + // Repeat search for small substring (<= 8 chars) + // from new point 'str1' without reloading substring. + cmpl(cnt2, 8); + // Have to check that we don't read beyond string. + jccb(Assembler::lessEqual, ADJUST_STR); + + Label CHECK_NEXT, CONT_SCAN_SUBSTR, RET_FOUND_LONG; + // Compare the rest of substring (> 8 chars). + movptr(str1, result); + + cmpl(tmp, cnt2); + // First 8 chars are already matched. + jccb(Assembler::equal, CHECK_NEXT); + + bind(SCAN_SUBSTR); + pcmpestri(vec, Address(str1, 0), 0x0d); + // Need to reload strings pointers if not matched whole vector + jcc(Assembler::noOverflow, RELOAD_SUBSTR); // OF == 0 + + bind(CHECK_NEXT); + subl(cnt2, 8); + jccb(Assembler::lessEqual, RET_FOUND_LONG); // Found full substring + addptr(str1, 16); + addptr(str2, 16); + subl(cnt1, 8); + cmpl(cnt2, 8); // Do not read beyond substring + jccb(Assembler::greaterEqual, CONT_SCAN_SUBSTR); + // Back-up strings to avoid reading beyond substring. + lea(str2, Address(str2, cnt2, Address::times_2, -16)); + lea(str1, Address(str1, cnt2, Address::times_2, -16)); + subl(cnt1, cnt2); + movl(cnt2, 8); + addl(cnt1, 8); + bind(CONT_SCAN_SUBSTR); + movdqu(vec, Address(str2, 0)); + jmpb(SCAN_SUBSTR); + + bind(RET_FOUND_LONG); + movptr(str1, Address(rsp, wordSize)); + } // non constant + + bind(RET_FOUND); + // Compute substr offset + subptr(result, str1); + shrl(result, 1); // index bind(CLEANUP); - addptr(rsp, 3*wordSize); -} + pop(rsp); // restore SP + +} // string_indexof // Compare strings. void MacroAssembler::string_compare(Register str1, Register str2,
--- a/src/cpu/x86/vm/assembler_x86.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/assembler_x86.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1121,6 +1121,7 @@ void movdl(XMMRegister dst, Register src); void movdl(Register dst, XMMRegister src); + void movdl(XMMRegister dst, Address src); // Move Double Quadword void movdq(XMMRegister dst, Register src); @@ -1288,9 +1289,12 @@ void pshuflw(XMMRegister dst, XMMRegister src, int mode); void pshuflw(XMMRegister dst, Address src, int mode); - // Shift Right Logical Quadword Immediate + // Shift Right by bits Logical Quadword Immediate void psrlq(XMMRegister dst, int shift); + // Shift Right by bytes Logical DoubleQuadword Immediate + void psrldq(XMMRegister dst, int shift); + // Logical Compare Double Quadword void ptest(XMMRegister dst, XMMRegister src); void ptest(XMMRegister dst, Address src); @@ -2290,10 +2294,22 @@ void movl2ptr(Register dst, Register src) { LP64_ONLY(movslq(dst, src)) NOT_LP64(if (dst != src) movl(dst, src)); } // IndexOf strings. + // Small strings are loaded through stack if they cross page boundary. void string_indexof(Register str1, Register str2, - Register cnt1, Register cnt2, Register result, + Register cnt1, Register cnt2, + int int_cnt2, Register result, XMMRegister vec, Register tmp); + // IndexOf for constant substrings with size >= 8 elements + // which don't need to be loaded through stack. + void string_indexofC8(Register str1, Register str2, + Register cnt1, Register cnt2, + int int_cnt2, Register result, + XMMRegister vec, Register tmp); + + // Smallest code: we don't need to load through stack, + // check string tail. + // Compare strings. void string_compare(Register str1, Register str2, Register cnt1, Register cnt2, Register result,
--- a/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -456,10 +456,8 @@ __ verify_not_null_oop(rax); // search an exception handler (rax: exception oop, rdx: throwing pc) - __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::handle_exception_nofpu_id))); - - __ stop("should not reach here"); - + __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::handle_exception_from_callee_id))); + __ should_not_reach_here(); assert(code_offset() - offset <= exception_handler_size, "overflow"); __ end_a_stub();
--- a/src/cpu/x86/vm/c1_Runtime1_x86.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/c1_Runtime1_x86.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -248,11 +248,14 @@ #ifdef _LP64 align_dummy_0, align_dummy_1, #endif // _LP64 - dummy1, SLOT2(dummy1H) // 0, 4 - dummy2, SLOT2(dummy2H) // 8, 12 - // Two temps to be used as needed by users of save/restore callee registers - temp_2_off, SLOT2(temp_2H_off) // 16, 20 - temp_1_off, SLOT2(temp_1H_off) // 24, 28 +#ifdef _WIN64 + // Windows always allocates space for it's argument registers (see + // frame::arg_reg_save_area_bytes). + arg_reg_save_1, arg_reg_save_1H, // 0, 4 + arg_reg_save_2, arg_reg_save_2H, // 8, 12 + arg_reg_save_3, arg_reg_save_3H, // 16, 20 + arg_reg_save_4, arg_reg_save_4H, // 24, 28 +#endif // _WIN64 xmm_regs_as_doubles_off, // 32 float_regs_as_doubles_off = xmm_regs_as_doubles_off + xmm_regs_as_doubles_size_in_slots, // 160 fpu_state_off = float_regs_as_doubles_off + float_regs_as_doubles_size_in_slots, // 224 @@ -282,24 +285,7 @@ rax_off, SLOT2(raxH_off) // 480, 484 saved_rbp_off, SLOT2(saved_rbpH_off) // 488, 492 return_off, SLOT2(returnH_off) // 496, 500 - reg_save_frame_size, // As noted: neglects any parameters to runtime // 504 - -#ifdef _WIN64 - c_rarg0_off = rcx_off, -#else - c_rarg0_off = rdi_off, -#endif // WIN64 - - // equates - - // illegal instruction handler - continue_dest_off = temp_1_off, - - // deoptimization equates - fp0_off = float_regs_as_doubles_off, // slot for java float/double return value - xmm0_off = xmm_regs_as_doubles_off, // slot for java float/double return value - deopt_type = temp_2_off, // slot for type of deopt in progress - ret_type = temp_1_off // slot for return type + reg_save_frame_size // As noted: neglects any parameters to runtime // 504 }; @@ -405,11 +391,6 @@ bool save_fpu_registers = true) { __ block_comment("save_live_registers"); - // 64bit passes the args in regs to the c++ runtime - int frame_size_in_slots = reg_save_frame_size NOT_LP64(+ num_rt_args); // args + thread - // frame_size = round_to(frame_size, 4); - sasm->set_frame_size(frame_size_in_slots / VMRegImpl::slots_per_word ); - __ pusha(); // integer registers // assert(float_regs_as_doubles_off % 2 == 0, "misaligned offset"); @@ -642,19 +623,58 @@ } -void Runtime1::generate_handle_exception(StubAssembler *sasm, OopMapSet* oop_maps, OopMap* oop_map, bool save_fpu_registers) { +OopMapSet* Runtime1::generate_handle_exception(StubID id, StubAssembler *sasm) { + __ block_comment("generate_handle_exception"); + // incoming parameters const Register exception_oop = rax; - const Register exception_pc = rdx; + const Register exception_pc = rdx; // other registers used in this stub - const Register real_return_addr = rbx; const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread); - __ block_comment("generate_handle_exception"); + // Save registers, if required. + OopMapSet* oop_maps = new OopMapSet(); + OopMap* oop_map = NULL; + switch (id) { + case forward_exception_id: + // We're handling an exception in the context of a compiled frame. + // The registers have been saved in the standard places. Perform + // an exception lookup in the caller and dispatch to the handler + // if found. Otherwise unwind and dispatch to the callers + // exception handler. + oop_map = generate_oop_map(sasm, 1 /*thread*/); + + // load and clear pending exception oop into RAX + __ movptr(exception_oop, Address(thread, Thread::pending_exception_offset())); + __ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD); + + // load issuing PC (the return address for this stub) into rdx + __ movptr(exception_pc, Address(rbp, 1*BytesPerWord)); + + // make sure that the vm_results are cleared (may be unnecessary) + __ movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD); + __ movptr(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD); + break; + case handle_exception_nofpu_id: + case handle_exception_id: + // At this point all registers MAY be live. + oop_map = save_live_registers(sasm, 1 /*thread*/, id == handle_exception_nofpu_id); + break; + case handle_exception_from_callee_id: { + // At this point all registers except exception oop (RAX) and + // exception pc (RDX) are dead. + const int frame_size = 2 /*BP, return address*/ NOT_LP64(+ 1 /*thread*/) WIN64_ONLY(+ frame::arg_reg_save_area_bytes / BytesPerWord); + oop_map = new OopMap(frame_size * VMRegImpl::slots_per_word, 0); + sasm->set_frame_size(frame_size); + WIN64_ONLY(__ subq(rsp, frame::arg_reg_save_area_bytes)); + break; + } + default: ShouldNotReachHere(); + } #ifdef TIERED // C2 can leave the fpu stack dirty - if (UseSSE < 2 ) { + if (UseSSE < 2) { __ empty_FPU_stack(); } #endif // TIERED @@ -686,11 +706,7 @@ // save exception oop and issuing pc into JavaThread // (exception handler will load it from here) __ movptr(Address(thread, JavaThread::exception_oop_offset()), exception_oop); - __ movptr(Address(thread, JavaThread::exception_pc_offset()), exception_pc); - - // save real return address (pc that called this stub) - __ movptr(real_return_addr, Address(rbp, 1*BytesPerWord)); - __ movptr(Address(rsp, temp_1_off * VMRegImpl::stack_slot_size), real_return_addr); + __ movptr(Address(thread, JavaThread::exception_pc_offset()), exception_pc); // patch throwing pc into return address (has bci & oop map) __ movptr(Address(rbp, 1*BytesPerWord), exception_pc); @@ -700,33 +716,41 @@ int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc)); oop_maps->add_gc_map(call_offset, oop_map); - // rax,: handler address + // rax: handler address // will be the deopt blob if nmethod was deoptimized while we looked up // handler regardless of whether handler existed in the nmethod. // only rax, is valid at this time, all other registers have been destroyed by the runtime call __ invalidate_registers(false, true, true, true, true, true); -#ifdef ASSERT - // Do we have an exception handler in the nmethod? - Label done; - __ testptr(rax, rax); - __ jcc(Assembler::notZero, done); - __ stop("no handler found"); - __ bind(done); -#endif - - // exception handler found - // patch the return address -> the stub will directly return to the exception handler + // patch the return address, this stub will directly return to the exception handler __ movptr(Address(rbp, 1*BytesPerWord), rax); - // restore registers - restore_live_registers(sasm, save_fpu_registers); + switch (id) { + case forward_exception_id: + case handle_exception_nofpu_id: + case handle_exception_id: + // Restore the registers that were saved at the beginning. + restore_live_registers(sasm, id == handle_exception_nofpu_id); + break; + case handle_exception_from_callee_id: + // WIN64_ONLY: No need to add frame::arg_reg_save_area_bytes to SP + // since we do a leave anyway. - // return to exception handler - __ leave(); - __ ret(0); + // Pop the return address since we are possibly changing SP (restoring from BP). + __ leave(); + __ pop(rcx); + // Restore SP from BP if the exception PC is a method handle call site. + NOT_LP64(__ get_thread(thread);) + __ cmpl(Address(thread, JavaThread::is_method_handle_return_offset()), 0); + __ cmovptr(Assembler::notEqual, rsp, rbp_mh_SP_save); + __ jmp(rcx); // jump to exception handler + break; + default: ShouldNotReachHere(); + } + + return oop_maps; } @@ -791,7 +815,7 @@ // the pop is also necessary to simulate the effect of a ret(0) __ pop(exception_pc); - // Restore SP from BP if the exception PC is a MethodHandle call site. + // Restore SP from BP if the exception PC is a method handle call site. NOT_LP64(__ get_thread(thread);) __ cmpl(Address(thread, JavaThread::is_method_handle_return_offset()), 0); __ cmovptr(Assembler::notEqual, rsp, rbp_mh_SP_save); @@ -934,7 +958,6 @@ __ ret(0); return oop_maps; - } @@ -952,35 +975,9 @@ switch (id) { case forward_exception_id: { - // we're handling an exception in the context of a compiled - // frame. The registers have been saved in the standard - // places. Perform an exception lookup in the caller and - // dispatch to the handler if found. Otherwise unwind and - // dispatch to the callers exception handler. - - const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread); - const Register exception_oop = rax; - const Register exception_pc = rdx; - - // load pending exception oop into rax, - __ movptr(exception_oop, Address(thread, Thread::pending_exception_offset())); - // clear pending exception - __ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD); - - // load issuing PC (the return address for this stub) into rdx - __ movptr(exception_pc, Address(rbp, 1*BytesPerWord)); - - // make sure that the vm_results are cleared (may be unnecessary) - __ movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD); - __ movptr(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD); - - // verify that that there is really a valid exception in rax, - __ verify_not_null_oop(exception_oop); - - oop_maps = new OopMapSet(); - OopMap* oop_map = generate_oop_map(sasm, 1); - generate_handle_exception(sasm, oop_maps, oop_map); - __ stop("should not reach here"); + oop_maps = generate_handle_exception(id, sasm); + __ leave(); + __ ret(0); } break; @@ -1315,13 +1312,15 @@ break; case handle_exception_nofpu_id: - save_fpu_registers = false; - // fall through case handle_exception_id: { StubFrame f(sasm, "handle_exception", dont_gc_arguments); - oop_maps = new OopMapSet(); - OopMap* oop_map = save_live_registers(sasm, 1, save_fpu_registers); - generate_handle_exception(sasm, oop_maps, oop_map, save_fpu_registers); + oop_maps = generate_handle_exception(id, sasm); + } + break; + + case handle_exception_from_callee_id: + { StubFrame f(sasm, "handle_exception_from_callee", dont_gc_arguments); + oop_maps = generate_handle_exception(id, sasm); } break;
--- a/src/cpu/x86/vm/interpreter_x86_32.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/interpreter_x86_32.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -231,7 +231,7 @@ // Method handle invoker -// Dispatch a method of the form java.dyn.MethodHandles::invoke(...) +// Dispatch a method of the form java.lang.invoke.MethodHandles::invoke(...) address InterpreterGenerator::generate_method_handle_entry(void) { if (!EnableMethodHandles) { return generate_abstract_entry();
--- a/src/cpu/x86/vm/interpreter_x86_64.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/interpreter_x86_64.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -318,7 +318,7 @@ // Method handle invoker -// Dispatch a method of the form java.dyn.MethodHandles::invoke(...) +// Dispatch a method of the form java.lang.invoke.MethodHandles::invoke(...) address InterpreterGenerator::generate_method_handle_entry(void) { if (!EnableMethodHandles) { return generate_abstract_entry();
--- a/src/cpu/x86/vm/methodHandles_x86.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/methodHandles_x86.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -125,9 +125,9 @@ } // given the MethodType, find out where the MH argument is buried - __ load_heap_oop(rdx_temp, Address(rax_mtype, __ delayed_value(java_dyn_MethodType::form_offset_in_bytes, rdi_temp))); + __ load_heap_oop(rdx_temp, Address(rax_mtype, __ delayed_value(java_lang_invoke_MethodType::form_offset_in_bytes, rdi_temp))); Register rdx_vmslots = rdx_temp; - __ movl(rdx_vmslots, Address(rdx_temp, __ delayed_value(java_dyn_MethodTypeForm::vmslots_offset_in_bytes, rdi_temp))); + __ movl(rdx_vmslots, Address(rdx_temp, __ delayed_value(java_lang_invoke_MethodTypeForm::vmslots_offset_in_bytes, rdi_temp))); __ movptr(rcx_recv, __ argument_address(rdx_vmslots)); trace_method_handle(_masm, "invokeExact"); @@ -154,11 +154,11 @@ rcx_argslot, rbx_temp, rdx_temp); // load up an adapter from the calling type (Java weaves this) - __ load_heap_oop(rdx_temp, Address(rax_mtype, __ delayed_value(java_dyn_MethodType::form_offset_in_bytes, rdi_temp))); + __ load_heap_oop(rdx_temp, Address(rax_mtype, __ delayed_value(java_lang_invoke_MethodType::form_offset_in_bytes, rdi_temp))); Register rdx_adapter = rdx_temp; - // __ load_heap_oop(rdx_adapter, Address(rdx_temp, java_dyn_MethodTypeForm::genericInvoker_offset_in_bytes())); + // __ load_heap_oop(rdx_adapter, Address(rdx_temp, java_lang_invoke_MethodTypeForm::genericInvoker_offset_in_bytes())); // deal with old JDK versions: - __ lea(rdi_temp, Address(rdx_temp, __ delayed_value(java_dyn_MethodTypeForm::genericInvoker_offset_in_bytes, rdi_temp))); + __ lea(rdi_temp, Address(rdx_temp, __ delayed_value(java_lang_invoke_MethodTypeForm::genericInvoker_offset_in_bytes, rdi_temp))); __ cmpptr(rdi_temp, rdx_temp); Label sorry_no_invoke_generic; __ jcc(Assembler::below, sorry_no_invoke_generic); @@ -371,16 +371,16 @@ // which conversion op types are implemented here? int MethodHandles::adapter_conversion_ops_supported_mask() { - return ((1<<sun_dyn_AdapterMethodHandle::OP_RETYPE_ONLY) - |(1<<sun_dyn_AdapterMethodHandle::OP_RETYPE_RAW) - |(1<<sun_dyn_AdapterMethodHandle::OP_CHECK_CAST) - |(1<<sun_dyn_AdapterMethodHandle::OP_PRIM_TO_PRIM) - |(1<<sun_dyn_AdapterMethodHandle::OP_REF_TO_PRIM) - |(1<<sun_dyn_AdapterMethodHandle::OP_SWAP_ARGS) - |(1<<sun_dyn_AdapterMethodHandle::OP_ROT_ARGS) - |(1<<sun_dyn_AdapterMethodHandle::OP_DUP_ARGS) - |(1<<sun_dyn_AdapterMethodHandle::OP_DROP_ARGS) - //|(1<<sun_dyn_AdapterMethodHandle::OP_SPREAD_ARGS) //BUG! + return ((1<<java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_PRIM) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_REF_TO_PRIM) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS) + |(1<<java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS) + //|(1<<java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS) //BUG! ); // FIXME: MethodHandlesTest gets a crash if we enable OP_SPREAD_ARGS. } @@ -415,20 +415,21 @@ const Register rarg2_required = LP64_ONLY(j_rarg2) NOT_LP64(rdi); assert_different_registers(rarg0_code, rarg1_actual, rarg2_required, saved_last_sp); - guarantee(java_dyn_MethodHandle::vmentry_offset_in_bytes() != 0, "must have offsets"); + guarantee(java_lang_invoke_MethodHandle::vmentry_offset_in_bytes() != 0, "must have offsets"); // some handy addresses Address rbx_method_fie( rbx, methodOopDesc::from_interpreted_offset() ); + Address rbx_method_fce( rbx, methodOopDesc::from_compiled_offset() ); - Address rcx_mh_vmtarget( rcx_recv, java_dyn_MethodHandle::vmtarget_offset_in_bytes() ); - Address rcx_dmh_vmindex( rcx_recv, sun_dyn_DirectMethodHandle::vmindex_offset_in_bytes() ); + Address rcx_mh_vmtarget( rcx_recv, java_lang_invoke_MethodHandle::vmtarget_offset_in_bytes() ); + Address rcx_dmh_vmindex( rcx_recv, java_lang_invoke_DirectMethodHandle::vmindex_offset_in_bytes() ); - Address rcx_bmh_vmargslot( rcx_recv, sun_dyn_BoundMethodHandle::vmargslot_offset_in_bytes() ); - Address rcx_bmh_argument( rcx_recv, sun_dyn_BoundMethodHandle::argument_offset_in_bytes() ); + Address rcx_bmh_vmargslot( rcx_recv, java_lang_invoke_BoundMethodHandle::vmargslot_offset_in_bytes() ); + Address rcx_bmh_argument( rcx_recv, java_lang_invoke_BoundMethodHandle::argument_offset_in_bytes() ); - Address rcx_amh_vmargslot( rcx_recv, sun_dyn_AdapterMethodHandle::vmargslot_offset_in_bytes() ); - Address rcx_amh_argument( rcx_recv, sun_dyn_AdapterMethodHandle::argument_offset_in_bytes() ); - Address rcx_amh_conversion( rcx_recv, sun_dyn_AdapterMethodHandle::conversion_offset_in_bytes() ); + Address rcx_amh_vmargslot( rcx_recv, java_lang_invoke_AdapterMethodHandle::vmargslot_offset_in_bytes() ); + Address rcx_amh_argument( rcx_recv, java_lang_invoke_AdapterMethodHandle::argument_offset_in_bytes() ); + Address rcx_amh_conversion( rcx_recv, java_lang_invoke_AdapterMethodHandle::conversion_offset_in_bytes() ); Address vmarg; // __ argument_address(vmargslot) const int java_mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes(); @@ -448,12 +449,10 @@ case _raise_exception: { // Not a real MH entry, but rather shared code for raising an - // exception. Since we use a C2I adapter to set up the - // interpreter state, arguments are expected in compiler - // argument registers. + // exception. Since we use the compiled entry, arguments are + // expected in compiler argument registers. assert(raise_exception_method(), "must be set"); - address c2i_entry = raise_exception_method()->get_c2i_entry(); - assert(c2i_entry, "method must be linked"); + assert(raise_exception_method()->from_compiled_entry(), "method must be linked"); const Register rdi_pc = rax; __ pop(rdi_pc); // caller PC @@ -461,7 +460,7 @@ Register rbx_method = rbx_temp; Label L_no_method; - // FIXME: fill in _raise_exception_method with a suitable sun.dyn method + // FIXME: fill in _raise_exception_method with a suitable java.lang.invoke method __ movptr(rbx_method, ExternalAddress((address) &_raise_exception_method)); __ testptr(rbx_method, rbx_method); __ jccb(Assembler::zero, L_no_method); @@ -472,13 +471,10 @@ __ jccb(Assembler::zero, L_no_method); __ verify_oop(rbx_method); - // 32-bit: push remaining arguments as if coming from the compiler. NOT_LP64(__ push(rarg2_required)); + __ push(rdi_pc); // restore caller PC + __ jmp(rbx_method_fce); // jump to compiled entry - __ push(rdi_pc); // restore caller PC - __ jump(ExternalAddress(c2i_entry)); // do C2I transition - - // If we get here, the Java runtime did not do its job of creating the exception. // Do something that is at least causes a valid throw from the interpreter. __ bind(L_no_method); __ push(rarg2_required);
--- a/src/cpu/x86/vm/stubGenerator_x86_32.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/stubGenerator_x86_32.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -439,10 +439,6 @@ // Verify that there is really a valid exception in RAX. __ verify_oop(exception_oop); - // Restore SP from BP if the exception PC is a MethodHandle call site. - __ cmpl(Address(thread, JavaThread::is_method_handle_return_offset()), 0); - __ cmovptr(Assembler::notEqual, rsp, rbp); - // continue at exception handler (return address removed) // rax: exception // rbx: exception handler @@ -733,18 +729,19 @@ // Input: // start - starting address // count - element count - void gen_write_ref_array_pre_barrier(Register start, Register count) { + void gen_write_ref_array_pre_barrier(Register start, Register count, bool uninitialized_target) { assert_different_registers(start, count); BarrierSet* bs = Universe::heap()->barrier_set(); switch (bs->kind()) { case BarrierSet::G1SATBCT: case BarrierSet::G1SATBCTLogging: - { - __ pusha(); // push registers - __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre), - start, count); - __ popa(); - } + // With G1, don't generate the call if we statically know that the target in uninitialized + if (!uninitialized_target) { + __ pusha(); // push registers + __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre), + start, count); + __ popa(); + } break; case BarrierSet::CardTableModRef: case BarrierSet::CardTableExtension: @@ -923,7 +920,8 @@ address generate_disjoint_copy(BasicType t, bool aligned, Address::ScaleFactor sf, - address* entry, const char *name) { + address* entry, const char *name, + bool dest_uninitialized = false) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -945,16 +943,19 @@ __ movptr(from , Address(rsp, 12+ 4)); __ movptr(to , Address(rsp, 12+ 8)); __ movl(count, Address(rsp, 12+ 12)); + + if (entry != NULL) { + *entry = __ pc(); // Entry point from conjoint arraycopy stub. + BLOCK_COMMENT("Entry:"); + } + if (t == T_OBJECT) { __ testl(count, count); __ jcc(Assembler::zero, L_0_count); - gen_write_ref_array_pre_barrier(to, count); + gen_write_ref_array_pre_barrier(to, count, dest_uninitialized); __ mov(saved_to, to); // save 'to' } - *entry = __ pc(); // Entry point from conjoint arraycopy stub. - BLOCK_COMMENT("Entry:"); - __ subptr(to, from); // to --> to_from __ cmpl(count, 2<<shift); // Short arrays (< 8 bytes) copy by element __ jcc(Assembler::below, L_copy_4_bytes); // use unsigned cmp @@ -1085,7 +1086,8 @@ address generate_conjoint_copy(BasicType t, bool aligned, Address::ScaleFactor sf, address nooverlap_target, - address* entry, const char *name) { + address* entry, const char *name, + bool dest_uninitialized = false) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1108,23 +1110,17 @@ __ movptr(src , Address(rsp, 12+ 4)); // from __ movptr(dst , Address(rsp, 12+ 8)); // to __ movl2ptr(count, Address(rsp, 12+12)); // count - if (t == T_OBJECT) { - gen_write_ref_array_pre_barrier(dst, count); - } if (entry != NULL) { *entry = __ pc(); // Entry point from generic arraycopy stub. BLOCK_COMMENT("Entry:"); } - if (t == T_OBJECT) { - __ testl(count, count); - __ jcc(Assembler::zero, L_0_count); - } + // nooverlap_target expects arguments in rsi and rdi. __ mov(from, src); __ mov(to , dst); - // arrays overlap test + // arrays overlap test: dispatch to disjoint stub if necessary. RuntimeAddress nooverlap(nooverlap_target); __ cmpptr(dst, src); __ lea(end, Address(src, count, sf, 0)); // src + count * elem_size @@ -1132,6 +1128,12 @@ __ cmpptr(dst, end); __ jump_cc(Assembler::aboveEqual, nooverlap); + if (t == T_OBJECT) { + __ testl(count, count); + __ jcc(Assembler::zero, L_0_count); + gen_write_ref_array_pre_barrier(dst, count, dest_uninitialized); + } + // copy from high to low __ cmpl(count, 2<<shift); // Short arrays (< 8 bytes) copy by element __ jcc(Assembler::below, L_copy_4_bytes); // use unsigned cmp @@ -1416,7 +1418,7 @@ // rax, == 0 - success // rax, == -1^K - failure, where K is partial transfer count // - address generate_checkcast_copy(const char *name, address* entry) { + address generate_checkcast_copy(const char *name, address* entry, bool dest_uninitialized = false) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1451,8 +1453,10 @@ __ movptr(to, to_arg); __ movl2ptr(length, length_arg); - *entry = __ pc(); // Entry point from generic arraycopy stub. - BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); // Entry point from generic arraycopy stub. + BLOCK_COMMENT("Entry:"); + } //--------------------------------------------------------------- // Assembler stub will be used for this call to arraycopy @@ -1475,7 +1479,7 @@ Address elem_klass_addr(elem, oopDesc::klass_offset_in_bytes()); // Copy from low to high addresses, indexed from the end of each array. - gen_write_ref_array_pre_barrier(to, count); + gen_write_ref_array_pre_barrier(to, count, dest_uninitialized); __ lea(end_from, end_from_addr); __ lea(end_to, end_to_addr); assert(length == count, ""); // else fix next line: @@ -2038,6 +2042,15 @@ generate_conjoint_copy(T_OBJECT, true, Address::times_ptr, entry, &entry_oop_arraycopy, "oop_arraycopy"); + StubRoutines::_oop_disjoint_arraycopy_uninit = + generate_disjoint_copy(T_OBJECT, true, Address::times_ptr, &entry, + "oop_disjoint_arraycopy_uninit", + /*dest_uninitialized*/true); + StubRoutines::_oop_arraycopy_uninit = + generate_conjoint_copy(T_OBJECT, true, Address::times_ptr, entry, + NULL, "oop_arraycopy_uninit", + /*dest_uninitialized*/true); + StubRoutines::_jlong_disjoint_arraycopy = generate_disjoint_long_copy(&entry, "jlong_disjoint_arraycopy"); StubRoutines::_jlong_arraycopy = @@ -2051,20 +2064,20 @@ StubRoutines::_arrayof_jshort_fill = generate_fill(T_SHORT, true, "arrayof_jshort_fill"); StubRoutines::_arrayof_jint_fill = generate_fill(T_INT, true, "arrayof_jint_fill"); - StubRoutines::_arrayof_jint_disjoint_arraycopy = - StubRoutines::_jint_disjoint_arraycopy; - StubRoutines::_arrayof_oop_disjoint_arraycopy = - StubRoutines::_oop_disjoint_arraycopy; - StubRoutines::_arrayof_jlong_disjoint_arraycopy = - StubRoutines::_jlong_disjoint_arraycopy; + StubRoutines::_arrayof_jint_disjoint_arraycopy = StubRoutines::_jint_disjoint_arraycopy; + StubRoutines::_arrayof_oop_disjoint_arraycopy = StubRoutines::_oop_disjoint_arraycopy; + StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = StubRoutines::_oop_disjoint_arraycopy_uninit; + StubRoutines::_arrayof_jlong_disjoint_arraycopy = StubRoutines::_jlong_disjoint_arraycopy; - StubRoutines::_arrayof_jint_arraycopy = StubRoutines::_jint_arraycopy; - StubRoutines::_arrayof_oop_arraycopy = StubRoutines::_oop_arraycopy; - StubRoutines::_arrayof_jlong_arraycopy = StubRoutines::_jlong_arraycopy; + StubRoutines::_arrayof_jint_arraycopy = StubRoutines::_jint_arraycopy; + StubRoutines::_arrayof_oop_arraycopy = StubRoutines::_oop_arraycopy; + StubRoutines::_arrayof_oop_arraycopy_uninit = StubRoutines::_oop_arraycopy_uninit; + StubRoutines::_arrayof_jlong_arraycopy = StubRoutines::_jlong_arraycopy; StubRoutines::_checkcast_arraycopy = - generate_checkcast_copy("checkcast_arraycopy", - &entry_checkcast_arraycopy); + generate_checkcast_copy("checkcast_arraycopy", &entry_checkcast_arraycopy); + StubRoutines::_checkcast_arraycopy_uninit = + generate_checkcast_copy("checkcast_arraycopy_uninit", NULL, /*dest_uninitialized*/true); StubRoutines::_unsafe_arraycopy = generate_unsafe_copy("unsafe_arraycopy",
--- a/src/cpu/x86/vm/stubGenerator_x86_64.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/stubGenerator_x86_64.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1057,20 +1057,6 @@ return start; } - static address disjoint_byte_copy_entry; - static address disjoint_short_copy_entry; - static address disjoint_int_copy_entry; - static address disjoint_long_copy_entry; - static address disjoint_oop_copy_entry; - - static address byte_copy_entry; - static address short_copy_entry; - static address int_copy_entry; - static address long_copy_entry; - static address oop_copy_entry; - - static address checkcast_copy_entry; - // // Verify that a register contains clean 32-bits positive value // (high 32-bits are 0) so it could be used in 64-bits shifts. @@ -1173,34 +1159,35 @@ // Generate code for an array write pre barrier // // addr - starting address - // count - element count + // count - element count + // tmp - scratch register // // Destroy no registers! // - void gen_write_ref_array_pre_barrier(Register addr, Register count) { + void gen_write_ref_array_pre_barrier(Register addr, Register count, bool dest_uninitialized) { BarrierSet* bs = Universe::heap()->barrier_set(); switch (bs->kind()) { case BarrierSet::G1SATBCT: case BarrierSet::G1SATBCTLogging: - { - __ pusha(); // push registers - if (count == c_rarg0) { - if (addr == c_rarg1) { - // exactly backwards!! - __ xchgptr(c_rarg1, c_rarg0); - } else { - __ movptr(c_rarg1, count); - __ movptr(c_rarg0, addr); - } - - } else { - __ movptr(c_rarg0, addr); - __ movptr(c_rarg1, count); - } - __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre), 2); - __ popa(); + // With G1, don't generate the call if we statically know that the target in uninitialized + if (!dest_uninitialized) { + __ pusha(); // push registers + if (count == c_rarg0) { + if (addr == c_rarg1) { + // exactly backwards!! + __ xchgptr(c_rarg1, c_rarg0); + } else { + __ movptr(c_rarg1, count); + __ movptr(c_rarg0, addr); + } + } else { + __ movptr(c_rarg0, addr); + __ movptr(c_rarg1, count); + } + __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre), 2); + __ popa(); } - break; + break; case BarrierSet::CardTableModRef: case BarrierSet::CardTableExtension: case BarrierSet::ModRef: @@ -1379,7 +1366,7 @@ // disjoint_byte_copy_entry is set to the no-overlap entry point // used by generate_conjoint_byte_copy(). // - address generate_disjoint_byte_copy(bool aligned, const char *name) { + address generate_disjoint_byte_copy(bool aligned, address* entry, const char *name) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1399,9 +1386,11 @@ __ enter(); // required for proper stackwalking of RuntimeStub frame assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. - disjoint_byte_copy_entry = __ pc(); - BLOCK_COMMENT("Entry:"); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } setup_arg_regs(); // from => rdi, to => rsi, count => rdx // r9 and r10 may be used to save non-volatile registers @@ -1479,7 +1468,8 @@ // dwords or qwords that span cache line boundaries will still be loaded // and stored atomically. // - address generate_conjoint_byte_copy(bool aligned, const char *name) { + address generate_conjoint_byte_copy(bool aligned, address nooverlap_target, + address* entry, const char *name) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1494,11 +1484,13 @@ __ enter(); // required for proper stackwalking of RuntimeStub frame assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. - byte_copy_entry = __ pc(); - BLOCK_COMMENT("Entry:"); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - - array_overlap_test(disjoint_byte_copy_entry, Address::times_1); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } + + array_overlap_test(nooverlap_target, Address::times_1); setup_arg_regs(); // from => rdi, to => rsi, count => rdx // r9 and r10 may be used to save non-volatile registers @@ -1574,7 +1566,7 @@ // disjoint_short_copy_entry is set to the no-overlap entry point // used by generate_conjoint_short_copy(). // - address generate_disjoint_short_copy(bool aligned, const char *name) { + address generate_disjoint_short_copy(bool aligned, address *entry, const char *name) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1593,9 +1585,11 @@ __ enter(); // required for proper stackwalking of RuntimeStub frame assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. - disjoint_short_copy_entry = __ pc(); - BLOCK_COMMENT("Entry:"); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } setup_arg_regs(); // from => rdi, to => rsi, count => rdx // r9 and r10 may be used to save non-volatile registers @@ -1686,7 +1680,8 @@ // or qwords that span cache line boundaries will still be loaded // and stored atomically. // - address generate_conjoint_short_copy(bool aligned, const char *name) { + address generate_conjoint_short_copy(bool aligned, address nooverlap_target, + address *entry, const char *name) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1701,11 +1696,13 @@ __ enter(); // required for proper stackwalking of RuntimeStub frame assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. - short_copy_entry = __ pc(); - BLOCK_COMMENT("Entry:"); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - - array_overlap_test(disjoint_short_copy_entry, Address::times_2); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } + + array_overlap_test(nooverlap_target, Address::times_2); setup_arg_regs(); // from => rdi, to => rsi, count => rdx // r9 and r10 may be used to save non-volatile registers @@ -1773,7 +1770,8 @@ // disjoint_int_copy_entry is set to the no-overlap entry point // used by generate_conjoint_int_oop_copy(). // - address generate_disjoint_int_oop_copy(bool aligned, bool is_oop, const char *name) { + address generate_disjoint_int_oop_copy(bool aligned, bool is_oop, address* entry, + const char *name, bool dest_uninitialized = false) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1793,21 +1791,17 @@ __ enter(); // required for proper stackwalking of RuntimeStub frame assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. - (is_oop ? disjoint_oop_copy_entry : disjoint_int_copy_entry) = __ pc(); - - if (is_oop) { - // no registers are destroyed by this call - gen_write_ref_array_pre_barrier(/* dest */ c_rarg1, /* count */ c_rarg2); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); } - BLOCK_COMMENT("Entry:"); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - setup_arg_regs(); // from => rdi, to => rsi, count => rdx // r9 and r10 may be used to save non-volatile registers - if (is_oop) { __ movq(saved_to, to); + gen_write_ref_array_pre_barrier(to, count, dest_uninitialized); } // 'from', 'to' and 'count' are now valid @@ -1867,7 +1861,9 @@ // the hardware handle it. The two dwords within qwords that span // cache line boundaries will still be loaded and stored atomicly. // - address generate_conjoint_int_oop_copy(bool aligned, bool is_oop, const char *name) { + address generate_conjoint_int_oop_copy(bool aligned, bool is_oop, address nooverlap_target, + address *entry, const char *name, + bool dest_uninitialized = false) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1882,20 +1878,21 @@ __ enter(); // required for proper stackwalking of RuntimeStub frame assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); + } + + array_overlap_test(nooverlap_target, Address::times_4); + setup_arg_regs(); // from => rdi, to => rsi, count => rdx + // r9 and r10 may be used to save non-volatile registers + if (is_oop) { // no registers are destroyed by this call - gen_write_ref_array_pre_barrier(/* dest */ c_rarg1, /* count */ c_rarg2); + gen_write_ref_array_pre_barrier(to, count, dest_uninitialized); } - (is_oop ? oop_copy_entry : int_copy_entry) = __ pc(); - BLOCK_COMMENT("Entry:"); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - - array_overlap_test(is_oop ? disjoint_oop_copy_entry : disjoint_int_copy_entry, - Address::times_4); - setup_arg_regs(); // from => rdi, to => rsi, count => rdx - // r9 and r10 may be used to save non-volatile registers - assert_clean_int(count, rax); // Make sure 'count' is clean int. // 'from', 'to' and 'count' are now valid __ movptr(dword_count, count); @@ -1959,7 +1956,8 @@ // disjoint_oop_copy_entry or disjoint_long_copy_entry is set to the // no-overlap entry point used by generate_conjoint_long_oop_copy(). // - address generate_disjoint_long_oop_copy(bool aligned, bool is_oop, const char *name) { + address generate_disjoint_long_oop_copy(bool aligned, bool is_oop, address *entry, + const char *name, bool dest_uninitialized = false) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -1978,20 +1976,19 @@ // Save no-overlap entry point for generate_conjoint_long_oop_copy() assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. - if (is_oop) { - disjoint_oop_copy_entry = __ pc(); - // no registers are destroyed by this call - gen_write_ref_array_pre_barrier(/* dest */ c_rarg1, /* count */ c_rarg2); - } else { - disjoint_long_copy_entry = __ pc(); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); } - BLOCK_COMMENT("Entry:"); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) setup_arg_regs(); // from => rdi, to => rsi, count => rdx // r9 and r10 may be used to save non-volatile registers - // 'from', 'to' and 'qword_count' are now valid + if (is_oop) { + // no registers are destroyed by this call + gen_write_ref_array_pre_barrier(to, qword_count, dest_uninitialized); + } // Copy from low to high addresses. Use 'to' as scratch. __ lea(end_from, Address(from, qword_count, Address::times_8, -8)); @@ -2045,7 +2042,9 @@ // c_rarg1 - destination array address // c_rarg2 - element count, treated as ssize_t, can be zero // - address generate_conjoint_long_oop_copy(bool aligned, bool is_oop, const char *name) { + address generate_conjoint_long_oop_copy(bool aligned, bool is_oop, + address nooverlap_target, address *entry, + const char *name, bool dest_uninitialized = false) { __ align(CodeEntryAlignment); StubCodeMark mark(this, "StubRoutines", name); address start = __ pc(); @@ -2059,31 +2058,21 @@ __ enter(); // required for proper stackwalking of RuntimeStub frame assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. - address disjoint_copy_entry = NULL; - if (is_oop) { - assert(!UseCompressedOops, "shouldn't be called for compressed oops"); - disjoint_copy_entry = disjoint_oop_copy_entry; - oop_copy_entry = __ pc(); - array_overlap_test(disjoint_oop_copy_entry, Address::times_8); - } else { - disjoint_copy_entry = disjoint_long_copy_entry; - long_copy_entry = __ pc(); - array_overlap_test(disjoint_long_copy_entry, Address::times_8); + if (entry != NULL) { + *entry = __ pc(); + // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) + BLOCK_COMMENT("Entry:"); } - BLOCK_COMMENT("Entry:"); - // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) - - array_overlap_test(disjoint_copy_entry, Address::times_8); + + array_overlap_test(nooverlap_target, Address::times_8); setup_arg_regs(); // from => rdi, to => rsi, count => rdx // r9 and r10 may be used to save non-volatile registers - // 'from', 'to' and 'qword_count' are now valid - if (is_oop) { // Save to and count for store barrier __ movptr(saved_count, qword_count); // No registers are destroyed by this call - gen_write_ref_array_pre_barrier(to, saved_count); + gen_write_ref_array_pre_barrier(to, saved_count, dest_uninitialized); } __ jmp(L_copy_32_bytes); @@ -2162,7 +2151,8 @@ // rax == 0 - success // rax == -1^K - failure, where K is partial transfer count // - address generate_checkcast_copy(const char *name) { + address generate_checkcast_copy(const char *name, address *entry, + bool dest_uninitialized = false) { Label L_load_element, L_store_element, L_do_card_marks, L_done; @@ -2216,8 +2206,10 @@ #endif // Caller of this entry point must set up the argument registers. - checkcast_copy_entry = __ pc(); - BLOCK_COMMENT("Entry:"); + if (entry != NULL) { + *entry = __ pc(); + BLOCK_COMMENT("Entry:"); + } // allocate spill slots for r13, r14 enum { @@ -2254,7 +2246,7 @@ Address from_element_addr(end_from, count, TIMES_OOP, 0); Address to_element_addr(end_to, count, TIMES_OOP, 0); - gen_write_ref_array_pre_barrier(to, count); + gen_write_ref_array_pre_barrier(to, count, dest_uninitialized); // Copy from low to high addresses, indexed from the end of each array. __ lea(end_from, end_from_addr); @@ -2334,7 +2326,9 @@ // Examines the alignment of the operands and dispatches // to a long, int, short, or byte copy loop. // - address generate_unsafe_copy(const char *name) { + address generate_unsafe_copy(const char *name, + address byte_copy_entry, address short_copy_entry, + address int_copy_entry, address long_copy_entry) { Label L_long_aligned, L_int_aligned, L_short_aligned; @@ -2432,7 +2426,10 @@ // rax == 0 - success // rax == -1^K - failure, where K is partial transfer count // - address generate_generic_copy(const char *name) { + address generate_generic_copy(const char *name, + address byte_copy_entry, address short_copy_entry, + address int_copy_entry, address long_copy_entry, + address oop_copy_entry, address checkcast_copy_entry) { Label L_failed, L_failed_0, L_objArray; Label L_copy_bytes, L_copy_shorts, L_copy_ints, L_copy_longs; @@ -2725,33 +2722,75 @@ } void generate_arraycopy_stubs() { - // Call the conjoint generation methods immediately after - // the disjoint ones so that short branches from the former - // to the latter can be generated. - StubRoutines::_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(false, "jbyte_disjoint_arraycopy"); - StubRoutines::_jbyte_arraycopy = generate_conjoint_byte_copy(false, "jbyte_arraycopy"); - - StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, "jshort_disjoint_arraycopy"); - StubRoutines::_jshort_arraycopy = generate_conjoint_short_copy(false, "jshort_arraycopy"); - - StubRoutines::_jint_disjoint_arraycopy = generate_disjoint_int_oop_copy(false, false, "jint_disjoint_arraycopy"); - StubRoutines::_jint_arraycopy = generate_conjoint_int_oop_copy(false, false, "jint_arraycopy"); - - StubRoutines::_jlong_disjoint_arraycopy = generate_disjoint_long_oop_copy(false, false, "jlong_disjoint_arraycopy"); - StubRoutines::_jlong_arraycopy = generate_conjoint_long_oop_copy(false, false, "jlong_arraycopy"); + address entry; + address entry_jbyte_arraycopy; + address entry_jshort_arraycopy; + address entry_jint_arraycopy; + address entry_oop_arraycopy; + address entry_jlong_arraycopy; + address entry_checkcast_arraycopy; + + StubRoutines::_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(false, &entry, + "jbyte_disjoint_arraycopy"); + StubRoutines::_jbyte_arraycopy = generate_conjoint_byte_copy(false, entry, &entry_jbyte_arraycopy, + "jbyte_arraycopy"); + + StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, &entry, + "jshort_disjoint_arraycopy"); + StubRoutines::_jshort_arraycopy = generate_conjoint_short_copy(false, entry, &entry_jshort_arraycopy, + "jshort_arraycopy"); + + StubRoutines::_jint_disjoint_arraycopy = generate_disjoint_int_oop_copy(false, false, &entry, + "jint_disjoint_arraycopy"); + StubRoutines::_jint_arraycopy = generate_conjoint_int_oop_copy(false, false, entry, + &entry_jint_arraycopy, "jint_arraycopy"); + + StubRoutines::_jlong_disjoint_arraycopy = generate_disjoint_long_oop_copy(false, false, &entry, + "jlong_disjoint_arraycopy"); + StubRoutines::_jlong_arraycopy = generate_conjoint_long_oop_copy(false, false, entry, + &entry_jlong_arraycopy, "jlong_arraycopy"); if (UseCompressedOops) { - StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_int_oop_copy(false, true, "oop_disjoint_arraycopy"); - StubRoutines::_oop_arraycopy = generate_conjoint_int_oop_copy(false, true, "oop_arraycopy"); + StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_int_oop_copy(false, true, &entry, + "oop_disjoint_arraycopy"); + StubRoutines::_oop_arraycopy = generate_conjoint_int_oop_copy(false, true, entry, + &entry_oop_arraycopy, "oop_arraycopy"); + StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_int_oop_copy(false, true, &entry, + "oop_disjoint_arraycopy_uninit", + /*dest_uninitialized*/true); + StubRoutines::_oop_arraycopy_uninit = generate_conjoint_int_oop_copy(false, true, entry, + NULL, "oop_arraycopy_uninit", + /*dest_uninitialized*/true); } else { - StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_long_oop_copy(false, true, "oop_disjoint_arraycopy"); - StubRoutines::_oop_arraycopy = generate_conjoint_long_oop_copy(false, true, "oop_arraycopy"); + StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_long_oop_copy(false, true, &entry, + "oop_disjoint_arraycopy"); + StubRoutines::_oop_arraycopy = generate_conjoint_long_oop_copy(false, true, entry, + &entry_oop_arraycopy, "oop_arraycopy"); + StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_long_oop_copy(false, true, &entry, + "oop_disjoint_arraycopy_uninit", + /*dest_uninitialized*/true); + StubRoutines::_oop_arraycopy_uninit = generate_conjoint_long_oop_copy(false, true, entry, + NULL, "oop_arraycopy_uninit", + /*dest_uninitialized*/true); } - StubRoutines::_checkcast_arraycopy = generate_checkcast_copy("checkcast_arraycopy"); - StubRoutines::_unsafe_arraycopy = generate_unsafe_copy("unsafe_arraycopy"); - StubRoutines::_generic_arraycopy = generate_generic_copy("generic_arraycopy"); + StubRoutines::_checkcast_arraycopy = generate_checkcast_copy("checkcast_arraycopy", &entry_checkcast_arraycopy); + StubRoutines::_checkcast_arraycopy_uninit = generate_checkcast_copy("checkcast_arraycopy_uninit", NULL, + /*dest_uninitialized*/true); + + StubRoutines::_unsafe_arraycopy = generate_unsafe_copy("unsafe_arraycopy", + entry_jbyte_arraycopy, + entry_jshort_arraycopy, + entry_jint_arraycopy, + entry_jlong_arraycopy); + StubRoutines::_generic_arraycopy = generate_generic_copy("generic_arraycopy", + entry_jbyte_arraycopy, + entry_jshort_arraycopy, + entry_jint_arraycopy, + entry_oop_arraycopy, + entry_jlong_arraycopy, + entry_checkcast_arraycopy); StubRoutines::_jbyte_fill = generate_fill(T_BYTE, false, "jbyte_fill"); StubRoutines::_jshort_fill = generate_fill(T_SHORT, false, "jshort_fill"); @@ -2776,6 +2815,9 @@ StubRoutines::_arrayof_oop_disjoint_arraycopy = StubRoutines::_oop_disjoint_arraycopy; StubRoutines::_arrayof_oop_arraycopy = StubRoutines::_oop_arraycopy; + + StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = StubRoutines::_oop_disjoint_arraycopy_uninit; + StubRoutines::_arrayof_oop_arraycopy_uninit = StubRoutines::_oop_arraycopy_uninit; } void generate_math_stubs() { @@ -3069,20 +3111,6 @@ } }; // end class declaration -address StubGenerator::disjoint_byte_copy_entry = NULL; -address StubGenerator::disjoint_short_copy_entry = NULL; -address StubGenerator::disjoint_int_copy_entry = NULL; -address StubGenerator::disjoint_long_copy_entry = NULL; -address StubGenerator::disjoint_oop_copy_entry = NULL; - -address StubGenerator::byte_copy_entry = NULL; -address StubGenerator::short_copy_entry = NULL; -address StubGenerator::int_copy_entry = NULL; -address StubGenerator::long_copy_entry = NULL; -address StubGenerator::oop_copy_entry = NULL; - -address StubGenerator::checkcast_copy_entry = NULL; - void StubGenerator_generate(CodeBuffer* code, bool all) { StubGenerator g(code, all); }
--- a/src/cpu/x86/vm/templateTable_x86_32.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -3110,7 +3110,7 @@ __ profile_call(rsi); } - __ movptr(rcx_method_handle, Address(rax_callsite, __ delayed_value(java_dyn_CallSite::target_offset_in_bytes, rcx))); + __ movptr(rcx_method_handle, Address(rax_callsite, __ delayed_value(java_lang_invoke_CallSite::target_offset_in_bytes, rcx))); __ null_check(rcx_method_handle); __ prepare_to_jump_from_interpreted(); __ jump_to_method_handle_entry(rcx_method_handle, rdx);
--- a/src/cpu/x86/vm/templateTable_x86_64.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -3145,7 +3145,7 @@ __ profile_call(r13); } - __ load_heap_oop(rcx_method_handle, Address(rax_callsite, __ delayed_value(java_dyn_CallSite::target_offset_in_bytes, rcx))); + __ load_heap_oop(rcx_method_handle, Address(rax_callsite, __ delayed_value(java_lang_invoke_CallSite::target_offset_in_bytes, rcx))); __ null_check(rcx_method_handle); __ prepare_to_jump_from_interpreted(); __ jump_to_method_handle_entry(rcx_method_handle, rdx);
--- a/src/cpu/x86/vm/vm_version_x86.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/vm_version_x86.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -436,6 +436,13 @@ UseCountLeadingZerosInstruction = true; } } + + // On family 21 processors default is no sw prefetch + if ( cpu_family() == 21 ) { + if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) { + AllocatePrefetchStyle = 0; + } + } } if( is_intel() ) { // Intel cpus specific settings
--- a/src/cpu/x86/vm/x86_32.ad Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/x86_32.ad Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ // -// Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. +// Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. // // This code is free software; you can redistribute it and/or modify it @@ -12658,17 +12658,46 @@ ins_pipe( pipe_slow ); %} +// fast search of substring with known size. +instruct string_indexof_con(eDIRegP str1, eDXRegI cnt1, eSIRegP str2, immI int_cnt2, + eBXRegI result, regXD vec, eAXRegI cnt2, eCXRegI tmp, eFlagsReg cr) %{ + predicate(UseSSE42Intrinsics); + match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2))); + effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, KILL cnt2, KILL tmp, KILL cr); + + format %{ "String IndexOf $str1,$cnt1,$str2,$int_cnt2 -> $result // KILL $vec, $cnt1, $cnt2, $tmp" %} + ins_encode %{ + int icnt2 = (int)$int_cnt2$$constant; + if (icnt2 >= 8) { + // IndexOf for constant substrings with size >= 8 elements + // which don't need to be loaded through stack. + __ string_indexofC8($str1$$Register, $str2$$Register, + $cnt1$$Register, $cnt2$$Register, + icnt2, $result$$Register, + $vec$$XMMRegister, $tmp$$Register); + } else { + // Small strings are loaded through stack if they cross page boundary. + __ string_indexof($str1$$Register, $str2$$Register, + $cnt1$$Register, $cnt2$$Register, + icnt2, $result$$Register, + $vec$$XMMRegister, $tmp$$Register); + } + %} + ins_pipe( pipe_slow ); +%} + instruct string_indexof(eDIRegP str1, eDXRegI cnt1, eSIRegP str2, eAXRegI cnt2, - eBXRegI result, regXD tmp1, eCXRegI tmp2, eFlagsReg cr) %{ + eBXRegI result, regXD vec, eCXRegI tmp, eFlagsReg cr) %{ predicate(UseSSE42Intrinsics); match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2))); - effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp2, KILL cr); - - format %{ "String IndexOf $str1,$cnt1,$str2,$cnt2 -> $result // KILL $tmp2, $tmp1" %} + effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp, KILL cr); + + format %{ "String IndexOf $str1,$cnt1,$str2,$cnt2 -> $result // KILL all" %} ins_encode %{ __ string_indexof($str1$$Register, $str2$$Register, - $cnt1$$Register, $cnt2$$Register, $result$$Register, - $tmp1$$XMMRegister, $tmp2$$Register); + $cnt1$$Register, $cnt2$$Register, + (-1), $result$$Register, + $vec$$XMMRegister, $tmp$$Register); %} ins_pipe( pipe_slow ); %}
--- a/src/cpu/x86/vm/x86_64.ad Thu Mar 17 10:32:46 2011 -0700 +++ b/src/cpu/x86/vm/x86_64.ad Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ // -// Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. +// Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. // // This code is free software; you can redistribute it and/or modify it @@ -11598,18 +11598,48 @@ ins_pipe( pipe_slow ); %} +// fast search of substring with known size. +instruct string_indexof_con(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, immI int_cnt2, + rbx_RegI result, regD vec, rax_RegI cnt2, rcx_RegI tmp, rFlagsReg cr) +%{ + predicate(UseSSE42Intrinsics); + match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 int_cnt2))); + effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, KILL cnt2, KILL tmp, KILL cr); + + format %{ "String IndexOf $str1,$cnt1,$str2,$int_cnt2 -> $result // KILL $vec, $cnt1, $cnt2, $tmp" %} + ins_encode %{ + int icnt2 = (int)$int_cnt2$$constant; + if (icnt2 >= 8) { + // IndexOf for constant substrings with size >= 8 elements + // which don't need to be loaded through stack. + __ string_indexofC8($str1$$Register, $str2$$Register, + $cnt1$$Register, $cnt2$$Register, + icnt2, $result$$Register, + $vec$$XMMRegister, $tmp$$Register); + } else { + // Small strings are loaded through stack if they cross page boundary. + __ string_indexof($str1$$Register, $str2$$Register, + $cnt1$$Register, $cnt2$$Register, + icnt2, $result$$Register, + $vec$$XMMRegister, $tmp$$Register); + } + %} + ins_pipe( pipe_slow ); +%} + instruct string_indexof(rdi_RegP str1, rdx_RegI cnt1, rsi_RegP str2, rax_RegI cnt2, - rbx_RegI result, regD tmp1, rcx_RegI tmp2, rFlagsReg cr) + rbx_RegI result, regD vec, rcx_RegI tmp, rFlagsReg cr) %{ predicate(UseSSE42Intrinsics); match(Set result (StrIndexOf (Binary str1 cnt1) (Binary str2 cnt2))); - effect(TEMP tmp1, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp2, KILL cr); - - format %{ "String IndexOf $str1,$cnt1,$str2,$cnt2 -> $result // KILL $tmp1, $tmp2" %} + effect(TEMP vec, USE_KILL str1, USE_KILL str2, USE_KILL cnt1, USE_KILL cnt2, KILL tmp, KILL cr); + + format %{ "String IndexOf $str1,$cnt1,$str2,$cnt2 -> $result // KILL all" %} ins_encode %{ __ string_indexof($str1$$Register, $str2$$Register, - $cnt1$$Register, $cnt2$$Register, $result$$Register, - $tmp1$$XMMRegister, $tmp2$$Register); + $cnt1$$Register, $cnt2$$Register, + (-1), $result$$Register, + $vec$$XMMRegister, $tmp$$Register); %} ins_pipe( pipe_slow ); %}
--- a/src/os/solaris/dtrace/libjvm_db.c Thu Mar 17 10:32:46 2011 -0700 +++ b/src/os/solaris/dtrace/libjvm_db.c Fri Mar 18 09:03:43 2011 -0700 @@ -524,6 +524,8 @@ CHECK_FAIL(err); err = read_pointer(J, constantPool + nameIndex * POINTER_SIZE + SIZE_constantPoolOopDesc, &nameSymbol); CHECK_FAIL(err); + // The symbol is a CPSlot and has lower bit set to indicate metadata + nameSymbol &= (~1); // remove metadata lsb err = ps_pread(J->P, nameSymbol + OFFSET_Symbol_length, &nameSymbolLength, 2); CHECK_FAIL(err); nameString = (char*)calloc(nameSymbolLength + 1, 1); @@ -535,6 +537,7 @@ CHECK_FAIL(err); err = read_pointer(J, constantPool + signatureIndex * POINTER_SIZE + SIZE_constantPoolOopDesc, &signatureSymbol); CHECK_FAIL(err); + signatureSymbol &= (~1); // remove metadata lsb err = ps_pread(J->P, signatureSymbol + OFFSET_Symbol_length, &signatureSymbolLength, 2); CHECK_FAIL(err); signatureString = (char*)calloc(signatureSymbolLength + 1, 1);
--- a/src/share/tools/hsdis/hsdis-demo.c Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/tools/hsdis/hsdis-demo.c Fri Mar 18 09:03:43 2011 -0700 @@ -22,8 +22,6 @@ * */ -#include "precompiled.hpp" - /* hsdis-demo.c -- dump a range of addresses as native instructions This demonstrates the protocol required by the HotSpot PrintAssembly option. */
--- a/src/share/tools/hsdis/hsdis.c Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/tools/hsdis/hsdis.c Fri Mar 18 09:03:43 2011 -0700 @@ -22,8 +22,6 @@ * */ -#include "precompiled.hpp" - /* hsdis.c -- dump a range of addresses as native instructions This implements the plugin protocol required by the HotSpot PrintAssembly option.
--- a/src/share/vm/c1/c1_Canonicalizer.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/c1/c1_Canonicalizer.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -209,7 +209,7 @@ // limit this optimization to current block if (value != NULL && in_current_block(conv)) { set_canonical(new StoreField(x->obj(), x->offset(), x->field(), value, x->is_static(), - x->state_before(), x->is_loaded(), x->is_initialized())); + x->state_before(), x->needs_patching())); return; } }
--- a/src/share/vm/c1/c1_GraphBuilder.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/c1/c1_GraphBuilder.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1456,12 +1456,12 @@ BasicType field_type = field->type()->basic_type(); ValueType* type = as_ValueType(field_type); // call will_link again to determine if the field is valid. - const bool is_loaded = holder->is_loaded() && - field->will_link(method()->holder(), code); - const bool is_initialized = is_loaded && holder->is_initialized(); + const bool needs_patching = !holder->is_loaded() || + !field->will_link(method()->holder(), code) || + PatchALot; ValueStack* state_before = NULL; - if (!is_initialized || PatchALot) { + if (!holder->is_initialized() || needs_patching) { // save state before instruction for debug info when // deoptimization happens during patching state_before = copy_state_before(); @@ -1469,10 +1469,6 @@ Value obj = NULL; if (code == Bytecodes::_getstatic || code == Bytecodes::_putstatic) { - // commoning of class constants should only occur if the class is - // fully initialized and resolved in this constant pool. The will_link test - // above essentially checks if this class is resolved in this constant pool - // so, the is_initialized flag should be suffiect. if (state_before != NULL) { // build a patching constant obj = new Constant(new ClassConstant(holder), state_before); @@ -1482,7 +1478,7 @@ } - const int offset = is_loaded ? field->offset() : -1; + const int offset = !needs_patching ? field->offset() : -1; switch (code) { case Bytecodes::_getstatic: { // check for compile-time constants, i.e., initialized static final fields @@ -1509,7 +1505,7 @@ state_before = copy_state_for_exception(); } push(type, append(new LoadField(append(obj), offset, field, true, - state_before, is_loaded, is_initialized))); + state_before, needs_patching))); } break; } @@ -1518,7 +1514,7 @@ if (state_before == NULL) { state_before = copy_state_for_exception(); } - append(new StoreField(append(obj), offset, field, val, true, state_before, is_loaded, is_initialized)); + append(new StoreField(append(obj), offset, field, val, true, state_before, needs_patching)); } break; case Bytecodes::_getfield : @@ -1526,8 +1522,8 @@ if (state_before == NULL) { state_before = copy_state_for_exception(); } - LoadField* load = new LoadField(apop(), offset, field, false, state_before, is_loaded, true); - Value replacement = is_loaded ? _memory->load(load) : load; + LoadField* load = new LoadField(apop(), offset, field, false, state_before, needs_patching); + Value replacement = !needs_patching ? _memory->load(load) : load; if (replacement != load) { assert(replacement->is_linked() || !replacement->can_be_linked(), "should already by linked"); push(type, replacement); @@ -1542,8 +1538,8 @@ if (state_before == NULL) { state_before = copy_state_for_exception(); } - StoreField* store = new StoreField(apop(), offset, field, val, false, state_before, is_loaded, true); - if (is_loaded) store = _memory->store(store); + StoreField* store = new StoreField(apop(), offset, field, val, false, state_before, needs_patching); + if (!needs_patching) store = _memory->store(store); if (store != NULL) { append(store); } @@ -3308,22 +3304,23 @@ Value exception = append_with_bci(new ExceptionObject(), SynchronizationEntryBCI); assert(exception->is_pinned(), "must be"); + int bci = SynchronizationEntryBCI; if (compilation()->env()->dtrace_method_probes()) { - // Report exit from inline methods + // Report exit from inline methods. We don't have a stream here + // so pass an explicit bci of SynchronizationEntryBCI. Values* args = new Values(1); - args->push(append(new Constant(new ObjectConstant(method())))); - append(new RuntimeCall(voidType, "dtrace_method_exit", CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), args)); + args->push(append_with_bci(new Constant(new ObjectConstant(method())), bci)); + append_with_bci(new RuntimeCall(voidType, "dtrace_method_exit", CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), args), bci); } - int bci = SynchronizationEntryBCI; if (lock) { assert(state()->locks_size() > 0 && state()->lock_at(state()->locks_size() - 1) == lock, "lock is missing"); if (!lock->is_linked()) { - lock = append_with_bci(lock, -1); + lock = append_with_bci(lock, bci); } // exit the monitor in the context of the synchronized method - monitorexit(lock, SynchronizationEntryBCI); + monitorexit(lock, bci); // exit the context of the synchronized method if (!default_handler) {
--- a/src/share/vm/c1/c1_Instruction.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/c1/c1_Instruction.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -323,8 +323,6 @@ CanTrapFlag, DirectCompareFlag, IsEliminatedFlag, - IsInitializedFlag, - IsLoadedFlag, IsSafepointFlag, IsStaticFlag, IsStrictfpFlag, @@ -693,7 +691,7 @@ public: // creation AccessField(Value obj, int offset, ciField* field, bool is_static, - ValueStack* state_before, bool is_loaded, bool is_initialized) + ValueStack* state_before, bool needs_patching) : Instruction(as_ValueType(field->type()->basic_type()), state_before) , _obj(obj) , _offset(offset) @@ -701,16 +699,9 @@ , _explicit_null_check(NULL) { set_needs_null_check(!is_static); - set_flag(IsLoadedFlag, is_loaded); - set_flag(IsInitializedFlag, is_initialized); set_flag(IsStaticFlag, is_static); + set_flag(NeedsPatchingFlag, needs_patching); ASSERT_VALUES - if (!is_loaded || (PatchALot && !field->is_volatile())) { - // need to patch if the holder wasn't loaded or we're testing - // using PatchALot. Don't allow PatchALot for fields which are - // known to be volatile they aren't patchable. - set_flag(NeedsPatchingFlag, true); - } // pin of all instructions with memory access pin(); } @@ -721,11 +712,14 @@ ciField* field() const { return _field; } BasicType field_type() const { return _field->type()->basic_type(); } bool is_static() const { return check_flag(IsStaticFlag); } - bool is_loaded() const { return check_flag(IsLoadedFlag); } - bool is_initialized() const { return check_flag(IsInitializedFlag); } NullCheck* explicit_null_check() const { return _explicit_null_check; } bool needs_patching() const { return check_flag(NeedsPatchingFlag); } + // Unresolved getstatic and putstatic can cause initialization. + // Technically it occurs at the Constant that materializes the base + // of the static fields but it's simpler to model it here. + bool is_init_point() const { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); } + // manipulation // Under certain circumstances, if a previous NullCheck instruction @@ -745,15 +739,15 @@ public: // creation LoadField(Value obj, int offset, ciField* field, bool is_static, - ValueStack* state_before, bool is_loaded, bool is_initialized) - : AccessField(obj, offset, field, is_static, state_before, is_loaded, is_initialized) + ValueStack* state_before, bool needs_patching) + : AccessField(obj, offset, field, is_static, state_before, needs_patching) {} ciType* declared_type() const; ciType* exact_type() const; // generic - HASHING2(LoadField, is_loaded() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if not yet loaded or if volatile + HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if needs patching or if volatile }; @@ -764,8 +758,8 @@ public: // creation StoreField(Value obj, int offset, ciField* field, Value value, bool is_static, - ValueStack* state_before, bool is_loaded, bool is_initialized) - : AccessField(obj, offset, field, is_static, state_before, is_loaded, is_initialized) + ValueStack* state_before, bool needs_patching) + : AccessField(obj, offset, field, is_static, state_before, needs_patching) , _value(value) { set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
--- a/src/share/vm/c1/c1_LIR.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/c1/c1_LIR.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1156,7 +1156,7 @@ return is_invokedynamic() // An invokedynamic is always a MethodHandle call site. || - (method()->holder()->name() == ciSymbol::java_dyn_MethodHandle() && + (method()->holder()->name() == ciSymbol::java_lang_invoke_MethodHandle() && methodOopDesc::is_method_handle_invoke_name(method()->name()->sid())); }
--- a/src/share/vm/c1/c1_LIRGenerator.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/c1/c1_LIRGenerator.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1559,9 +1559,7 @@ (info ? new CodeEmitInfo(info) : NULL)); } - if (is_volatile) { - assert(!needs_patching && x->is_loaded(), - "how do we know it's volatile if it's not loaded"); + if (is_volatile && !needs_patching) { volatile_field_store(value.result(), address, info); } else { LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none; @@ -1627,9 +1625,7 @@ address = generate_address(object.result(), x->offset(), field_type); } - if (is_volatile) { - assert(!needs_patching && x->is_loaded(), - "how do we know it's volatile if it's not loaded"); + if (is_volatile && !needs_patching) { volatile_field_load(address, reg, info); } else { LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none; @@ -2516,7 +2512,7 @@ __ load(new LIR_Address(tmp, call_site_offset, T_OBJECT), tmp); // Load target MethodHandle from CallSite object. - __ load(new LIR_Address(tmp, java_dyn_CallSite::target_offset_in_bytes(), T_OBJECT), receiver); + __ load(new LIR_Address(tmp, java_lang_invoke_CallSite::target_offset_in_bytes(), T_OBJECT), receiver); __ call_dynamic(target, receiver, result_register, SharedRuntime::get_resolve_opt_virtual_call_stub(),
--- a/src/share/vm/c1/c1_LinearScan.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/c1/c1_LinearScan.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -2703,7 +2703,7 @@ assert(_fpu_stack_allocator != NULL, "must be present"); opr = _fpu_stack_allocator->to_fpu_stack(opr); - assert(opr->fpu_regnrLo() == opr->fpu_regnrHi(), "assumed in calculation (only fpu_regnrHi is used)"); + assert(opr->fpu_regnrLo() == opr->fpu_regnrHi(), "assumed in calculation (only fpu_regnrLo is used)"); #endif #ifdef SPARC assert(opr->fpu_regnrLo() == opr->fpu_regnrHi() + 1, "assumed in calculation (only fpu_regnrHi is used)"); @@ -2715,7 +2715,12 @@ assert(opr->fpu_regnrLo() == opr->fpu_regnrHi(), "assumed in calculation (only fpu_regnrHi is used)"); #endif +#ifdef VM_LITTLE_ENDIAN + VMReg rname_first = frame_map()->fpu_regname(opr->fpu_regnrLo()); +#else VMReg rname_first = frame_map()->fpu_regname(opr->fpu_regnrHi()); +#endif + #ifdef _LP64 first = new LocationValue(Location::new_reg_loc(Location::dbl, rname_first)); second = &_int_0_scope_value;
--- a/src/share/vm/c1/c1_Runtime1.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/c1/c1_Runtime1.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -426,10 +426,9 @@ // been deoptimized. If that is the case we return the deopt blob // unpack_with_exception entry instead. This makes life for the exception blob easier // because making that same check and diverting is painful from assembly language. -// - - JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* thread, oopDesc* ex, address pc, nmethod*& nm)) + // Reset method handle flag. + thread->set_is_method_handle_return(false); Handle exception(thread, ex); nm = CodeCache::find_nmethod(pc); @@ -480,11 +479,12 @@ return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls(); } - // ExceptionCache is used only for exceptions at call and not for implicit exceptions + // ExceptionCache is used only for exceptions at call sites and not for implicit exceptions if (guard_pages_enabled) { address fast_continuation = nm->handler_for_exception_and_pc(exception, pc); if (fast_continuation != NULL) { - if (fast_continuation == ExceptionCache::unwind_handler()) fast_continuation = NULL; + // Set flag if return address is a method handle call site. + thread->set_is_method_handle_return(nm->is_method_handle_return(pc)); return fast_continuation; } } @@ -522,14 +522,14 @@ thread->set_exception_pc(pc); // the exception cache is used only by non-implicit exceptions - if (continuation == NULL) { - nm->add_handler_for_exception_and_pc(exception, pc, ExceptionCache::unwind_handler()); - } else { + if (continuation != NULL) { nm->add_handler_for_exception_and_pc(exception, pc, continuation); } } thread->set_vm_result(exception()); + // Set flag if return address is a method handle call site. + thread->set_is_method_handle_return(nm->is_method_handle_return(pc)); if (TraceExceptions) { ttyLocker ttyl; @@ -542,20 +542,19 @@ JRT_END // Enter this method from compiled code only if there is a Java exception handler -// in the method handling the exception +// in the method handling the exception. // We are entering here from exception stub. We don't do a normal VM transition here. // We do it in a helper. This is so we can check to see if the nmethod we have just // searched for an exception handler has been deoptimized in the meantime. -address Runtime1::exception_handler_for_pc(JavaThread* thread) { +address Runtime1::exception_handler_for_pc(JavaThread* thread) { oop exception = thread->exception_oop(); address pc = thread->exception_pc(); // Still in Java mode - debug_only(ResetNoHandleMark rnhm); + DEBUG_ONLY(ResetNoHandleMark rnhm); nmethod* nm = NULL; address continuation = NULL; { // Enter VM mode by calling the helper - ResetNoHandleMark rnhm; continuation = exception_handler_for_pc_helper(thread, exception, pc, nm); } @@ -563,11 +562,11 @@ // Now check to see if the nmethod we were called from is now deoptimized. // If so we must return to the deopt blob and deoptimize the nmethod - if (nm != NULL && caller_is_deopted()) { continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls(); } + assert(continuation != NULL, "no handler found"); return continuation; }
--- a/src/share/vm/c1/c1_Runtime1.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/c1/c1_Runtime1.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -54,6 +54,7 @@ stub(new_multi_array) \ stub(handle_exception_nofpu) /* optimized version that does not preserve fpu registers */ \ stub(handle_exception) \ + stub(handle_exception_from_callee) \ stub(throw_array_store_exception) \ stub(throw_class_cast_exception) \ stub(throw_incompatible_class_change_error) \ @@ -116,11 +117,11 @@ static const char* _blob_names[]; // stub generation - static void generate_blob_for(BufferBlob* blob, StubID id); - static OopMapSet* generate_code_for(StubID id, StubAssembler* masm); + static void generate_blob_for(BufferBlob* blob, StubID id); + static OopMapSet* generate_code_for(StubID id, StubAssembler* sasm); static OopMapSet* generate_exception_throw(StubAssembler* sasm, address target, bool has_argument); - static void generate_handle_exception(StubAssembler *sasm, OopMapSet* oop_maps, OopMap* oop_map, bool ignore_fpu_registers = false); - static void generate_unwind_exception(StubAssembler *sasm); + static OopMapSet* generate_handle_exception(StubID id, StubAssembler* sasm); + static void generate_unwind_exception(StubAssembler *sasm); static OopMapSet* generate_patching(StubAssembler* sasm, address target); static OopMapSet* generate_stub_call(StubAssembler* sasm, Register result, address entry,
--- a/src/share/vm/c1/c1_ValueMap.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/c1/c1_ValueMap.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -141,7 +141,8 @@ // visitor functions void do_StoreField (StoreField* x) { - if (!x->is_initialized()) { + if (x->is_init_point()) { + // putstatic is an initialization point so treat it as a wide kill kill_memory(); } else { kill_field(x->field()); @@ -159,7 +160,8 @@ void do_Local (Local* x) { /* nothing to do */ } void do_Constant (Constant* x) { /* nothing to do */ } void do_LoadField (LoadField* x) { - if (!x->is_initialized()) { + if (x->is_init_point()) { + // getstatic is an initialization point so treat it as a wide kill kill_memory(); } }
--- a/src/share/vm/ci/ciCallSite.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/ci/ciCallSite.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,7 +34,7 @@ // Return the target MethodHandle of this CallSite. ciMethodHandle* ciCallSite::get_target() const { VM_ENTRY_MARK; - oop method_handle_oop = java_dyn_CallSite::target(get_oop()); + oop method_handle_oop = java_lang_invoke_CallSite::target(get_oop()); return CURRENT_ENV->get_object(method_handle_oop)->as_method_handle(); }
--- a/src/share/vm/ci/ciCallSite.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/ci/ciCallSite.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,7 +29,7 @@ // ciCallSite // -// The class represents a java.dyn.CallSite object. +// The class represents a java.lang.invoke.CallSite object. class ciCallSite : public ciInstance { public: ciCallSite(instanceHandle h_i) : ciInstance(h_i) {}
--- a/src/share/vm/ci/ciField.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/ci/ciField.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -177,7 +177,7 @@ // Never trust strangely unstable finals: System.out, etc. return false; // Even if general trusting is disabled, trust system-built closures in these packages. - if (holder->is_in_package("java/dyn") || holder->is_in_package("sun/dyn")) + if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke")) return true; return TrustFinalNonStaticFields; } @@ -191,8 +191,9 @@ // Check to see if the field is constant. if (_holder->is_initialized() && this->is_final()) { if (!this->is_static()) { - // A field can be constant if it's a final static field or if it's - // a final non-static field of a trusted class ({java,sun}.dyn). + // A field can be constant if it's a final static field or if + // it's a final non-static field of a trusted class (classes in + // java.lang.invoke and sun.invoke packages and subpackages). if (trust_final_non_static_fields(_holder)) { _is_constant = true; return;
--- a/src/share/vm/ci/ciMethod.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/ci/ciMethod.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -769,7 +769,7 @@ // signature-polymorphic MethodHandle methods, invokeExact or invokeGeneric. bool ciMethod::is_method_handle_invoke() const { if (!is_loaded()) { - bool flag = (holder()->name() == ciSymbol::java_dyn_MethodHandle() && + bool flag = (holder()->name() == ciSymbol::java_lang_invoke_MethodHandle() && methodOopDesc::is_method_handle_invoke_name(name()->sid())); return flag; }
--- a/src/share/vm/ci/ciMethodHandle.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/ci/ciMethodHandle.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,7 +30,7 @@ // ciMethodHandle // -// The class represents a java.dyn.MethodHandle object. +// The class represents a java.lang.invoke.MethodHandle object. class ciMethodHandle : public ciInstance { private: ciMethod* _callee;
--- a/src/share/vm/ci/ciObjectFactory.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/ci/ciObjectFactory.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -342,9 +342,9 @@ return new (arena()) ciMethodData(h_md); } else if (o->is_instance()) { instanceHandle h_i(THREAD, (instanceOop)o); - if (java_dyn_CallSite::is_instance(o)) + if (java_lang_invoke_CallSite::is_instance(o)) return new (arena()) ciCallSite(h_i); - else if (java_dyn_MethodHandle::is_instance(o)) + else if (java_lang_invoke_MethodHandle::is_instance(o)) return new (arena()) ciMethodHandle(h_i); else return new (arena()) ciInstance(h_i);
--- a/src/share/vm/ci/ciStreams.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/ci/ciStreams.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -380,7 +380,7 @@ bool ignore; // report as InvokeDynamic for invokedynamic, which is syntactically classless if (cur_bc() == Bytecodes::_invokedynamic) - return CURRENT_ENV->get_klass_by_name(_holder, ciSymbol::java_dyn_InvokeDynamic(), false); + return CURRENT_ENV->get_klass_by_name(_holder, ciSymbol::java_lang_invoke_InvokeDynamic(), false); return CURRENT_ENV->get_klass_by_index(cpool, get_method_holder_index(), ignore, _holder); }
--- a/src/share/vm/classfile/classFileParser.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/classFileParser.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -146,12 +146,14 @@ break; case JVM_CONSTANT_MethodHandle : case JVM_CONSTANT_MethodType : - if (!EnableMethodHandles || - _major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { + if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { classfile_parse_error( - (!EnableMethodHandles ? - "This JVM does not support constant tag %u in class file %s" : - "Class file version does not support constant tag %u in class file %s"), + "Class file version does not support constant tag %u in class file %s", + tag, CHECK); + } + if (!EnableMethodHandles) { + classfile_parse_error( + "This JVM does not support constant tag %u in class file %s", tag, CHECK); } if (tag == JVM_CONSTANT_MethodHandle) { @@ -170,12 +172,14 @@ case JVM_CONSTANT_InvokeDynamicTrans : // this tag appears only in old classfiles case JVM_CONSTANT_InvokeDynamic : { - if (!EnableInvokeDynamic || - _major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { + if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { classfile_parse_error( - (!EnableInvokeDynamic ? - "This JVM does not support constant tag %u in class file %s" : - "Class file version does not support constant tag %u in class file %s"), + "Class file version does not support constant tag %u in class file %s", + tag, CHECK); + } + if (!EnableInvokeDynamic) { + classfile_parse_error( + "This JVM does not support constant tag %u in class file %s", tag, CHECK); } cfs->guarantee_more(5, CHECK); // bsm_index, nt, tag/access_flags @@ -1616,8 +1620,13 @@ AccessFlags access_flags; if (name == vmSymbols::class_initializer_name()) { - // We ignore the access flags for a class initializer. (JVM Spec. p. 116) - flags = JVM_ACC_STATIC; + // We ignore the other access flags for a valid class initializer. + // (JVM Spec 2nd ed., chapter 4.6) + if (_major_version < 51) { // backward compatibility + flags = JVM_ACC_STATIC; + } else if ((flags & JVM_ACC_STATIC) == JVM_ACC_STATIC) { + flags &= JVM_ACC_STATIC | JVM_ACC_STRICT; + } } else { verify_legal_method_modifiers(flags, is_interface, name, CHECK_(nullHandle)); } @@ -2797,11 +2806,11 @@ // Force MethodHandle.vmentry to be an unmanaged pointer. // There is no way for a classfile to express this, so we must help it. -void ClassFileParser::java_dyn_MethodHandle_fix_pre(constantPoolHandle cp, +void ClassFileParser::java_lang_invoke_MethodHandle_fix_pre(constantPoolHandle cp, typeArrayHandle fields, FieldAllocationCount *fac_ptr, TRAPS) { - // Add fake fields for java.dyn.MethodHandle instances + // Add fake fields for java.lang.invoke.MethodHandle instances // // This is not particularly nice, but since there is no way to express // a native wordSize field in Java, we must do it at this level. @@ -2818,9 +2827,10 @@ } } + if (AllowTransitionalJSR292 && word_sig_index == 0) return; if (word_sig_index == 0) THROW_MSG(vmSymbols::java_lang_VirtualMachineError(), - "missing I or J signature (for vmentry) in java.dyn.MethodHandle"); + "missing I or J signature (for vmentry) in java.lang.invoke.MethodHandle"); // Find vmentry field and change the signature. bool found_vmentry = false; @@ -2857,9 +2867,10 @@ } } + if (AllowTransitionalJSR292 && !found_vmentry) return; if (!found_vmentry) THROW_MSG(vmSymbols::java_lang_VirtualMachineError(), - "missing vmentry byte field in java.dyn.MethodHandle"); + "missing vmentry byte field in java.lang.invoke.MethodHandle"); } @@ -3224,9 +3235,18 @@ java_lang_Class_fix_pre(&methods, &fac, CHECK_(nullHandle)); } - // adjust the vmentry field declaration in java.dyn.MethodHandle - if (EnableMethodHandles && class_name == vmSymbols::sun_dyn_MethodHandleImpl() && class_loader.is_null()) { - java_dyn_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); + // adjust the vmentry field declaration in java.lang.invoke.MethodHandle + if (EnableMethodHandles && class_name == vmSymbols::java_lang_invoke_MethodHandle() && class_loader.is_null()) { + java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); + } + if (AllowTransitionalJSR292 && + EnableMethodHandles && class_name == vmSymbols::java_dyn_MethodHandle() && class_loader.is_null()) { + java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); + } + if (AllowTransitionalJSR292 && + EnableMethodHandles && class_name == vmSymbols::sun_dyn_MethodHandleImpl() && class_loader.is_null()) { + // allow vmentry field in MethodHandleImpl also + java_lang_invoke_MethodHandle_fix_pre(cp, fields, &fac, CHECK_(nullHandle)); } // Add a fake "discovered" field if it is not present
--- a/src/share/vm/classfile/classFileParser.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/classFileParser.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -162,9 +162,9 @@ // Adjust the next_nonstatic_oop_offset to place the fake fields // before any Java fields. void java_lang_Class_fix_post(int* next_nonstatic_oop_offset); - // Adjust the field allocation counts for java.dyn.MethodHandle to add + // Adjust the field allocation counts for java.lang.invoke.MethodHandle to add // a fake address (void*) field. - void java_dyn_MethodHandle_fix_pre(constantPoolHandle cp, + void java_lang_invoke_MethodHandle_fix_pre(constantPoolHandle cp, typeArrayHandle fields, FieldAllocationCount *fac_ptr, TRAPS);
--- a/src/share/vm/classfile/classLoader.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/classLoader.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1332,7 +1332,7 @@ } if (_compile_the_world_counter >= CompileTheWorldStartAt) { - if (k.is_null() || (exception_occurred && !CompileTheWorldIgnoreInitErrors)) { + if (k.is_null() || exception_occurred) { // If something went wrong (e.g. ExceptionInInitializerError) we skip this class tty->print_cr("CompileTheWorld (%d) : Skipping %s", _compile_the_world_counter, buffer); } else {
--- a/src/share/vm/classfile/javaClasses.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/javaClasses.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -66,6 +66,28 @@ return ik->find_local_field(name_symbol, signature_symbol, fd); } +static bool find_hacked_field(instanceKlass* ik, + Symbol* name_symbol, Symbol* signature_symbol, + fieldDescriptor* fd, + bool allow_super = false) { + bool found = find_field(ik, name_symbol, signature_symbol, fd, allow_super); + if (!found && AllowTransitionalJSR292) { + Symbol* backup_sig = SystemDictionary::find_backup_signature(signature_symbol); + if (backup_sig != NULL) { + found = find_field(ik, name_symbol, backup_sig, fd, allow_super); + if (TraceMethodHandles) { + ResourceMark rm; + tty->print_cr("MethodHandles: %s.%s: backup for %s => %s%s", + ik->name()->as_C_string(), name_symbol->as_C_string(), + signature_symbol->as_C_string(), backup_sig->as_C_string(), + (found ? "" : " (NOT FOUND)")); + } + } + } + return found; +} +#define find_field find_hacked_field /* remove after AllowTransitionalJSR292 */ + // Helpful routine for computing field offsets at run time rather than hardcoding them static void compute_offset(int &dest_offset, @@ -2176,41 +2198,43 @@ } -// Support for java_dyn_MethodHandle - -int java_dyn_MethodHandle::_type_offset; -int java_dyn_MethodHandle::_vmtarget_offset; -int java_dyn_MethodHandle::_vmentry_offset; -int java_dyn_MethodHandle::_vmslots_offset; - -int sun_dyn_MemberName::_clazz_offset; -int sun_dyn_MemberName::_name_offset; -int sun_dyn_MemberName::_type_offset; -int sun_dyn_MemberName::_flags_offset; -int sun_dyn_MemberName::_vmtarget_offset; -int sun_dyn_MemberName::_vmindex_offset; - -int sun_dyn_DirectMethodHandle::_vmindex_offset; - -int sun_dyn_BoundMethodHandle::_argument_offset; -int sun_dyn_BoundMethodHandle::_vmargslot_offset; - -int sun_dyn_AdapterMethodHandle::_conversion_offset; - -void java_dyn_MethodHandle::compute_offsets() { +// Support for java_lang_invoke_MethodHandle + +int java_lang_invoke_MethodHandle::_type_offset; +int java_lang_invoke_MethodHandle::_vmtarget_offset; +int java_lang_invoke_MethodHandle::_vmentry_offset; +int java_lang_invoke_MethodHandle::_vmslots_offset; + +int java_lang_invoke_MemberName::_clazz_offset; +int java_lang_invoke_MemberName::_name_offset; +int java_lang_invoke_MemberName::_type_offset; +int java_lang_invoke_MemberName::_flags_offset; +int java_lang_invoke_MemberName::_vmtarget_offset; +int java_lang_invoke_MemberName::_vmindex_offset; + +int java_lang_invoke_DirectMethodHandle::_vmindex_offset; + +int java_lang_invoke_BoundMethodHandle::_argument_offset; +int java_lang_invoke_BoundMethodHandle::_vmargslot_offset; + +int java_lang_invoke_AdapterMethodHandle::_conversion_offset; + +void java_lang_invoke_MethodHandle::compute_offsets() { klassOop k = SystemDictionary::MethodHandle_klass(); if (k != NULL && EnableMethodHandles) { - compute_offset(_type_offset, k, vmSymbols::type_name(), vmSymbols::java_dyn_MethodType_signature(), true); - compute_offset(_vmtarget_offset, k, vmSymbols::vmtarget_name(), vmSymbols::object_signature(), true); - compute_offset(_vmentry_offset, k, vmSymbols::vmentry_name(), vmSymbols::machine_word_signature(), true); + bool allow_super = false; + if (AllowTransitionalJSR292) allow_super = true; // temporary, to access java.dyn.MethodHandleImpl + compute_offset(_type_offset, k, vmSymbols::type_name(), vmSymbols::java_lang_invoke_MethodType_signature(), allow_super); + compute_offset(_vmtarget_offset, k, vmSymbols::vmtarget_name(), vmSymbols::object_signature(), allow_super); + compute_offset(_vmentry_offset, k, vmSymbols::vmentry_name(), vmSymbols::machine_word_signature(), allow_super); // Note: MH.vmslots (if it is present) is a hoisted copy of MH.type.form.vmslots. // It is optional pending experiments to keep or toss. - compute_optional_offset(_vmslots_offset, k, vmSymbols::vmslots_name(), vmSymbols::int_signature(), true); + compute_optional_offset(_vmslots_offset, k, vmSymbols::vmslots_name(), vmSymbols::int_signature(), allow_super); } } -void sun_dyn_MemberName::compute_offsets() { +void java_lang_invoke_MemberName::compute_offsets() { klassOop k = SystemDictionary::MemberName_klass(); if (k != NULL && EnableMethodHandles) { compute_offset(_clazz_offset, k, vmSymbols::clazz_name(), vmSymbols::class_signature()); @@ -2222,14 +2246,14 @@ } } -void sun_dyn_DirectMethodHandle::compute_offsets() { +void java_lang_invoke_DirectMethodHandle::compute_offsets() { klassOop k = SystemDictionary::DirectMethodHandle_klass(); if (k != NULL && EnableMethodHandles) { compute_offset(_vmindex_offset, k, vmSymbols::vmindex_name(), vmSymbols::int_signature(), true); } } -void sun_dyn_BoundMethodHandle::compute_offsets() { +void java_lang_invoke_BoundMethodHandle::compute_offsets() { klassOop k = SystemDictionary::BoundMethodHandle_klass(); if (k != NULL && EnableMethodHandles) { compute_offset(_vmargslot_offset, k, vmSymbols::vmargslot_name(), vmSymbols::int_signature(), true); @@ -2237,22 +2261,22 @@ } } -void sun_dyn_AdapterMethodHandle::compute_offsets() { +void java_lang_invoke_AdapterMethodHandle::compute_offsets() { klassOop k = SystemDictionary::AdapterMethodHandle_klass(); if (k != NULL && EnableMethodHandles) { compute_offset(_conversion_offset, k, vmSymbols::conversion_name(), vmSymbols::int_signature(), true); } } -oop java_dyn_MethodHandle::type(oop mh) { +oop java_lang_invoke_MethodHandle::type(oop mh) { return mh->obj_field(_type_offset); } -void java_dyn_MethodHandle::set_type(oop mh, oop mtype) { +void java_lang_invoke_MethodHandle::set_type(oop mh, oop mtype) { mh->obj_field_put(_type_offset, mtype); } -int java_dyn_MethodHandle::vmslots(oop mh) { +int java_lang_invoke_MethodHandle::vmslots(oop mh) { int vmslots_offset = _vmslots_offset; if (vmslots_offset != 0) { #ifdef ASSERT @@ -2267,7 +2291,7 @@ } // if MH.vmslots exists, hoist into it the value of type.form.vmslots -void java_dyn_MethodHandle::init_vmslots(oop mh) { +void java_lang_invoke_MethodHandle::init_vmslots(oop mh) { int vmslots_offset = _vmslots_offset; if (vmslots_offset != 0) { mh->int_field_put(vmslots_offset, compute_vmslots(mh)); @@ -2276,20 +2300,20 @@ // fetch type.form.vmslots, which is the number of JVM stack slots // required to carry the arguments of this MH -int java_dyn_MethodHandle::compute_vmslots(oop mh) { +int java_lang_invoke_MethodHandle::compute_vmslots(oop mh) { oop mtype = type(mh); if (mtype == NULL) return 0; // Java code would get NPE - oop form = java_dyn_MethodType::form(mtype); + oop form = java_lang_invoke_MethodType::form(mtype); if (form == NULL) return 0; // Java code would get NPE - return java_dyn_MethodTypeForm::vmslots(form); + return java_lang_invoke_MethodTypeForm::vmslots(form); } // fetch the low-level entry point for this mh -MethodHandleEntry* java_dyn_MethodHandle::vmentry(oop mh) { +MethodHandleEntry* java_lang_invoke_MethodHandle::vmentry(oop mh) { return (MethodHandleEntry*) mh->address_field(_vmentry_offset); } -void java_dyn_MethodHandle::set_vmentry(oop mh, MethodHandleEntry* me) { +void java_lang_invoke_MethodHandle::set_vmentry(oop mh, MethodHandleEntry* me) { assert(_vmentry_offset != 0, "must be present"); // This is always the final step that initializes a valid method handle: @@ -2303,123 +2327,123 @@ /// MemberName accessors -oop sun_dyn_MemberName::clazz(oop mname) { +oop java_lang_invoke_MemberName::clazz(oop mname) { assert(is_instance(mname), "wrong type"); return mname->obj_field(_clazz_offset); } -void sun_dyn_MemberName::set_clazz(oop mname, oop clazz) { +void java_lang_invoke_MemberName::set_clazz(oop mname, oop clazz) { assert(is_instance(mname), "wrong type"); mname->obj_field_put(_clazz_offset, clazz); } -oop sun_dyn_MemberName::name(oop mname) { +oop java_lang_invoke_MemberName::name(oop mname) { assert(is_instance(mname), "wrong type"); return mname->obj_field(_name_offset); } -void sun_dyn_MemberName::set_name(oop mname, oop name) { +void java_lang_invoke_MemberName::set_name(oop mname, oop name) { assert(is_instance(mname), "wrong type"); mname->obj_field_put(_name_offset, name); } -oop sun_dyn_MemberName::type(oop mname) { +oop java_lang_invoke_MemberName::type(oop mname) { assert(is_instance(mname), "wrong type"); return mname->obj_field(_type_offset); } -void sun_dyn_MemberName::set_type(oop mname, oop type) { +void java_lang_invoke_MemberName::set_type(oop mname, oop type) { assert(is_instance(mname), "wrong type"); mname->obj_field_put(_type_offset, type); } -int sun_dyn_MemberName::flags(oop mname) { +int java_lang_invoke_MemberName::flags(oop mname) { assert(is_instance(mname), "wrong type"); return mname->int_field(_flags_offset); } -void sun_dyn_MemberName::set_flags(oop mname, int flags) { +void java_lang_invoke_MemberName::set_flags(oop mname, int flags) { assert(is_instance(mname), "wrong type"); mname->int_field_put(_flags_offset, flags); } -oop sun_dyn_MemberName::vmtarget(oop mname) { +oop java_lang_invoke_MemberName::vmtarget(oop mname) { assert(is_instance(mname), "wrong type"); return mname->obj_field(_vmtarget_offset); } -void sun_dyn_MemberName::set_vmtarget(oop mname, oop ref) { +void java_lang_invoke_MemberName::set_vmtarget(oop mname, oop ref) { assert(is_instance(mname), "wrong type"); mname->obj_field_put(_vmtarget_offset, ref); } -int sun_dyn_MemberName::vmindex(oop mname) { +int java_lang_invoke_MemberName::vmindex(oop mname) { assert(is_instance(mname), "wrong type"); return mname->int_field(_vmindex_offset); } -void sun_dyn_MemberName::set_vmindex(oop mname, int index) { +void java_lang_invoke_MemberName::set_vmindex(oop mname, int index) { assert(is_instance(mname), "wrong type"); mname->int_field_put(_vmindex_offset, index); } -oop java_dyn_MethodHandle::vmtarget(oop mh) { +oop java_lang_invoke_MethodHandle::vmtarget(oop mh) { assert(is_instance(mh), "MH only"); return mh->obj_field(_vmtarget_offset); } -void java_dyn_MethodHandle::set_vmtarget(oop mh, oop ref) { +void java_lang_invoke_MethodHandle::set_vmtarget(oop mh, oop ref) { assert(is_instance(mh), "MH only"); mh->obj_field_put(_vmtarget_offset, ref); } -int sun_dyn_DirectMethodHandle::vmindex(oop mh) { +int java_lang_invoke_DirectMethodHandle::vmindex(oop mh) { assert(is_instance(mh), "DMH only"); return mh->int_field(_vmindex_offset); } -void sun_dyn_DirectMethodHandle::set_vmindex(oop mh, int index) { +void java_lang_invoke_DirectMethodHandle::set_vmindex(oop mh, int index) { assert(is_instance(mh), "DMH only"); mh->int_field_put(_vmindex_offset, index); } -int sun_dyn_BoundMethodHandle::vmargslot(oop mh) { +int java_lang_invoke_BoundMethodHandle::vmargslot(oop mh) { assert(is_instance(mh), "BMH only"); return mh->int_field(_vmargslot_offset); } -oop sun_dyn_BoundMethodHandle::argument(oop mh) { +oop java_lang_invoke_BoundMethodHandle::argument(oop mh) { assert(is_instance(mh), "BMH only"); return mh->obj_field(_argument_offset); } -int sun_dyn_AdapterMethodHandle::conversion(oop mh) { +int java_lang_invoke_AdapterMethodHandle::conversion(oop mh) { assert(is_instance(mh), "AMH only"); return mh->int_field(_conversion_offset); } -void sun_dyn_AdapterMethodHandle::set_conversion(oop mh, int conv) { +void java_lang_invoke_AdapterMethodHandle::set_conversion(oop mh, int conv) { assert(is_instance(mh), "AMH only"); mh->int_field_put(_conversion_offset, conv); } -// Support for java_dyn_MethodType - -int java_dyn_MethodType::_rtype_offset; -int java_dyn_MethodType::_ptypes_offset; -int java_dyn_MethodType::_form_offset; - -void java_dyn_MethodType::compute_offsets() { +// Support for java_lang_invoke_MethodType + +int java_lang_invoke_MethodType::_rtype_offset; +int java_lang_invoke_MethodType::_ptypes_offset; +int java_lang_invoke_MethodType::_form_offset; + +void java_lang_invoke_MethodType::compute_offsets() { klassOop k = SystemDictionary::MethodType_klass(); if (k != NULL) { compute_offset(_rtype_offset, k, vmSymbols::rtype_name(), vmSymbols::class_signature()); compute_offset(_ptypes_offset, k, vmSymbols::ptypes_name(), vmSymbols::class_array_signature()); - compute_offset(_form_offset, k, vmSymbols::form_name(), vmSymbols::java_dyn_MethodTypeForm_signature()); + compute_offset(_form_offset, k, vmSymbols::form_name(), vmSymbols::java_lang_invoke_MethodTypeForm_signature()); } } -void java_dyn_MethodType::print_signature(oop mt, outputStream* st) { +void java_lang_invoke_MethodType::print_signature(oop mt, outputStream* st) { st->print("("); objArrayOop pts = ptypes(mt); for (int i = 0, limit = pts->length(); i < limit; i++) { @@ -2429,7 +2453,7 @@ java_lang_Class::print_signature(rtype(mt), st); } -Symbol* java_dyn_MethodType::as_signature(oop mt, bool intern_if_not_found, TRAPS) { +Symbol* java_lang_invoke_MethodType::as_signature(oop mt, bool intern_if_not_found, TRAPS) { ResourceMark rm; stringStream buffer(128); print_signature(mt, &buffer); @@ -2444,103 +2468,83 @@ return name; } -oop java_dyn_MethodType::rtype(oop mt) { +oop java_lang_invoke_MethodType::rtype(oop mt) { assert(is_instance(mt), "must be a MethodType"); return mt->obj_field(_rtype_offset); } -objArrayOop java_dyn_MethodType::ptypes(oop mt) { +objArrayOop java_lang_invoke_MethodType::ptypes(oop mt) { assert(is_instance(mt), "must be a MethodType"); return (objArrayOop) mt->obj_field(_ptypes_offset); } -oop java_dyn_MethodType::form(oop mt) { +oop java_lang_invoke_MethodType::form(oop mt) { assert(is_instance(mt), "must be a MethodType"); return mt->obj_field(_form_offset); } -oop java_dyn_MethodType::ptype(oop mt, int idx) { +oop java_lang_invoke_MethodType::ptype(oop mt, int idx) { return ptypes(mt)->obj_at(idx); } -int java_dyn_MethodType::ptype_count(oop mt) { +int java_lang_invoke_MethodType::ptype_count(oop mt) { return ptypes(mt)->length(); } -// Support for java_dyn_MethodTypeForm - -int java_dyn_MethodTypeForm::_vmslots_offset; -int java_dyn_MethodTypeForm::_erasedType_offset; -int java_dyn_MethodTypeForm::_genericInvoker_offset; - -void java_dyn_MethodTypeForm::compute_offsets() { +// Support for java_lang_invoke_MethodTypeForm + +int java_lang_invoke_MethodTypeForm::_vmslots_offset; +int java_lang_invoke_MethodTypeForm::_erasedType_offset; +int java_lang_invoke_MethodTypeForm::_genericInvoker_offset; + +void java_lang_invoke_MethodTypeForm::compute_offsets() { klassOop k = SystemDictionary::MethodTypeForm_klass(); if (k != NULL) { compute_optional_offset(_vmslots_offset, k, vmSymbols::vmslots_name(), vmSymbols::int_signature(), true); - compute_optional_offset(_erasedType_offset, k, vmSymbols::erasedType_name(), vmSymbols::java_dyn_MethodType_signature(), true); - compute_optional_offset(_genericInvoker_offset, k, vmSymbols::genericInvoker_name(), vmSymbols::java_dyn_MethodHandle_signature(), true); + compute_optional_offset(_erasedType_offset, k, vmSymbols::erasedType_name(), vmSymbols::java_lang_invoke_MethodType_signature(), true); + compute_optional_offset(_genericInvoker_offset, k, vmSymbols::genericInvoker_name(), vmSymbols::java_lang_invoke_MethodHandle_signature(), true); if (_genericInvoker_offset == 0) _genericInvoker_offset = -1; // set to explicit "empty" value } } -int java_dyn_MethodTypeForm::vmslots(oop mtform) { +int java_lang_invoke_MethodTypeForm::vmslots(oop mtform) { assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only"); return mtform->int_field(_vmslots_offset); } -oop java_dyn_MethodTypeForm::erasedType(oop mtform) { +oop java_lang_invoke_MethodTypeForm::erasedType(oop mtform) { assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only"); return mtform->obj_field(_erasedType_offset); } -oop java_dyn_MethodTypeForm::genericInvoker(oop mtform) { +oop java_lang_invoke_MethodTypeForm::genericInvoker(oop mtform) { assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only"); return mtform->obj_field(_genericInvoker_offset); } -// Support for java_dyn_CallSite - -int java_dyn_CallSite::_target_offset; -int java_dyn_CallSite::_caller_method_offset; -int java_dyn_CallSite::_caller_bci_offset; - -void java_dyn_CallSite::compute_offsets() { +// Support for java_lang_invoke_CallSite + +int java_lang_invoke_CallSite::_target_offset; + +void java_lang_invoke_CallSite::compute_offsets() { if (!EnableInvokeDynamic) return; klassOop k = SystemDictionary::CallSite_klass(); if (k != NULL) { - compute_offset(_target_offset, k, vmSymbols::target_name(), vmSymbols::java_dyn_MethodHandle_signature()); - compute_offset(_caller_method_offset, k, vmSymbols::vmmethod_name(), vmSymbols::sun_dyn_MemberName_signature()); - compute_offset(_caller_bci_offset, k, vmSymbols::vmindex_name(), vmSymbols::int_signature()); + compute_offset(_target_offset, k, vmSymbols::target_name(), vmSymbols::java_lang_invoke_MethodHandle_signature()); } } -oop java_dyn_CallSite::target(oop site) { +oop java_lang_invoke_CallSite::target(oop site) { return site->obj_field(_target_offset); } -void java_dyn_CallSite::set_target(oop site, oop target) { +void java_lang_invoke_CallSite::set_target(oop site, oop target) { site->obj_field_put(_target_offset, target); } -oop java_dyn_CallSite::caller_method(oop site) { - return site->obj_field(_caller_method_offset); -} - -void java_dyn_CallSite::set_caller_method(oop site, oop ref) { - site->obj_field_put(_caller_method_offset, ref); -} - -jint java_dyn_CallSite::caller_bci(oop site) { - return site->int_field(_caller_bci_offset); -} - -void java_dyn_CallSite::set_caller_bci(oop site, jint bci) { - site->int_field_put(_caller_bci_offset, bci); -} - // Support for java_security_AccessControlContext @@ -2877,16 +2881,16 @@ java_lang_Thread::compute_offsets(); java_lang_ThreadGroup::compute_offsets(); if (EnableMethodHandles) { - java_dyn_MethodHandle::compute_offsets(); - sun_dyn_MemberName::compute_offsets(); - sun_dyn_DirectMethodHandle::compute_offsets(); - sun_dyn_BoundMethodHandle::compute_offsets(); - sun_dyn_AdapterMethodHandle::compute_offsets(); - java_dyn_MethodType::compute_offsets(); - java_dyn_MethodTypeForm::compute_offsets(); + java_lang_invoke_MethodHandle::compute_offsets(); + java_lang_invoke_MemberName::compute_offsets(); + java_lang_invoke_DirectMethodHandle::compute_offsets(); + java_lang_invoke_BoundMethodHandle::compute_offsets(); + java_lang_invoke_AdapterMethodHandle::compute_offsets(); + java_lang_invoke_MethodType::compute_offsets(); + java_lang_invoke_MethodTypeForm::compute_offsets(); } if (EnableInvokeDynamic) { - java_dyn_CallSite::compute_offsets(); + java_lang_invoke_CallSite::compute_offsets(); } java_security_AccessControlContext::compute_offsets(); // Initialize reflection classes. The layouts of these classes
--- a/src/share/vm/classfile/javaClasses.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/javaClasses.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -794,11 +794,11 @@ }; -// Interface to java.dyn.MethodHandle objects +// Interface to java.lang.invoke.MethodHandle objects class MethodHandleEntry; -class java_dyn_MethodHandle: AllStatic { +class java_lang_invoke_MethodHandle: AllStatic { friend class JavaClasses; private: @@ -839,7 +839,7 @@ static int vmslots_offset_in_bytes() { return _vmslots_offset; } }; -class sun_dyn_DirectMethodHandle: public java_dyn_MethodHandle { +class java_lang_invoke_DirectMethodHandle: public java_lang_invoke_MethodHandle { friend class JavaClasses; private: @@ -864,7 +864,7 @@ static int vmindex_offset_in_bytes() { return _vmindex_offset; } }; -class sun_dyn_BoundMethodHandle: public java_dyn_MethodHandle { +class java_lang_invoke_BoundMethodHandle: public java_lang_invoke_MethodHandle { friend class JavaClasses; private: @@ -891,7 +891,7 @@ static int vmargslot_offset_in_bytes() { return _vmargslot_offset; } }; -class sun_dyn_AdapterMethodHandle: public sun_dyn_BoundMethodHandle { +class java_lang_invoke_AdapterMethodHandle: public java_lang_invoke_BoundMethodHandle { friend class JavaClasses; private: @@ -942,14 +942,14 @@ }; -// Interface to sun.dyn.MemberName objects +// Interface to java.lang.invoke.MemberName objects // (These are a private interface for Java code to query the class hierarchy.) -class sun_dyn_MemberName: AllStatic { +class java_lang_invoke_MemberName: AllStatic { friend class JavaClasses; private: - // From java.dyn.MemberName: + // From java.lang.invoke.MemberName: // private Class<?> clazz; // class in which the method is defined // private String name; // may be null if not yet materialized // private Object type; // may be null if not yet materialized @@ -1018,9 +1018,9 @@ }; -// Interface to java.dyn.MethodType objects +// Interface to java.lang.invoke.MethodType objects -class java_dyn_MethodType: AllStatic { +class java_lang_invoke_MethodType: AllStatic { friend class JavaClasses; private: @@ -1052,7 +1052,7 @@ static int form_offset_in_bytes() { return _form_offset; } }; -class java_dyn_MethodTypeForm: AllStatic { +class java_lang_invoke_MethodTypeForm: AllStatic { friend class JavaClasses; private: @@ -1075,9 +1075,9 @@ }; -// Interface to java.dyn.CallSite objects +// Interface to java.lang.invoke.CallSite objects -class java_dyn_CallSite: AllStatic { +class java_lang_invoke_CallSite: AllStatic { friend class JavaClasses; private:
--- a/src/share/vm/classfile/symbolTable.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/symbolTable.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -88,7 +88,7 @@ void SymbolTable::unlink() { int removed = 0; int total = 0; - int memory_total = 0; + size_t memory_total = 0; for (int i = 0; i < the_table()->table_size(); ++i) { for (HashtableEntry<Symbol*>** p = the_table()->bucket_addr(i); *p != NULL; ) { HashtableEntry<Symbol*>* entry = *p; @@ -112,8 +112,10 @@ } symbols_removed += removed; symbols_counted += total; - if (PrintGCDetails) { - gclog_or_tty->print(" [Symbols=%d size=%dK] ", total, + // Exclude printing for normal PrintGCDetails because people parse + // this output. + if (PrintGCDetails && Verbose && WizardMode) { + gclog_or_tty->print(" [Symbols=%d size=" SIZE_FORMAT "K] ", total, (memory_total*HeapWordSize)/1024); } }
--- a/src/share/vm/classfile/systemDictionary.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/systemDictionary.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1887,27 +1887,99 @@ 0 }; +Symbol* SystemDictionary::find_backup_symbol(Symbol* symbol, + const char* from_prefix, + const char* to_prefix) { + assert(AllowTransitionalJSR292, ""); // delete this subroutine + Symbol* backup_symbol = NULL; + size_t from_len = strlen(from_prefix); + if (strncmp((const char*) symbol->base(), from_prefix, from_len) != 0) + return NULL; + char buf[100]; + size_t to_len = strlen(to_prefix); + size_t tail_len = symbol->utf8_length() - from_len; + size_t new_len = to_len + tail_len; + guarantee(new_len < sizeof(buf), "buf too small"); + memcpy(buf, to_prefix, to_len); + memcpy(buf + to_len, symbol->base() + from_len, tail_len); + buf[new_len] = '\0'; + vmSymbols::SID backup_sid = vmSymbols::find_sid(buf); + if (backup_sid != vmSymbols::NO_SID) { + backup_symbol = vmSymbols::symbol_at(backup_sid); + } + return backup_symbol; +} + +Symbol* SystemDictionary::find_backup_class_name(Symbol* symbol) { + assert(AllowTransitionalJSR292, ""); // delete this subroutine + if (symbol == NULL) return NULL; + Symbol* backup_symbol = find_backup_symbol(symbol, "java/lang/invoke/", "java/dyn/"); // AllowTransitionalJSR292 ONLY + if (backup_symbol == NULL) + backup_symbol = find_backup_symbol(symbol, "java/dyn/", "sun/dyn/"); // AllowTransitionalJSR292 ONLY + return backup_symbol; +} + +Symbol* SystemDictionary::find_backup_signature(Symbol* symbol) { + assert(AllowTransitionalJSR292, ""); // delete this subroutine + if (symbol == NULL) return NULL; + return find_backup_symbol(symbol, "Ljava/lang/invoke/", "Ljava/dyn/"); +} + bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) { assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); int info = wk_init_info[id - FIRST_WKID]; int sid = (info >> CEIL_LG_OPTION_LIMIT); Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid); klassOop* klassp = &_well_known_klasses[id]; - bool must_load = (init_opt < SystemDictionary::Opt); - bool try_load = true; + bool pre_load = (init_opt < SystemDictionary::Opt); + bool try_load = true; if (init_opt == SystemDictionary::Opt_Kernel) { #ifndef KERNEL try_load = false; #endif //KERNEL } - if ((*klassp) == NULL && try_load) { + Symbol* backup_symbol = NULL; // symbol to try if the current symbol fails + if (init_opt == SystemDictionary::Pre_JSR292) { + if (!EnableMethodHandles) try_load = false; // do not bother to load such classes + if (AllowTransitionalJSR292) { + backup_symbol = find_backup_class_name(symbol); + if (try_load && PreferTransitionalJSR292) { + while (backup_symbol != NULL) { + (*klassp) = resolve_or_null(backup_symbol, CHECK_0); // try backup early + if (TraceMethodHandles) { + ResourceMark rm; + tty->print_cr("MethodHandles: try backup first for %s => %s (%s)", + symbol->as_C_string(), backup_symbol->as_C_string(), + ((*klassp) == NULL) ? "no such class" : "backup load succeeded"); + } + if ((*klassp) != NULL) return true; + backup_symbol = find_backup_class_name(backup_symbol); // find next backup + } + } + } + } + if ((*klassp) != NULL) return true; + if (!try_load) return false; + while (symbol != NULL) { + bool must_load = (pre_load && (backup_symbol == NULL)); if (must_load) { (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class } else { (*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass } + if ((*klassp) != NULL) return true; + // Go around again. Example of long backup sequence: + // java.lang.invoke.MemberName, java.dyn.MemberName, sun.dyn.MemberName, ONLY if AllowTransitionalJSR292 + if (TraceMethodHandles && (backup_symbol != NULL)) { + ResourceMark rm; + tty->print_cr("MethodHandles: backup for %s => %s", + symbol->as_C_string(), backup_symbol->as_C_string()); + } + symbol = backup_symbol; + if (AllowTransitionalJSR292) + backup_symbol = find_backup_class_name(symbol); } - return ((*klassp) != NULL); + return false; } void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) { @@ -2348,6 +2420,8 @@ if (THREAD->is_Compiler_thread()) return NULL; // do not attempt from within compiler bool for_invokeGeneric = (name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name)); + if (AllowInvokeForInvokeGeneric && name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name)) + for_invokeGeneric = true; bool found_on_bcp = false; Handle mt = find_method_handle_type(signature, accessing_klass, for_invokeGeneric, @@ -2376,7 +2450,7 @@ } } -// Ask Java code to find or construct a java.dyn.MethodType for the given +// Ask Java code to find or construct a java.lang.invoke.MethodType for the given // signature, as interpreted relative to the given class loader. // Because of class loader constraints, all method handle usage must be // consistent with this loader. @@ -2430,25 +2504,33 @@ } assert(arg == npts, ""); - // call sun.dyn.MethodHandleNatives::findMethodType(Class rt, Class[] pts) -> MethodType + // call java.lang.invoke.MethodHandleNatives::findMethodType(Class rt, Class[] pts) -> MethodType JavaCallArguments args(Handle(THREAD, rt())); args.push_oop(pts()); JavaValue result(T_OBJECT); + Symbol* findMethodHandleType_signature = vmSymbols::findMethodHandleType_signature(); + if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodType_klass()->name() == vmSymbols::java_dyn_MethodType()) { + findMethodHandleType_signature = vmSymbols::findMethodHandleType_TRANS_signature(); + } JavaCalls::call_static(&result, SystemDictionary::MethodHandleNatives_klass(), vmSymbols::findMethodHandleType_name(), - vmSymbols::findMethodHandleType_signature(), + findMethodHandleType_signature, &args, CHECK_(empty)); Handle method_type(THREAD, (oop) result.get_jobject()); if (for_invokeGeneric) { - // call sun.dyn.MethodHandleNatives::notifyGenericMethodType(MethodType) -> void + // call java.lang.invoke.MethodHandleNatives::notifyGenericMethodType(MethodType) -> void JavaCallArguments args(Handle(THREAD, method_type())); JavaValue no_result(T_VOID); + Symbol* notifyGenericMethodType_signature = vmSymbols::notifyGenericMethodType_signature(); + if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodType_klass()->name() == vmSymbols::java_dyn_MethodType()) { + notifyGenericMethodType_signature = vmSymbols::notifyGenericMethodType_TRANS_signature(); + } JavaCalls::call_static(&no_result, SystemDictionary::MethodHandleNatives_klass(), vmSymbols::notifyGenericMethodType_name(), - vmSymbols::notifyGenericMethodType_signature(), + notifyGenericMethodType_signature, &args, THREAD); if (HAS_PENDING_EXCEPTION) { // If the notification fails, just kill it. @@ -2489,7 +2571,7 @@ THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad signature", empty); } - // call sun.dyn.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle + // call java.lang.invoke.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle JavaCallArguments args; args.push_oop(caller->java_mirror()); // the referring class args.push_int(ref_kind); @@ -2497,15 +2579,19 @@ args.push_oop(name()); args.push_oop(type()); JavaValue result(T_OBJECT); + Symbol* linkMethodHandleConstant_signature = vmSymbols::linkMethodHandleConstant_signature(); + if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandle_klass()->name() == vmSymbols::java_dyn_MethodHandle()) { + linkMethodHandleConstant_signature = vmSymbols::linkMethodHandleConstant_TRANS_signature(); + } JavaCalls::call_static(&result, SystemDictionary::MethodHandleNatives_klass(), vmSymbols::linkMethodHandleConstant_name(), - vmSymbols::linkMethodHandleConstant_signature(), + linkMethodHandleConstant_signature, &args, CHECK_(empty)); return Handle(THREAD, (oop) result.get_jobject()); } -// Ask Java code to find or construct a java.dyn.CallSite for the given +// Ask Java code to find or construct a java.lang.invoke.CallSite for the given // name and signature, as interpreted relative to the given class loader. Handle SystemDictionary::make_dynamic_call_site(Handle bootstrap_method, Symbol* name, @@ -2516,13 +2602,13 @@ TRAPS) { Handle empty; guarantee(bootstrap_method.not_null() && - java_dyn_MethodHandle::is_instance(bootstrap_method()), + java_lang_invoke_MethodHandle::is_instance(bootstrap_method()), "caller must supply a valid BSM"); Handle caller_mname = MethodHandles::new_MemberName(CHECK_(empty)); MethodHandles::init_MemberName(caller_mname(), caller_method()); - // call sun.dyn.MethodHandleNatives::makeDynamicCallSite(bootm, name, mtype, info, caller_mname, caller_pos) + // call java.lang.invoke.MethodHandleNatives::makeDynamicCallSite(bootm, name, mtype, info, caller_mname, caller_pos) oop name_str_oop = StringTable::intern(name, CHECK_(empty)); // not a handle! JavaCallArguments args(Handle(THREAD, bootstrap_method())); args.push_oop(name_str_oop); @@ -2531,14 +2617,21 @@ args.push_oop(caller_mname()); args.push_int(caller_bci); JavaValue result(T_OBJECT); + Symbol* makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_signature(); + if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandleNatives_klass()->name() == vmSymbols::sun_dyn_MethodHandleNatives()) { + makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_TRANS_signature(); + } + if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandleNatives_klass()->name() == vmSymbols::java_dyn_MethodHandleNatives()) { + makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_TRANS2_signature(); + } JavaCalls::call_static(&result, SystemDictionary::MethodHandleNatives_klass(), vmSymbols::makeDynamicCallSite_name(), - vmSymbols::makeDynamicCallSite_signature(), + makeDynamicCallSite_signature, &args, CHECK_(empty)); oop call_site_oop = (oop) result.get_jobject(); assert(call_site_oop->is_oop() - /*&& java_dyn_CallSite::is_instance(call_site_oop)*/, "must be sane"); + /*&& java_lang_invoke_CallSite::is_instance(call_site_oop)*/, "must be sane"); if (TraceMethodHandles) { #ifndef PRODUCT tty->print_cr("Linked invokedynamic bci=%d site="INTPTR_FORMAT":", caller_bci, call_site_oop);
--- a/src/share/vm/classfile/systemDictionary.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/systemDictionary.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -144,18 +144,18 @@ template(reflect_UnsafeStaticFieldAccessorImpl_klass, sun_reflect_UnsafeStaticFieldAccessorImpl, Opt_Only_JDK15) \ \ /* support for dynamic typing; it's OK if these are NULL in earlier JDKs */ \ - template(MethodHandle_klass, java_dyn_MethodHandle, Opt) \ - template(MemberName_klass, sun_dyn_MemberName, Opt) \ - template(MethodHandleImpl_klass, sun_dyn_MethodHandleImpl, Opt) \ - template(MethodHandleNatives_klass, sun_dyn_MethodHandleNatives, Opt) \ - template(AdapterMethodHandle_klass, sun_dyn_AdapterMethodHandle, Opt) \ - template(BoundMethodHandle_klass, sun_dyn_BoundMethodHandle, Opt) \ - template(DirectMethodHandle_klass, sun_dyn_DirectMethodHandle, Opt) \ - template(MethodType_klass, java_dyn_MethodType, Opt) \ - template(MethodTypeForm_klass, java_dyn_MethodTypeForm, Opt) \ - template(WrongMethodTypeException_klass, java_dyn_WrongMethodTypeException, Opt) \ - template(Linkage_klass, java_dyn_Linkage, Opt) \ - template(CallSite_klass, java_dyn_CallSite, Opt) \ + template(MethodHandle_klass, java_lang_invoke_MethodHandle, Pre_JSR292) \ + template(MemberName_klass, java_lang_invoke_MemberName, Pre_JSR292) \ + template(MethodHandleImpl_klass, sun_dyn_MethodHandleImpl, Opt) /* AllowTransitionalJSR292 ONLY */ \ + template(MethodHandleNatives_klass, java_lang_invoke_MethodHandleNatives, Pre_JSR292) \ + template(AdapterMethodHandle_klass, java_lang_invoke_AdapterMethodHandle, Pre_JSR292) \ + template(BoundMethodHandle_klass, java_lang_invoke_BoundMethodHandle, Pre_JSR292) \ + template(DirectMethodHandle_klass, java_lang_invoke_DirectMethodHandle, Pre_JSR292) \ + template(MethodType_klass, java_lang_invoke_MethodType, Pre_JSR292) \ + template(MethodTypeForm_klass, java_lang_invoke_MethodTypeForm, Pre_JSR292) \ + template(WrongMethodTypeException_klass, java_lang_invoke_WrongMethodTypeException, Pre_JSR292) \ + template(Linkage_klass, java_lang_invoke_Linkage, Opt) /* AllowTransitionalJSR292 ONLY */ \ + template(CallSite_klass, java_lang_invoke_CallSite, Pre_JSR292) \ /* Note: MethodHandle must be first, and CallSite last in group */ \ \ template(StringBuffer_klass, java_lang_StringBuffer, Pre) \ @@ -207,6 +207,7 @@ enum InitOption { Pre, // preloaded; error if not present + Pre_JSR292, // preloaded if EnableMethodHandles // Order is significant. Options before this point require resolve_or_fail. // Options after this point will use resolve_or_null instead. @@ -401,6 +402,7 @@ } static klassOop check_klass_Pre(klassOop k) { return check_klass(k); } + static klassOop check_klass_Pre_JSR292(klassOop k) { return EnableInvokeDynamic ? check_klass(k) : k; } static klassOop check_klass_Opt(klassOop k) { return k; } static klassOop check_klass_Opt_Kernel(klassOop k) { return k; } //== Opt static klassOop check_klass_Opt_Only_JDK15(klassOop k) { @@ -420,6 +422,8 @@ initialize_wk_klasses_until((WKID) limit, start_id, THREAD); } + static Symbol* find_backup_symbol(Symbol* symbol, const char* from_prefix, const char* to_prefix); + public: #define WK_KLASS_DECLARE(name, ignore_symbol, option) \ static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); } @@ -441,6 +445,9 @@ static void load_abstract_ownable_synchronizer_klass(TRAPS); + static Symbol* find_backup_class_name(Symbol* class_name_symbol); + static Symbol* find_backup_signature(Symbol* signature_symbol); + private: // Tells whether ClassLoader.loadClassInternal is present static bool has_loadClassInternal() { return _has_loadClassInternal; } @@ -475,18 +482,18 @@ Handle loader2, bool is_method, TRAPS); // JSR 292 - // find the java.dyn.MethodHandles::invoke method for a given signature + // find the java.lang.invoke.MethodHandles::invoke method for a given signature static methodOop find_method_handle_invoke(Symbol* name, Symbol* signature, KlassHandle accessing_klass, TRAPS); - // ask Java to compute a java.dyn.MethodType object for a given signature + // ask Java to compute a java.lang.invoke.MethodType object for a given signature static Handle find_method_handle_type(Symbol* signature, KlassHandle accessing_klass, bool for_invokeGeneric, bool& return_bcp_flag, TRAPS); - // ask Java to compute a java.dyn.MethodHandle object for a given CP entry + // ask Java to compute a java.lang.invoke.MethodHandle object for a given CP entry static Handle link_method_handle_constant(KlassHandle caller, int ref_kind, //e.g., JVM_REF_invokeVirtual KlassHandle callee,
--- a/src/share/vm/classfile/verifier.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/verifier.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1671,13 +1671,19 @@ VerificationType::long_type(), VerificationType::long2_type(), CHECK_VERIFY(this)); } else if (tag.is_method_handle()) { + Symbol* methodHandle_name = vmSymbols::java_lang_invoke_MethodHandle(); + if (AllowTransitionalJSR292 && !Universe::is_bootstrapping()) + methodHandle_name = SystemDictionaryHandles::MethodHandle_klass()->name(); current_frame->push_stack( VerificationType::reference_type( - vmSymbols::java_dyn_MethodHandle()), CHECK_VERIFY(this)); + methodHandle_name), CHECK_VERIFY(this)); } else if (tag.is_method_type()) { + Symbol* methodType_name = vmSymbols::java_lang_invoke_MethodType(); + if (AllowTransitionalJSR292 && !Universe::is_bootstrapping()) + methodType_name = SystemDictionaryHandles::MethodType_klass()->name(); current_frame->push_stack( VerificationType::reference_type( - vmSymbols::java_dyn_MethodType()), CHECK_VERIFY(this)); + methodType_name), CHECK_VERIFY(this)); } else { verify_error(bci, "Invalid index in ldc"); return;
--- a/src/share/vm/classfile/vmSymbols.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/vmSymbols.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -277,6 +277,12 @@ return sid; } +vmSymbols::SID vmSymbols::find_sid(const char* symbol_name) { + Symbol* symbol = SymbolTable::probe(symbol_name, (int) strlen(symbol_name)); + if (symbol == NULL) return NO_SID; + return find_sid(symbol); +} + static vmIntrinsics::ID wrapper_intrinsic(BasicType type, bool unboxing) { #define TYPE2(type, unboxing) ((int)(type)*2 + ((unboxing) ? 1 : 0)) switch (TYPE2(type, unboxing)) {
--- a/src/share/vm/classfile/vmSymbols.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/classfile/vmSymbols.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -229,33 +229,60 @@ template(base_name, "base") \ \ /* Support for JSR 292 & invokedynamic (JDK 1.7 and above) */ \ - template(java_dyn_InvokeDynamic, "java/dyn/InvokeDynamic") \ - template(java_dyn_Linkage, "java/dyn/Linkage") \ - template(java_dyn_CallSite, "java/dyn/CallSite") \ - template(java_dyn_MethodHandle, "java/dyn/MethodHandle") \ - template(java_dyn_MethodType, "java/dyn/MethodType") \ - template(java_dyn_WrongMethodTypeException, "java/dyn/WrongMethodTypeException") \ - template(java_dyn_MethodType_signature, "Ljava/dyn/MethodType;") \ - template(java_dyn_MethodHandle_signature, "Ljava/dyn/MethodHandle;") \ + template(java_lang_invoke_InvokeDynamic, "java/lang/invoke/InvokeDynamic") \ + template(java_lang_invoke_Linkage, "java/lang/invoke/Linkage") \ + template(java_lang_invoke_CallSite, "java/lang/invoke/CallSite") \ + template(java_lang_invoke_MethodHandle, "java/lang/invoke/MethodHandle") \ + template(java_lang_invoke_MethodType, "java/lang/invoke/MethodType") \ + template(java_lang_invoke_WrongMethodTypeException, "java/lang/invoke/WrongMethodTypeException") \ + template(java_lang_invoke_MethodType_signature, "Ljava/lang/invoke/MethodType;") \ + template(java_lang_invoke_MethodHandle_signature, "Ljava/lang/invoke/MethodHandle;") \ /* internal classes known only to the JVM: */ \ - template(java_dyn_MethodTypeForm, "java/dyn/MethodTypeForm") \ - template(java_dyn_MethodTypeForm_signature, "Ljava/dyn/MethodTypeForm;") \ - template(sun_dyn_MemberName, "sun/dyn/MemberName") \ - template(sun_dyn_MemberName_signature, "Lsun/dyn/MemberName;") \ - template(sun_dyn_MethodHandleImpl, "sun/dyn/MethodHandleImpl") \ - template(sun_dyn_MethodHandleNatives, "sun/dyn/MethodHandleNatives") \ - template(sun_dyn_AdapterMethodHandle, "sun/dyn/AdapterMethodHandle") \ - template(sun_dyn_BoundMethodHandle, "sun/dyn/BoundMethodHandle") \ - template(sun_dyn_DirectMethodHandle, "sun/dyn/DirectMethodHandle") \ - /* internal up-calls made only by the JVM, via class sun.dyn.MethodHandleNatives: */ \ + template(java_lang_invoke_MethodTypeForm, "java/lang/invoke/MethodTypeForm") \ + template(java_lang_invoke_MethodTypeForm_signature, "Ljava/lang/invoke/MethodTypeForm;") \ + template(java_lang_invoke_MemberName, "java/lang/invoke/MemberName") \ + template(java_lang_invoke_MethodHandleNatives, "java/lang/invoke/MethodHandleNatives") \ + template(java_lang_invoke_AdapterMethodHandle, "java/lang/invoke/AdapterMethodHandle") \ + template(java_lang_invoke_BoundMethodHandle, "java/lang/invoke/BoundMethodHandle") \ + template(java_lang_invoke_DirectMethodHandle, "java/lang/invoke/DirectMethodHandle") \ + /* temporary transitional public names from 6839872: */ \ + template(java_dyn_InvokeDynamic, "java/dyn/InvokeDynamic") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_Linkage, "java/dyn/Linkage") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_CallSite, "java/dyn/CallSite") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_MethodHandle, "java/dyn/MethodHandle") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_MethodType, "java/dyn/MethodType") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_WrongMethodTypeException, "java/dyn/WrongMethodTypeException") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_MethodType_signature, "Ljava/dyn/MethodType;") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_MethodHandle_signature, "Ljava/dyn/MethodHandle;") /* AllowTransitionalJSR292 ONLY */ \ + /* temporary transitional internal names from 6839872: */ \ + template(java_dyn_MethodTypeForm, "java/dyn/MethodTypeForm") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_MethodTypeForm_signature, "Ljava/dyn/MethodTypeForm;") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_MemberName, "java/dyn/MemberName") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_MethodHandleNatives, "java/dyn/MethodHandleNatives") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_AdapterMethodHandle, "java/dyn/AdapterMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_BoundMethodHandle, "java/dyn/BoundMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ + template(java_dyn_DirectMethodHandle, "java/dyn/DirectMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ + /* temporary transitional internal names from EDR: */ \ + template(sun_dyn_MemberName, "sun/dyn/MemberName") /* AllowTransitionalJSR292 ONLY */ \ + template(sun_dyn_MethodHandleImpl, "sun/dyn/MethodHandleImpl") /* AllowTransitionalJSR292 ONLY */ \ + template(sun_dyn_MethodHandleNatives, "sun/dyn/MethodHandleNatives") /* AllowTransitionalJSR292 ONLY */ \ + template(sun_dyn_AdapterMethodHandle, "sun/dyn/AdapterMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ + template(sun_dyn_BoundMethodHandle, "sun/dyn/BoundMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ + template(sun_dyn_DirectMethodHandle, "sun/dyn/DirectMethodHandle") /* AllowTransitionalJSR292 ONLY */ \ + /* internal up-calls made only by the JVM, via class sun.invoke.MethodHandleNatives: */ \ template(findMethodHandleType_name, "findMethodHandleType") \ - template(findMethodHandleType_signature, "(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/dyn/MethodType;") \ + template(findMethodHandleType_signature, "(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/invoke/MethodType;") \ + template(findMethodHandleType_TRANS_signature, "(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/dyn/MethodType;") /* AllowTransitionalJSR292 ONLY */ \ template(notifyGenericMethodType_name, "notifyGenericMethodType") \ - template(notifyGenericMethodType_signature, "(Ljava/dyn/MethodType;)V") \ + template(notifyGenericMethodType_signature, "(Ljava/lang/invoke/MethodType;)V") \ + template(notifyGenericMethodType_TRANS_signature, "(Ljava/dyn/MethodType;)V") /* AllowTransitionalJSR292 ONLY */ \ template(linkMethodHandleConstant_name, "linkMethodHandleConstant") \ - template(linkMethodHandleConstant_signature, "(Ljava/lang/Class;ILjava/lang/Class;Ljava/lang/String;Ljava/lang/Object;)Ljava/dyn/MethodHandle;") \ + template(linkMethodHandleConstant_signature, "(Ljava/lang/Class;ILjava/lang/Class;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/invoke/MethodHandle;") \ + template(linkMethodHandleConstant_TRANS_signature, "(Ljava/lang/Class;ILjava/lang/Class;Ljava/lang/String;Ljava/lang/Object;)Ljava/dyn/MethodHandle;") /* AllowTransitionalJSR292 ONLY */ \ template(makeDynamicCallSite_name, "makeDynamicCallSite") \ - template(makeDynamicCallSite_signature, "(Ljava/dyn/MethodHandle;Ljava/lang/String;Ljava/dyn/MethodType;Ljava/lang/Object;Lsun/dyn/MemberName;I)Ljava/dyn/CallSite;") \ + template(makeDynamicCallSite_signature, "(Ljava/lang/invoke/MethodHandle;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/Object;Ljava/lang/invoke/MemberName;I)Ljava/lang/invoke/CallSite;") \ + template(makeDynamicCallSite_TRANS_signature, "(Ljava/dyn/MethodHandle;Ljava/lang/String;Ljava/dyn/MethodType;Ljava/lang/Object;Lsun/dyn/MemberName;I)Ljava/dyn/CallSite;") /* AllowTransitionalJSR292 ONLY */ \ + template(makeDynamicCallSite_TRANS2_signature, "(Ljava/dyn/MethodHandle;Ljava/lang/String;Ljava/dyn/MethodType;Ljava/lang/Object;Ljava/dyn/MemberName;I)Ljava/dyn/CallSite;") /* AllowTransitionalJSR292 ONLY */ \ NOT_LP64( do_alias(machine_word_signature, int_signature) ) \ LP64_ONLY( do_alias(machine_word_signature, long_signature) ) \ \ @@ -882,13 +909,15 @@ \ do_intrinsic(_invoke, java_lang_reflect_Method, invoke_name, object_object_array_object_signature, F_R) \ /* (symbols invoke_name and invoke_signature defined above) */ \ - do_intrinsic(_checkSpreadArgument, sun_dyn_MethodHandleImpl, checkSpreadArgument_name, checkSpreadArgument_signature, F_S) \ + do_intrinsic(_checkSpreadArgument, java_lang_invoke_MethodHandleNatives, checkSpreadArgument_name, checkSpreadArgument_signature, F_S) \ + do_intrinsic(_checkSpreadArgument_TRANS,sun_dyn_MethodHandleImpl, checkSpreadArgument_name, checkSpreadArgument_signature, F_S) /* AllowTransitionalJSR292 ONLY */ \ + do_intrinsic(_checkSpreadArgument_TRANS2,java_dyn_MethodHandleNatives, checkSpreadArgument_name, checkSpreadArgument_signature, F_S) /* AllowTransitionalJSR292 ONLY */ \ do_name( checkSpreadArgument_name, "checkSpreadArgument") \ do_name( checkSpreadArgument_signature, "(Ljava/lang/Object;I)V") \ - do_intrinsic(_invokeExact, java_dyn_MethodHandle, invokeExact_name, object_array_object_signature, F_RN) \ - do_intrinsic(_invokeGeneric, java_dyn_MethodHandle, invokeGeneric_name, object_array_object_signature, F_RN) \ - do_intrinsic(_invokeVarargs, java_dyn_MethodHandle, invokeVarargs_name, object_array_object_signature, F_R) \ - do_intrinsic(_invokeDynamic, java_dyn_InvokeDynamic, star_name, object_array_object_signature, F_SN) \ + do_intrinsic(_invokeExact, java_lang_invoke_MethodHandle, invokeExact_name, object_array_object_signature, F_RN) \ + do_intrinsic(_invokeGeneric, java_lang_invoke_MethodHandle, invokeGeneric_name, object_array_object_signature, F_RN) \ + do_intrinsic(_invokeVarargs, java_lang_invoke_MethodHandle, invokeVarargs_name, object_array_object_signature, F_R) \ + do_intrinsic(_invokeDynamic, java_lang_invoke_InvokeDynamic, star_name, object_array_object_signature, F_SN) \ \ /* unboxing methods: */ \ do_intrinsic(_booleanValue, java_lang_Boolean, booleanValue_name, void_boolean_signature, F_R) \ @@ -995,6 +1024,7 @@ // Returns symbol's SID if one is assigned, else NO_SID. static SID find_sid(Symbol* symbol); + static SID find_sid(const char* symbol_name); #ifndef PRODUCT // No need for this in the product:
--- a/src/share/vm/code/codeCache.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/code/codeCache.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -939,9 +939,16 @@ _heap->high(), _heap->high_boundary()); st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT - " adapters=" UINT32_FORMAT " free_code_cache=" SIZE_FORMAT + " adapters=" UINT32_FORMAT " free_code_cache=" SIZE_FORMAT "Kb" " largest_free_block=" SIZE_FORMAT, - CodeCache::nof_blobs(), CodeCache::nof_nmethods(), - CodeCache::nof_adapters(), CodeCache::unallocated_capacity(), - CodeCache::largest_free_block()); + nof_blobs(), nof_nmethods(), nof_adapters(), + unallocated_capacity()/K, largest_free_block()); } + +void CodeCache::log_state(outputStream* st) { + st->print(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'" + " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'" + " largest_free_block='" SIZE_FORMAT "'", + nof_blobs(), nof_nmethods(), nof_adapters(), + unallocated_capacity(), largest_free_block()); +}
--- a/src/share/vm/code/codeCache.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/code/codeCache.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -147,6 +147,7 @@ static void verify(); // verifies the code cache static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN; static void print_bounds(outputStream* st); // Prints a summary of the bounds of the code cache + static void log_state(outputStream* st); // The full limits of the codeCache static address low_bound() { return (address) _heap->low_boundary(); } @@ -159,7 +160,7 @@ static size_t max_capacity() { return _heap->max_capacity(); } static size_t unallocated_capacity() { return _heap->unallocated_capacity(); } static size_t largest_free_block() { return _heap->largest_free_block(); } - static bool needs_flushing() { return unallocated_capacity() < CodeCacheFlushingMinimumFreeSpace; } + static bool needs_flushing() { return largest_free_block() < CodeCacheFlushingMinimumFreeSpace; } static bool needs_cache_clean() { return _needs_cache_clean; } static void set_needs_cache_clean(bool v) { _needs_cache_clean = v; }
--- a/src/share/vm/code/nmethod.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/code/nmethod.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -170,7 +170,7 @@ int pc_desc_resets; // number of resets (= number of caches) int pc_desc_queries; // queries to nmethod::find_pc_desc int pc_desc_approx; // number of those which have approximate true - int pc_desc_repeats; // number of _last_pc_desc hits + int pc_desc_repeats; // number of _pc_descs[0] hits int pc_desc_hits; // number of LRU cache hits int pc_desc_tests; // total number of PcDesc examinations int pc_desc_searches; // total number of quasi-binary search steps @@ -190,15 +190,10 @@ } nmethod_stats; #endif //PRODUCT + //--------------------------------------------------------------------------------- -// The _unwind_handler is a special marker address, which says that -// for given exception oop and address, the frame should be removed -// as the tuple cannot be caught in the nmethod -address ExceptionCache::_unwind_handler = (address) -1; - - ExceptionCache::ExceptionCache(Handle exception, address pc, address handler) { assert(pc != NULL, "Must be non null"); assert(exception.not_null(), "Must be non null"); @@ -283,40 +278,44 @@ void PcDescCache::reset_to(PcDesc* initial_pc_desc) { if (initial_pc_desc == NULL) { - _last_pc_desc = NULL; // native method + _pc_descs[0] = NULL; // native method; no PcDescs at all return; } NOT_PRODUCT(++nmethod_stats.pc_desc_resets); // reset the cache by filling it with benign (non-null) values assert(initial_pc_desc->pc_offset() < 0, "must be sentinel"); - _last_pc_desc = initial_pc_desc + 1; // first valid one is after sentinel for (int i = 0; i < cache_size; i++) _pc_descs[i] = initial_pc_desc; } PcDesc* PcDescCache::find_pc_desc(int pc_offset, bool approximate) { NOT_PRODUCT(++nmethod_stats.pc_desc_queries); - NOT_PRODUCT(if (approximate) ++nmethod_stats.pc_desc_approx); + NOT_PRODUCT(if (approximate) ++nmethod_stats.pc_desc_approx); + + // Note: one might think that caching the most recently + // read value separately would be a win, but one would be + // wrong. When many threads are updating it, the cache + // line it's in would bounce between caches, negating + // any benefit. // In order to prevent race conditions do not load cache elements // repeatedly, but use a local copy: PcDesc* res; - // Step one: Check the most recently returned value. - res = _last_pc_desc; - if (res == NULL) return NULL; // native method; no PcDescs at all + // Step one: Check the most recently added value. + res = _pc_descs[0]; + if (res == NULL) return NULL; // native method; no PcDescs at all if (match_desc(res, pc_offset, approximate)) { NOT_PRODUCT(++nmethod_stats.pc_desc_repeats); return res; } - // Step two: Check the LRU cache. - for (int i = 0; i < cache_size; i++) { + // Step two: Check the rest of the LRU cache. + for (int i = 1; i < cache_size; ++i) { res = _pc_descs[i]; - if (res->pc_offset() < 0) break; // optimization: skip empty cache + if (res->pc_offset() < 0) break; // optimization: skip empty cache if (match_desc(res, pc_offset, approximate)) { NOT_PRODUCT(++nmethod_stats.pc_desc_hits); - _last_pc_desc = res; // record this cache hit in case of repeat return res; } } @@ -327,24 +326,23 @@ void PcDescCache::add_pc_desc(PcDesc* pc_desc) { NOT_PRODUCT(++nmethod_stats.pc_desc_adds); - // Update the LRU cache by shifting pc_desc forward: + // Update the LRU cache by shifting pc_desc forward. for (int i = 0; i < cache_size; i++) { PcDesc* next = _pc_descs[i]; _pc_descs[i] = pc_desc; pc_desc = next; } - // Note: Do not update _last_pc_desc. It fronts for the LRU cache. } // adjust pcs_size so that it is a multiple of both oopSize and // sizeof(PcDesc) (assumes that if sizeof(PcDesc) is not a multiple // of oopSize, then 2*sizeof(PcDesc) is) -static int adjust_pcs_size(int pcs_size) { +static int adjust_pcs_size(int pcs_size) { int nsize = round_to(pcs_size, oopSize); if ((nsize % sizeof(PcDesc)) != 0) { nsize = pcs_size + sizeof(PcDesc); } - assert((nsize % oopSize) == 0, "correct alignment"); + assert((nsize % oopSize) == 0, "correct alignment"); return nsize; } @@ -767,7 +765,7 @@ void* nmethod::operator new(size_t size, int nmethod_size) { // Always leave some room in the CodeCache for I2C/C2I adapters - if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) return NULL; + if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) return NULL; return CodeCache::allocate(nmethod_size); } @@ -1185,14 +1183,17 @@ set_stack_traversal_mark(NMethodSweeper::traversal_count()); } -// Tell if a non-entrant method can be converted to a zombie (i.e., there is no activations on the stack) +// Tell if a non-entrant method can be converted to a zombie (i.e., +// there are no activations on the stack, not in use by the VM, +// and not in use by the ServiceThread) bool nmethod::can_not_entrant_be_converted() { assert(is_not_entrant(), "must be a non-entrant method"); // Since the nmethod sweeper only does partial sweep the sweeper's traversal // count can be greater than the stack traversal count before it hits the // nmethod for the second time. - return stack_traversal_mark()+1 < NMethodSweeper::traversal_count(); + return stack_traversal_mark()+1 < NMethodSweeper::traversal_count() && + !is_locked_by_vm(); } void nmethod::inc_decompile_count() { @@ -1299,6 +1300,7 @@ // Common functionality for both make_not_entrant and make_zombie bool nmethod::make_not_entrant_or_zombie(unsigned int state) { assert(state == zombie || state == not_entrant, "must be zombie or not_entrant"); + assert(!is_zombie(), "should not already be a zombie"); // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below. nmethodLocker nml(this); @@ -1306,11 +1308,6 @@ No_Safepoint_Verifier nsv; { - // If the method is already zombie there is nothing to do - if (is_zombie()) { - return false; - } - // invalidate osr nmethod before acquiring the patching lock since // they both acquire leaf locks and we don't want a deadlock. // This logic is equivalent to the logic below for patching the @@ -1380,13 +1377,12 @@ flush_dependencies(NULL); } - { - // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload event - // and it hasn't already been reported for this nmethod then report it now. - // (the event may have been reported earilier if the GC marked it for unloading). - Pause_No_Safepoint_Verifier pnsv(&nsv); - post_compiled_method_unload(); - } + // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload + // event and it hasn't already been reported for this nmethod then + // report it now. The event may have been reported earilier if the GC + // marked it for unloading). JvmtiDeferredEventQueue support means + // we no longer go to a safepoint here. + post_compiled_method_unload(); #ifdef ASSERT // It's no longer safe to access the oops section since zombie @@ -1571,7 +1567,7 @@ if (_jmethod_id != NULL && JvmtiExport::should_post_compiled_method_unload()) { assert(!unload_reported(), "already unloaded"); JvmtiDeferredEvent event = - JvmtiDeferredEvent::compiled_method_unload_event( + JvmtiDeferredEvent::compiled_method_unload_event(this, _jmethod_id, insts_begin()); if (SafepointSynchronize::is_at_safepoint()) { // Don't want to take the queueing lock. Add it as pending and @@ -1886,7 +1882,7 @@ oop nmethod::embeddedOop_at(u_char* p) { - RelocIterator iter(this, p, p + oopSize); + RelocIterator iter(this, p, p + 1); while (iter.next()) if (iter.type() == relocInfo::oop_type) { return iter.oop_reloc()->oop_value(); @@ -2176,10 +2172,12 @@ lock_nmethod(_nm); } -void nmethodLocker::lock_nmethod(nmethod* nm) { +// Only JvmtiDeferredEvent::compiled_method_unload_event() +// should pass zombie_ok == true. +void nmethodLocker::lock_nmethod(nmethod* nm, bool zombie_ok) { if (nm == NULL) return; Atomic::inc(&nm->_lock_count); - guarantee(!nm->is_zombie(), "cannot lock a zombie method"); + guarantee(zombie_ok || !nm->is_zombie(), "cannot lock a zombie method"); } void nmethodLocker::unlock_nmethod(nmethod* nm) {
--- a/src/share/vm/code/nmethod.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/code/nmethod.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -34,7 +34,6 @@ class ExceptionCache : public CHeapObj { friend class VMStructs; private: - static address _unwind_handler; enum { cache_size = 16 }; klassOop _exception_type; address _pc[cache_size]; @@ -62,8 +61,6 @@ bool match_exception_with_space(Handle exception) ; address test_address(address addr); bool add_address_and_handler(address addr, address handler) ; - - static address unwind_handler() { return _unwind_handler; } }; @@ -72,14 +69,13 @@ friend class VMStructs; private: enum { cache_size = 4 }; - PcDesc* _last_pc_desc; // most recent pc_desc found PcDesc* _pc_descs[cache_size]; // last cache_size pc_descs found public: - PcDescCache() { debug_only(_last_pc_desc = NULL); } + PcDescCache() { debug_only(_pc_descs[0] = NULL); } void reset_to(PcDesc* initial_pc_desc); PcDesc* find_pc_desc(int pc_offset, bool approximate); void add_pc_desc(PcDesc* pc_desc); - PcDesc* last_pc_desc() { return _last_pc_desc; } + PcDesc* last_pc_desc() { return _pc_descs[0]; } }; @@ -181,7 +177,7 @@ unsigned int _has_method_handle_invokes:1; // Has this method MethodHandle invokes? // Protected by Patching_lock - unsigned char _state; // {alive, not_entrant, zombie, unloaded) + unsigned char _state; // {alive, not_entrant, zombie, unloaded} #ifdef ASSERT bool _oops_are_stale; // indicates that it's no longer safe to access oops section @@ -197,7 +193,10 @@ NOT_PRODUCT(bool _has_debug_info; ) - // Nmethod Flushing lock (if non-zero, then the nmethod is not removed) + // Nmethod Flushing lock. If non-zero, then the nmethod is not removed + // and is not made into a zombie. However, once the nmethod is made into + // a zombie, it will be locked one final time if CompiledMethodUnload + // event processing needs to be done. jint _lock_count; // not_entrant method removal. Each mark_sweep pass will update @@ -525,8 +524,9 @@ void flush(); public: - // If returning true, it is unsafe to remove this nmethod even though it is a zombie - // nmethod, since the VM might have a reference to it. Should only be called from a safepoint. + // When true is returned, it is unsafe to remove this nmethod even if + // it is a zombie, since the VM or the ServiceThread might still be + // using it. bool is_locked_by_vm() const { return _lock_count >0; } // See comment at definition of _last_seen_on_stack @@ -692,13 +692,20 @@ }; -// Locks an nmethod so its code will not get removed, even if it is a zombie/not_entrant method +// Locks an nmethod so its code will not get removed and it will not +// be made into a zombie, even if it is a not_entrant method. After the +// nmethod becomes a zombie, if CompiledMethodUnload event processing +// needs to be done, then lock_nmethod() is used directly to keep the +// generated code from being reused too early. class nmethodLocker : public StackObj { nmethod* _nm; public: - static void lock_nmethod(nmethod* nm); // note: nm can be NULL + // note: nm can be NULL + // Only JvmtiDeferredEvent::compiled_method_unload_event() + // should pass zombie_ok == true. + static void lock_nmethod(nmethod* nm, bool zombie_ok = false); static void unlock_nmethod(nmethod* nm); // (ditto) nmethodLocker(address pc); // derive nm from pc
--- a/src/share/vm/compiler/compileBroker.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/compiler/compileBroker.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1364,7 +1364,7 @@ // We need this HandleMark to avoid leaking VM handles. HandleMark hm(thread); - if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) { + if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) { // the code cache is really full handle_full_code_cache(); } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) { @@ -1645,11 +1645,13 @@ if (UseCompiler || AlwaysCompileLoopMethods ) { if (xtty != NULL) { xtty->begin_elem("code_cache_full"); + CodeCache::log_state(xtty); xtty->stamp(); xtty->end_elem(); } warning("CodeCache is full. Compiler has been disabled."); warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize="); + CodeCache::print_bounds(tty); #ifndef PRODUCT if (CompileTheWorld || ExitOnFullCodeCache) { before_exit(JavaThread::current());
--- a/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -83,11 +83,15 @@ } template <class T> void write_ref_array_pre_work(T* dst, int count); - virtual void write_ref_array_pre(oop* dst, int count) { - write_ref_array_pre_work(dst, count); + virtual void write_ref_array_pre(oop* dst, int count, bool dest_uninitialized) { + if (!dest_uninitialized) { + write_ref_array_pre_work(dst, count); + } } - virtual void write_ref_array_pre(narrowOop* dst, int count) { - write_ref_array_pre_work(dst, count); + virtual void write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized) { + if (!dest_uninitialized) { + write_ref_array_pre_work(dst, count); + } } };
--- a/src/share/vm/interpreter/abstractInterpreter.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/interpreter/abstractInterpreter.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -96,7 +96,7 @@ empty, // empty method (code: _return) accessor, // accessor method (code: _aload_0, _getfield, _(a|i)return) abstract, // abstract method (throws an AbstractMethodException) - method_handle, // java.dyn.MethodHandles::invoke + method_handle, // java.lang.invoke.MethodHandles::invoke java_lang_math_sin, // implementation of java.lang.Math.sin (x) java_lang_math_cos, // implementation of java.lang.Math.cos (x) java_lang_math_tan, // implementation of java.lang.Math.tan (x)
--- a/src/share/vm/interpreter/interpreterRuntime.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -369,7 +369,10 @@ } // create exception - THROW_MSG(vmSymbols::java_dyn_WrongMethodTypeException(), message); + Symbol* java_lang_invoke_WrongMethodTypeException = vmSymbols::java_lang_invoke_WrongMethodTypeException(); + if (AllowTransitionalJSR292) + java_lang_invoke_WrongMethodTypeException = SystemDictionaryHandles::WrongMethodTypeException_klass()->name(); + THROW_MSG(java_lang_invoke_WrongMethodTypeException, message); } IRT_END @@ -794,7 +797,7 @@ Handle info; // optional argument(s) in JVM_CONSTANT_InvokeDynamic Handle bootm = SystemDictionary::find_bootstrap_method(caller_method, caller_bci, main_index, info, CHECK); - if (!java_dyn_MethodHandle::is_instance(bootm())) { + if (!java_lang_invoke_MethodHandle::is_instance(bootm())) { THROW_MSG(vmSymbols::java_lang_IllegalStateException(), "no bootstrap method found for invokedynamic"); }
--- a/src/share/vm/interpreter/linkResolver.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/interpreter/linkResolver.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -217,11 +217,13 @@ if (EnableMethodHandles && klass() == SystemDictionary::MethodHandle_klass() && methodOopDesc::is_method_handle_invoke_name(name)) { - if (!MethodHandles::enabled()) { + if (!THREAD->is_Compiler_thread() && !MethodHandles::enabled()) { // Make sure the Java part of the runtime has been booted up. klassOop natives = SystemDictionary::MethodHandleNatives_klass(); if (natives == NULL || instanceKlass::cast(natives)->is_not_initialized()) { - SystemDictionary::resolve_or_fail(vmSymbols::sun_dyn_MethodHandleNatives(), + Symbol* natives_name = vmSymbols::java_lang_invoke_MethodHandleNatives(); + if (natives != NULL && AllowTransitionalJSR292) natives_name = Klass::cast(natives)->name(); + SystemDictionary::resolve_or_fail(natives_name, Handle(), Handle(), true, @@ -298,7 +300,7 @@ } void LinkResolver::resolve_dynamic_method(methodHandle& resolved_method, KlassHandle& resolved_klass, constantPoolHandle pool, int index, TRAPS) { - // The class is java.dyn.MethodHandle + // The class is java.lang.invoke.MethodHandle resolved_klass = SystemDictionaryHandles::MethodHandle_klass(); Symbol* method_name = vmSymbols::invokeExact_name();
--- a/src/share/vm/memory/barrierSet.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/memory/barrierSet.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -35,9 +35,9 @@ start, count); #endif if (UseCompressedOops) { - Universe::heap()->barrier_set()->write_ref_array_pre((narrowOop*)start, (int)count); + Universe::heap()->barrier_set()->write_ref_array_pre((narrowOop*)start, (int)count, false); } else { - Universe::heap()->barrier_set()->write_ref_array_pre( (oop*)start, (int)count); + Universe::heap()->barrier_set()->write_ref_array_pre( (oop*)start, (int)count, false); } }
--- a/src/share/vm/memory/barrierSet.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/memory/barrierSet.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,6 +44,10 @@ Uninit }; + enum Flags { + None = 0, + TargetUninitialized = 1 + }; protected: int _max_covered_regions; Name _kind; @@ -128,8 +132,10 @@ virtual void read_prim_array(MemRegion mr) = 0; // Below length is the # array elements being written - virtual void write_ref_array_pre( oop* dst, int length) {} - virtual void write_ref_array_pre(narrowOop* dst, int length) {} + virtual void write_ref_array_pre(oop* dst, int length, + bool dest_uninitialized = false) {} + virtual void write_ref_array_pre(narrowOop* dst, int length, + bool dest_uninitialized = false) {} // Below count is the # array elements being written, starting // at the address "start", which may not necessarily be HeapWord-aligned inline void write_ref_array(HeapWord* start, size_t count);
--- a/src/share/vm/memory/heap.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/memory/heap.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -316,12 +316,19 @@ } size_t CodeHeap::largest_free_block() const { + // First check unused space excluding free blocks. + size_t free_sz = size(_free_segments); + size_t unused = max_capacity() - allocated_capacity() - free_sz; + if (unused >= free_sz) + return unused; + + // Now check largest free block. size_t len = 0; for (FreeBlock* b = _freelist; b != NULL; b = b->link()) { if (b->length() > len) len = b->length(); } - return size(len); + return MAX2(unused, size(len)); } // Free list management
--- a/src/share/vm/oops/constantPoolOop.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/oops/constantPoolOop.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1175,8 +1175,15 @@ case JVM_CONSTANT_UnresolvedClass: { - Symbol* k = from_cp->unresolved_klass_at(from_i); - to_cp->unresolved_klass_at_put(to_i, k); + // Can be resolved after checking tag, so check the slot first. + CPSlot entry = from_cp->slot_at(from_i); + if (entry.is_oop()) { + assert(entry.get_oop()->is_klass(), "must be"); + // Already resolved + to_cp->klass_at_put(to_i, (klassOop)entry.get_oop()); + } else { + to_cp->unresolved_klass_at_put(to_i, entry.get_symbol()); + } } break; case JVM_CONSTANT_UnresolvedClassInError: @@ -1189,8 +1196,14 @@ case JVM_CONSTANT_UnresolvedString: { - Symbol* s = from_cp->unresolved_string_at(from_i); - to_cp->unresolved_string_at_put(to_i, s); + // Can be resolved after checking tag, so check the slot first. + CPSlot entry = from_cp->slot_at(from_i); + if (entry.is_oop()) { + // Already resolved (either string or pseudo-string) + to_cp->string_at_put(to_i, entry.get_oop()); + } else { + to_cp->unresolved_string_at_put(to_i, entry.get_symbol()); + } } break; case JVM_CONSTANT_Utf8:
--- a/src/share/vm/oops/cpCacheOop.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/oops/cpCacheOop.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -190,7 +190,7 @@ ); void set_dynamic_call( - Handle call_site, // Resolved java.dyn.CallSite (f1) + Handle call_site, // Resolved java.lang.invoke.CallSite (f1) methodHandle signature_invoker // determines signature information );
--- a/src/share/vm/oops/instanceKlass.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/oops/instanceKlass.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -735,7 +735,12 @@ static int call_class_initializer_impl_counter = 0; // for debugging methodOop instanceKlass::class_initializer() { - return find_method(vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); + methodOop clinit = find_method( + vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); + if (clinit != NULL && clinit->has_valid_initializer_flags()) { + return clinit; + } + return NULL; } void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) { @@ -2415,7 +2420,7 @@ st->cr(); } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { st->print(BULLET"signature: "); - java_dyn_MethodType::print_signature(obj, st); + java_lang_invoke_MethodType::print_signature(obj, st); st->cr(); } } @@ -2446,7 +2451,7 @@ } } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { st->print(" = "); - java_dyn_MethodType::print_signature(obj, st); + java_lang_invoke_MethodType::print_signature(obj, st); } else if (java_lang_boxing_object::is_instance(obj)) { st->print(" = "); java_lang_boxing_object::print(obj, st);
--- a/src/share/vm/oops/instanceKlass.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/oops/instanceKlass.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -193,8 +193,8 @@ typeArrayOop _inner_classes; // Implementors of this interface (not valid if it overflows) klassOop _implementors[implementors_limit]; - // invokedynamic bootstrap method (a java.dyn.MethodHandle) - oop _bootstrap_method; + // invokedynamic bootstrap method (a java.lang.invoke.MethodHandle) + oop _bootstrap_method; // AllowTransitionalJSR292 ONLY // Annotations for this class, or null if none. typeArrayOop _class_annotations; // Annotation objects (byte arrays) for fields, or null if no annotations. @@ -529,7 +529,7 @@ _enclosing_method_method_index = method_index; } // JSR 292 support - oop bootstrap_method() const { return _bootstrap_method; } + oop bootstrap_method() const { return _bootstrap_method; } // AllowTransitionalJSR292 ONLY void set_bootstrap_method(oop mh) { oop_store(&_bootstrap_method, mh); } // jmethodID support @@ -817,7 +817,7 @@ oop* adr_signers() const { return (oop*)&this->_signers;} oop* adr_inner_classes() const { return (oop*)&this->_inner_classes;} oop* adr_implementors() const { return (oop*)&this->_implementors[0];} - oop* adr_bootstrap_method() const { return (oop*)&this->_bootstrap_method;} + oop* adr_bootstrap_method() const { return (oop*)&this->_bootstrap_method;} // AllowTransitionalJSR292 ONLY oop* adr_methods_jmethod_ids() const { return (oop*)&this->_methods_jmethod_ids;} oop* adr_methods_cached_itable_indices() const { return (oop*)&this->_methods_cached_itable_indices;} oop* adr_class_annotations() const { return (oop*)&this->_class_annotations;}
--- a/src/share/vm/oops/klassVtable.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/oops/klassVtable.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -883,7 +883,7 @@ int ime_num = 0; // Skip first methodOop if it is a class initializer - int i = ((methodOop)methods()->obj_at(0))->name() != vmSymbols::class_initializer_name() ? 0 : 1; + int i = ((methodOop)methods()->obj_at(0))->is_static_initializer() ? 1 : 0; // m, method_name, method_signature, klass reset each loop so they // don't need preserving across check_signature_loaders call @@ -1121,7 +1121,7 @@ assert(index < methods->length(), "should find index for resolve_invoke"); } // Adjust for <clinit>, which is left out of table if first method - if (methods->length() > 0 && ((methodOop)methods->obj_at(0))->name() == vmSymbols::class_initializer_name()) { + if (methods->length() > 0 && ((methodOop)methods->obj_at(0))->is_static_initializer()) { index--; } return index; @@ -1135,7 +1135,7 @@ int index = itable_index; // Adjust for <clinit>, which is left out of table if first method - if (methods->length() > 0 && ((methodOop)methods->obj_at(0))->name() == vmSymbols::class_initializer_name()) { + if (methods->length() > 0 && ((methodOop)methods->obj_at(0))->is_static_initializer()) { index++; }
--- a/src/share/vm/oops/methodDataOop.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/oops/methodDataOop.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -228,7 +228,7 @@ return byte_offset_of(DataLayout, _header._struct._bci); } static ByteSize cell_offset(int index) { - return byte_offset_of(DataLayout, _cells[index]); + return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size); } // Return a value which, when or-ed as a byte into _flags, sets the flag. static int flag_number_to_byte_constant(int flag_number) {
--- a/src/share/vm/oops/methodKlass.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/oops/methodKlass.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -103,6 +103,12 @@ m->backedge_counter()->init(); m->clear_number_of_breakpoints(); +#ifdef TIERED + m->set_rate(0); + m->set_prev_event_count(0); + m->set_prev_time(0); +#endif + assert(m->is_parsable(), "must be parsable here."); assert(m->size() == size, "wrong size for object"); // We should not publish an uprasable object's reference
--- a/src/share/vm/oops/methodOop.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/oops/methodOop.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -466,7 +466,20 @@ bool methodOopDesc::is_initializer() const { - return name() == vmSymbols::object_initializer_name() || name() == vmSymbols::class_initializer_name(); + return name() == vmSymbols::object_initializer_name() || is_static_initializer(); +} + +bool methodOopDesc::has_valid_initializer_flags() const { + return (is_static() || + instanceKlass::cast(method_holder())->major_version() < 51); +} + +bool methodOopDesc::is_static_initializer() const { + // For classfiles version 51 or greater, ensure that the clinit method is + // static. Non-static methods with the name "<clinit>" are not static + // initializers. (older classfiles exempted for backward compatibility) + return name() == vmSymbols::class_initializer_name() && + has_valid_initializer_flags(); } @@ -842,7 +855,7 @@ case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name): return true; } - if (AllowTransitionalJSR292 + if ((AllowTransitionalJSR292 || AllowInvokeForInvokeGeneric) && name_sid == vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name)) return true; return false; @@ -852,7 +865,7 @@ enum { _imcp_invoke_name = 1, // utf8: 'invokeExact' or 'invokeGeneric' _imcp_invoke_signature, // utf8: (variable Symbol*) - _imcp_method_type_value, // string: (variable java/dyn/MethodType, sic) + _imcp_method_type_value, // string: (variable java/lang/invoke/MethodType, sic) _imcp_limit }; @@ -1078,7 +1091,8 @@ vmSymbols::SID name_id = vmSymbols::find_sid(name()); if (name_id == vmSymbols::NO_SID) return; vmSymbols::SID sig_id = vmSymbols::find_sid(signature()); - if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_dyn_MethodHandle) + if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) + && !(klass_id == vmSymbols::VM_SYMBOL_ENUM_NAME(java_dyn_MethodHandle) && AllowTransitionalJSR292) && sig_id == vmSymbols::NO_SID) return; jshort flags = access_flags().as_short(); @@ -1104,7 +1118,8 @@ break; // Signature-polymorphic methods: MethodHandle.invoke*, InvokeDynamic.*. - case vmSymbols::VM_SYMBOL_ENUM_NAME(java_dyn_MethodHandle): + case vmSymbols::VM_SYMBOL_ENUM_NAME(java_dyn_MethodHandle): // AllowTransitionalJSR292 ONLY + case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle): if (is_static() || !is_native()) break; switch (name_id) { case vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name): @@ -1114,11 +1129,12 @@ id = vmIntrinsics::_invokeExact; break; case vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name): - if (AllowTransitionalJSR292) id = vmIntrinsics::_invokeExact; + if (AllowInvokeForInvokeGeneric) id = vmIntrinsics::_invokeGeneric; + else if (AllowTransitionalJSR292) id = vmIntrinsics::_invokeExact; break; } break; - case vmSymbols::VM_SYMBOL_ENUM_NAME(java_dyn_InvokeDynamic): + case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_InvokeDynamic): if (!is_static() || !is_native()) break; id = vmIntrinsics::_invokeDynamic; break;
--- a/src/share/vm/oops/methodOop.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/oops/methodOop.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -84,6 +84,11 @@ // | invocation_counter | // | backedge_counter | // |------------------------------------------------------| +// | prev_time (tiered only, 64 bit wide) | +// | | +// |------------------------------------------------------| +// | rate (tiered) | +// |------------------------------------------------------| // | code (pointer) | // | i2i (pointer) | // | adapter (pointer) | @@ -124,6 +129,11 @@ InvocationCounter _invocation_counter; // Incremented before each activation of the method - used to trigger frequency-based optimizations InvocationCounter _backedge_counter; // Incremented before each backedge taken - used to trigger frequencey-based optimizations +#ifdef TIERED + jlong _prev_time; // Previous time the rate was acquired + float _rate; // Events (invocation and backedge counter increments) per millisecond +#endif + #ifndef PRODUCT int _compiled_invocation_count; // Number of nmethod invocations so far (for perf. debugging) #endif @@ -304,6 +314,17 @@ InvocationCounter* invocation_counter() { return &_invocation_counter; } InvocationCounter* backedge_counter() { return &_backedge_counter; } +#ifdef TIERED + // We are reusing interpreter_invocation_count as a holder for the previous event count! + // We can do that since interpreter_invocation_count is not used in tiered. + int prev_event_count() const { return _interpreter_invocation_count; } + void set_prev_event_count(int count) { _interpreter_invocation_count = count; } + jlong prev_time() const { return _prev_time; } + void set_prev_time(jlong time) { _prev_time = time; } + float rate() const { return _rate; } + void set_rate(float rate) { _rate = rate; } +#endif + int invocation_count(); int backedge_count(); @@ -497,6 +518,13 @@ // returns true if the method is an initializer (<init> or <clinit>). bool is_initializer() const; + // returns true if the method is static OR if the classfile version < 51 + bool has_valid_initializer_flags() const; + + // returns true if the method name is <clinit> and the method has + // valid static initializer flags. + bool is_static_initializer() const; + // compiled code support // NOTE: code() is inherently racy as deopt can be clearing code // simultaneously. Use with caution.
--- a/src/share/vm/opto/bytecodeInfo.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/opto/bytecodeInfo.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -487,7 +487,7 @@ if (caller_jvms->method()->is_method_handle_adapter()) new_depth_adjust -= 1; // don't count actions in MH or indy adapter frames else if (callee_method->is_method_handle_invoke()) { - new_depth_adjust -= 1; // don't count method handle calls from java.dyn implem + new_depth_adjust -= 1; // don't count method handle calls from java.lang.invoke implem } if (new_depth_adjust != 0 && PrintInlining) { stringStream nm1; caller_jvms->method()->print_name(&nm1);
--- a/src/share/vm/opto/callGenerator.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/opto/callGenerator.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -199,7 +199,7 @@ Node* call_site = kit.make_load(kit.control(), call_site_adr, TypeInstPtr::BOTTOM, T_OBJECT, Compile::AliasIdxRaw); // Load the target MethodHandle from the CallSite object. - Node* target_mh_adr = kit.basic_plus_adr(call_site, call_site, java_dyn_CallSite::target_offset_in_bytes()); + Node* target_mh_adr = kit.basic_plus_adr(call_site, call_site, java_lang_invoke_CallSite::target_offset_in_bytes()); Node* target_mh = kit.make_load(kit.control(), target_mh_adr, TypeInstPtr::BOTTOM, T_OBJECT); address resolve_stub = SharedRuntime::get_resolve_opt_virtual_call_stub(); @@ -725,7 +725,7 @@ Node* call_site = kit.make_load(kit.control(), call_site_adr, TypeInstPtr::BOTTOM, T_OBJECT, Compile::AliasIdxRaw); // Load the target MethodHandle from the CallSite object. - Node* target_adr = kit.basic_plus_adr(call_site, call_site, java_dyn_CallSite::target_offset_in_bytes()); + Node* target_adr = kit.basic_plus_adr(call_site, call_site, java_lang_invoke_CallSite::target_offset_in_bytes()); Node* target_mh = kit.make_load(kit.control(), target_adr, TypeInstPtr::BOTTOM, T_OBJECT); // Check if the MethodHandle is still the same.
--- a/src/share/vm/opto/library_call.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/opto/library_call.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -97,7 +97,7 @@ RegionNode* region); Node* generate_current_thread(Node* &tls_output); address basictype2arraycopy(BasicType t, Node *src_offset, Node *dest_offset, - bool disjoint_bases, const char* &name); + bool disjoint_bases, const char* &name, bool dest_uninitialized); Node* load_mirror_from_klass(Node* klass); Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null, int nargs, @@ -212,26 +212,26 @@ AllocateNode* alloc, Node* src, Node* src_offset, Node* dest, Node* dest_offset, - Node* dest_size); + Node* dest_size, bool dest_uninitialized); void generate_slow_arraycopy(const TypePtr* adr_type, Node* src, Node* src_offset, Node* dest, Node* dest_offset, - Node* copy_length); + Node* copy_length, bool dest_uninitialized); Node* generate_checkcast_arraycopy(const TypePtr* adr_type, Node* dest_elem_klass, Node* src, Node* src_offset, Node* dest, Node* dest_offset, - Node* copy_length); + Node* copy_length, bool dest_uninitialized); Node* generate_generic_arraycopy(const TypePtr* adr_type, Node* src, Node* src_offset, Node* dest, Node* dest_offset, - Node* copy_length); + Node* copy_length, bool dest_uninitialized); void generate_unchecked_arraycopy(const TypePtr* adr_type, BasicType basic_elem_type, bool disjoint_bases, Node* src, Node* src_offset, Node* dest, Node* dest_offset, - Node* copy_length); + Node* copy_length, bool dest_uninitialized); bool inline_unsafe_CAS(BasicType type); bool inline_unsafe_ordered_store(BasicType type); bool inline_fp_conversions(vmIntrinsics::ID id); @@ -1193,7 +1193,7 @@ Node* result; // Disable the use of pcmpestri until it can be guaranteed that // the load doesn't cross into the uncommited space. - if (false && Matcher::has_match_rule(Op_StrIndexOf) && + if (Matcher::has_match_rule(Op_StrIndexOf) && UseSSE42Intrinsics) { // Generate SSE4.2 version of indexOf // We currently only have match rules that use SSE4.2 @@ -1211,14 +1211,14 @@ return true; } + ciInstanceKlass* str_klass = env()->String_klass(); + const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(str_klass); + // Make the merge point - RegionNode* result_rgn = new (C, 3) RegionNode(3); - Node* result_phi = new (C, 3) PhiNode(result_rgn, TypeInt::INT); + RegionNode* result_rgn = new (C, 4) RegionNode(4); + Node* result_phi = new (C, 4) PhiNode(result_rgn, TypeInt::INT); Node* no_ctrl = NULL; - ciInstanceKlass* klass = env()->String_klass(); - const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(klass); - // Get counts for string and substr Node* source_cnta = basic_plus_adr(receiver, receiver, count_offset); Node* source_cnt = make_load(no_ctrl, source_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset)); @@ -1236,6 +1236,17 @@ } if (!stopped()) { + // Check for substr count == 0 + cmp = _gvn.transform( new(C, 3) CmpINode(substr_cnt, intcon(0)) ); + bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::eq) ); + Node* if_zero = generate_slow_guard(bol, NULL); + if (if_zero != NULL) { + result_phi->init_req(3, intcon(0)); + result_rgn->init_req(3, if_zero); + } + } + + if (!stopped()) { result = make_string_method_node(Op_StrIndexOf, receiver, source_cnt, argument, substr_cnt); result_phi->init_req(1, result); result_rgn->init_req(1, control()); @@ -1244,8 +1255,8 @@ record_for_igvn(result_rgn); result = _gvn.transform(result_phi); - } else { //Use LibraryCallKit::string_indexOf - // don't intrinsify is argument isn't a constant string. + } else { // Use LibraryCallKit::string_indexOf + // don't intrinsify if argument isn't a constant string. if (!argument->is_Con()) { return false; } @@ -1281,7 +1292,7 @@ // No null check on the argument is needed since it's a constant String oop. _sp -= 2; if (stopped()) { - return true; + return true; } // The null string as a pattern always returns 0 (match at beginning of string) @@ -4081,7 +4092,8 @@ const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; bool disjoint_bases = true; generate_unchecked_arraycopy(raw_adr_type, T_LONG, disjoint_bases, - src, NULL, dest, NULL, countx); + src, NULL, dest, NULL, countx, + /*dest_uninitialized*/true); // If necessary, emit some card marks afterwards. (Non-arrays only.) if (card_mark) { @@ -4295,7 +4307,7 @@ // Note: The condition "disjoint" applies also for overlapping copies // where an descending copy is permitted (i.e., dest_offset <= src_offset). static address -select_arraycopy_function(BasicType t, bool aligned, bool disjoint, const char* &name) { +select_arraycopy_function(BasicType t, bool aligned, bool disjoint, const char* &name, bool dest_uninitialized) { int selector = (aligned ? COPYFUNC_ALIGNED : COPYFUNC_UNALIGNED) + (disjoint ? COPYFUNC_DISJOINT : COPYFUNC_CONJOINT); @@ -4304,6 +4316,10 @@ name = #xxx_arraycopy; \ return StubRoutines::xxx_arraycopy(); } +#define RETURN_STUB_PARM(xxx_arraycopy, parm) { \ + name = #xxx_arraycopy; \ + return StubRoutines::xxx_arraycopy(parm); } + switch (t) { case T_BYTE: case T_BOOLEAN: @@ -4340,10 +4356,10 @@ case T_ARRAY: case T_OBJECT: switch (selector) { - case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(oop_arraycopy); - case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_oop_arraycopy); - case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(oop_disjoint_arraycopy); - case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_oop_disjoint_arraycopy); + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB_PARM(oop_arraycopy, dest_uninitialized); + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB_PARM(arrayof_oop_arraycopy, dest_uninitialized); + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB_PARM(oop_disjoint_arraycopy, dest_uninitialized); + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB_PARM(arrayof_oop_disjoint_arraycopy, dest_uninitialized); } default: ShouldNotReachHere(); @@ -4351,6 +4367,7 @@ } #undef RETURN_STUB +#undef RETURN_STUB_PARM } //------------------------------basictype2arraycopy---------------------------- @@ -4358,7 +4375,8 @@ Node* src_offset, Node* dest_offset, bool disjoint_bases, - const char* &name) { + const char* &name, + bool dest_uninitialized) { const TypeInt* src_offset_inttype = gvn().find_int_type(src_offset);; const TypeInt* dest_offset_inttype = gvn().find_int_type(dest_offset);; @@ -4384,7 +4402,7 @@ disjoint = true; } - return select_arraycopy_function(t, aligned, disjoint, name); + return select_arraycopy_function(t, aligned, disjoint, name, dest_uninitialized); } @@ -4440,7 +4458,8 @@ // The component types are not the same or are not recognized. Punt. // (But, avoid the native method wrapper to JVM_ArrayCopy.) generate_slow_arraycopy(TypePtr::BOTTOM, - src, src_offset, dest, dest_offset, length); + src, src_offset, dest, dest_offset, length, + /*dest_uninitialized*/false); return true; } @@ -4553,7 +4572,7 @@ Node* original_dest = dest; AllocateArrayNode* alloc = NULL; // used for zeroing, if needed - bool must_clear_dest = false; + bool dest_uninitialized = false; // See if this is the initialization of a newly-allocated array. // If so, we will take responsibility here for initializing it to zero. @@ -4576,12 +4595,14 @@ adr_type = TypeRawPtr::BOTTOM; // all initializations are into raw memory // From this point on, every exit path is responsible for // initializing any non-copied parts of the object to zero. - must_clear_dest = true; + // Also, if this flag is set we make sure that arraycopy interacts properly + // with G1, eliding pre-barriers. See CR 6627983. + dest_uninitialized = true; } else { // No zeroing elimination here. alloc = NULL; //original_dest = dest; - //must_clear_dest = false; + //dest_uninitialized = false; } // Results are placed here: @@ -4613,10 +4634,10 @@ Node* checked_value = NULL; if (basic_elem_type == T_CONFLICT) { - assert(!must_clear_dest, ""); + assert(!dest_uninitialized, ""); Node* cv = generate_generic_arraycopy(adr_type, src, src_offset, dest, dest_offset, - copy_length); + copy_length, dest_uninitialized); if (cv == NULL) cv = intcon(-1); // failure (no stub available) checked_control = control(); checked_i_o = i_o(); @@ -4636,7 +4657,7 @@ } // copy_length is 0. - if (!stopped() && must_clear_dest) { + if (!stopped() && dest_uninitialized) { Node* dest_length = alloc->in(AllocateNode::ALength); if (_gvn.eqv_uncast(copy_length, dest_length) || _gvn.find_int_con(dest_length, 1) <= 0) { @@ -4662,7 +4683,7 @@ result_memory->init_req(zero_path, memory(adr_type)); } - if (!stopped() && must_clear_dest) { + if (!stopped() && dest_uninitialized) { // We have to initialize the *uncopied* part of the array to zero. // The copy destination is the slice dest[off..off+len]. The other slices // are dest_head = dest[0..off] and dest_tail = dest[off+len..dest.length]. @@ -4698,7 +4719,7 @@ { PreserveJVMState pjvms(this); didit = generate_block_arraycopy(adr_type, basic_elem_type, alloc, src, src_offset, dest, dest_offset, - dest_size); + dest_size, dest_uninitialized); if (didit) { // Present the results of the block-copying fast call. result_region->init_req(bcopy_path, control()); @@ -4774,7 +4795,7 @@ Node* cv = generate_checkcast_arraycopy(adr_type, dest_elem_klass, src, src_offset, dest, dest_offset, - ConvI2X(copy_length)); + ConvI2X(copy_length), dest_uninitialized); if (cv == NULL) cv = intcon(-1); // failure (no stub available) checked_control = control(); checked_i_o = i_o(); @@ -4797,7 +4818,7 @@ PreserveJVMState pjvms(this); generate_unchecked_arraycopy(adr_type, copy_type, disjoint_bases, src, src_offset, dest, dest_offset, - ConvI2X(copy_length)); + ConvI2X(copy_length), dest_uninitialized); // Present the results of the fast call. result_region->init_req(fast_path, control()); @@ -4876,7 +4897,7 @@ set_memory(slow_mem, adr_type); set_i_o(slow_i_o); - if (must_clear_dest) { + if (dest_uninitialized) { generate_clear_array(adr_type, dest, basic_elem_type, intcon(0), NULL, alloc->in(AllocateNode::AllocSize)); @@ -4884,7 +4905,7 @@ generate_slow_arraycopy(adr_type, src, src_offset, dest, dest_offset, - copy_length); + copy_length, /*dest_uninitialized*/false); result_region->init_req(slow_call_path, control()); result_i_o ->init_req(slow_call_path, i_o()); @@ -5128,7 +5149,7 @@ AllocateNode* alloc, Node* src, Node* src_offset, Node* dest, Node* dest_offset, - Node* dest_size) { + Node* dest_size, bool dest_uninitialized) { // See if there is an advantage from block transfer. int scale = exact_log2(type2aelembytes(basic_elem_type)); if (scale >= LogBytesPerLong) @@ -5173,7 +5194,7 @@ bool disjoint_bases = true; // since alloc != NULL generate_unchecked_arraycopy(adr_type, T_LONG, disjoint_bases, - sptr, NULL, dptr, NULL, countx); + sptr, NULL, dptr, NULL, countx, dest_uninitialized); return true; } @@ -5186,7 +5207,8 @@ LibraryCallKit::generate_slow_arraycopy(const TypePtr* adr_type, Node* src, Node* src_offset, Node* dest, Node* dest_offset, - Node* copy_length) { + Node* copy_length, bool dest_uninitialized) { + assert(!dest_uninitialized, "Invariant"); Node* call = make_runtime_call(RC_NO_LEAF | RC_UNCOMMON, OptoRuntime::slow_arraycopy_Type(), OptoRuntime::slow_arraycopy_Java(), @@ -5204,10 +5226,10 @@ Node* dest_elem_klass, Node* src, Node* src_offset, Node* dest, Node* dest_offset, - Node* copy_length) { + Node* copy_length, bool dest_uninitialized) { if (stopped()) return NULL; - address copyfunc_addr = StubRoutines::checkcast_arraycopy(); + address copyfunc_addr = StubRoutines::checkcast_arraycopy(dest_uninitialized); if (copyfunc_addr == NULL) { // Stub was not generated, go slow path. return NULL; } @@ -5245,9 +5267,9 @@ LibraryCallKit::generate_generic_arraycopy(const TypePtr* adr_type, Node* src, Node* src_offset, Node* dest, Node* dest_offset, - Node* copy_length) { + Node* copy_length, bool dest_uninitialized) { + assert(!dest_uninitialized, "Invariant"); if (stopped()) return NULL; - address copyfunc_addr = StubRoutines::generic_arraycopy(); if (copyfunc_addr == NULL) { // Stub was not generated, go slow path. return NULL; @@ -5268,7 +5290,7 @@ bool disjoint_bases, Node* src, Node* src_offset, Node* dest, Node* dest_offset, - Node* copy_length) { + Node* copy_length, bool dest_uninitialized) { if (stopped()) return; // nothing to do Node* src_start = src; @@ -5283,7 +5305,7 @@ const char* copyfunc_name = "arraycopy"; address copyfunc_addr = basictype2arraycopy(basic_elem_type, src_offset, dest_offset, - disjoint_bases, copyfunc_name); + disjoint_bases, copyfunc_name, dest_uninitialized); // Call it. Note that the count_ix value is not scaled to a byte-size. make_runtime_call(RC_LEAF|RC_NO_FP,
--- a/src/share/vm/opto/memnode.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/opto/memnode.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1559,21 +1559,24 @@ phase->C->has_unsafe_access(), "Field accesses must be precise" ); // For oop loads, we expect the _type to be precise - if (OptimizeStringConcat && klass == phase->C->env()->String_klass() && + if (klass == phase->C->env()->String_klass() && adr->is_AddP() && off != Type::OffsetBot) { - // For constant Strings treat the fields as compile time constants. + // For constant Strings treat the final fields as compile time constants. Node* base = adr->in(AddPNode::Base); const TypeOopPtr* t = phase->type(base)->isa_oopptr(); if (t != NULL && t->singleton()) { - ciObject* string = t->const_oop(); - ciConstant constant = string->as_instance()->field_value_by_offset(off); - if (constant.basic_type() == T_INT) { - return TypeInt::make(constant.as_int()); - } else if (constant.basic_type() == T_ARRAY) { - if (adr->bottom_type()->is_ptr_to_narrowoop()) { - return TypeNarrowOop::make_from_constant(constant.as_object()); - } else { - return TypeOopPtr::make_from_constant(constant.as_object()); + ciField* field = phase->C->env()->String_klass()->get_field_by_offset(off, false); + if (field != NULL && field->is_final()) { + ciObject* string = t->const_oop(); + ciConstant constant = string->as_instance()->field_value(field); + if (constant.basic_type() == T_INT) { + return TypeInt::make(constant.as_int()); + } else if (constant.basic_type() == T_ARRAY) { + if (adr->bottom_type()->is_ptr_to_narrowoop()) { + return TypeNarrowOop::make_from_constant(constant.as_object()); + } else { + return TypeOopPtr::make_from_constant(constant.as_object()); + } } } } @@ -4077,6 +4080,7 @@ n = base_memory(); assert(Node::in_dump() || n == NULL || n->bottom_type() == Type::TOP + || n->adr_type() == NULL // address is TOP || n->adr_type() == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0,
--- a/src/share/vm/opto/output.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/opto/output.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1028,7 +1028,7 @@ // helper for Fill_buffer bailout logic static void turn_off_compiler(Compile* C) { - if (CodeCache::unallocated_capacity() >= CodeCacheMinimumFreeSpace*10) { + if (CodeCache::largest_free_block() >= CodeCacheMinimumFreeSpace*10) { // Do not turn off compilation if a single giant method has // blown the code cache size. C->record_failure("excessive request to CodeCache");
--- a/src/share/vm/opto/parse3.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/opto/parse3.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -143,8 +143,8 @@ return; } else { - // final non-static field of a trusted class ({java,sun}.dyn - // classes). + // final non-static field of a trusted class (classes in + // java.lang.invoke and sun.invoke packages and subpackages). if (obj->is_Con()) { const TypeOopPtr* oop_ptr = obj->bottom_type()->isa_oopptr(); ciObject* constant_oop = oop_ptr->const_oop();
--- a/src/share/vm/opto/type.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/opto/type.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -3386,7 +3386,22 @@ instance_id = InstanceBot; tary = TypeAry::make(Type::BOTTOM, tary->_size); } + } else // Non integral arrays. + // Must fall to bottom if exact klasses in upper lattice + // are not equal or super klass is exact. + if ( above_centerline(ptr) && klass() != tap->klass() && + // meet with top[] and bottom[] are processed further down: + tap ->_klass != NULL && this->_klass != NULL && + // both are exact and not equal: + ((tap ->_klass_is_exact && this->_klass_is_exact) || + // 'tap' is exact and super or unrelated: + (tap ->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) || + // 'this' is exact and super or unrelated: + (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) { + tary = TypeAry::make(Type::BOTTOM, tary->_size); + return make( NotNull, NULL, tary, lazy_klass, false, off, InstanceBot ); } + bool xk = false; switch (tap->ptr()) { case AnyNull: @@ -3766,7 +3781,7 @@ // Oops, need to compute _klass and cache it ciKlass* k_ary = compute_klass(); - if( this != TypeAryPtr::OOPS ) { + if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) { // The _klass field acts as a cache of the underlying // ciKlass for this array type. In order to set the field, // we need to cast away const-ness.
--- a/src/share/vm/prims/jvmtiImpl.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/prims/jvmtiImpl.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -919,15 +919,24 @@ nmethod* nm) { JvmtiDeferredEvent event = JvmtiDeferredEvent(TYPE_COMPILED_METHOD_LOAD); event._event_data.compiled_method_load = nm; - nmethodLocker::lock_nmethod(nm); // will be unlocked when posted + // Keep the nmethod alive until the ServiceThread can process + // this deferred event. + nmethodLocker::lock_nmethod(nm); return event; } JvmtiDeferredEvent JvmtiDeferredEvent::compiled_method_unload_event( - jmethodID id, const void* code) { + nmethod* nm, jmethodID id, const void* code) { JvmtiDeferredEvent event = JvmtiDeferredEvent(TYPE_COMPILED_METHOD_UNLOAD); + event._event_data.compiled_method_unload.nm = nm; event._event_data.compiled_method_unload.method_id = id; event._event_data.compiled_method_unload.code_begin = code; + // Keep the nmethod alive until the ServiceThread can process + // this deferred event. This will keep the memory for the + // generated code from being reused too early. We pass + // zombie_ok == true here so that our nmethod that was just + // made into a zombie can be locked. + nmethodLocker::lock_nmethod(nm, true /* zombie_ok */); return event; } JvmtiDeferredEvent JvmtiDeferredEvent::dynamic_code_generated_event( @@ -946,14 +955,19 @@ case TYPE_COMPILED_METHOD_LOAD: { nmethod* nm = _event_data.compiled_method_load; JvmtiExport::post_compiled_method_load(nm); + // done with the deferred event so unlock the nmethod nmethodLocker::unlock_nmethod(nm); break; } - case TYPE_COMPILED_METHOD_UNLOAD: + case TYPE_COMPILED_METHOD_UNLOAD: { + nmethod* nm = _event_data.compiled_method_unload.nm; JvmtiExport::post_compiled_method_unload( _event_data.compiled_method_unload.method_id, _event_data.compiled_method_unload.code_begin); + // done with the deferred event so unlock the nmethod + nmethodLocker::unlock_nmethod(nm); break; + } case TYPE_DYNAMIC_CODE_GENERATED: JvmtiExport::post_dynamic_code_generated_internal( _event_data.dynamic_code_generated.name,
--- a/src/share/vm/prims/jvmtiImpl.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/prims/jvmtiImpl.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -458,6 +458,7 @@ union { nmethod* compiled_method_load; struct { + nmethod* nm; jmethodID method_id; const void* code_begin; } compiled_method_unload; @@ -477,7 +478,7 @@ // Factory methods static JvmtiDeferredEvent compiled_method_load_event(nmethod* nm) KERNEL_RETURN_(JvmtiDeferredEvent()); - static JvmtiDeferredEvent compiled_method_unload_event( + static JvmtiDeferredEvent compiled_method_unload_event(nmethod* nm, jmethodID id, const void* code) KERNEL_RETURN_(JvmtiDeferredEvent()); static JvmtiDeferredEvent dynamic_code_generated_event( const char* name, const void* begin, const void* end)
--- a/src/share/vm/prims/jvmtiRedefineClasses.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1084,7 +1084,10 @@ jbyte old_tag = old_cp->tag_at(old_i).value(); switch (old_tag) { case JVM_CONSTANT_Class: + case JVM_CONSTANT_UnresolvedClass: // revert the copy to JVM_CONSTANT_UnresolvedClass + // May be resolving while calling this so do the same for + // JVM_CONSTANT_UnresolvedClass (klass_name_at() deals with transition) (*merge_cp_p)->unresolved_klass_at_put(old_i, old_cp->klass_name_at(old_i)); break;
--- a/src/share/vm/prims/methodHandleWalk.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/prims/methodHandleWalk.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -36,7 +36,7 @@ // MethodHandleChain void MethodHandleChain::set_method_handle(Handle mh, TRAPS) { - if (!java_dyn_MethodHandle::is_instance(mh())) lose("bad method handle", CHECK); + if (!java_lang_invoke_MethodHandle::is_instance(mh())) lose("bad method handle", CHECK); // set current method handle and unpack partially _method_handle = mh; @@ -47,21 +47,21 @@ _conversion = -1; _last_invoke = Bytecodes::_nop; //arbitrary non-garbage - if (sun_dyn_DirectMethodHandle::is_instance(mh())) { + if (java_lang_invoke_DirectMethodHandle::is_instance(mh())) { set_last_method(mh(), THREAD); return; } - if (sun_dyn_AdapterMethodHandle::is_instance(mh())) { + if (java_lang_invoke_AdapterMethodHandle::is_instance(mh())) { _conversion = AdapterMethodHandle_conversion(); assert(_conversion != -1, "bad conv value"); - assert(sun_dyn_BoundMethodHandle::is_instance(mh()), "also BMH"); + assert(java_lang_invoke_BoundMethodHandle::is_instance(mh()), "also BMH"); } - if (sun_dyn_BoundMethodHandle::is_instance(mh())) { + if (java_lang_invoke_BoundMethodHandle::is_instance(mh())) { if (!is_adapter()) // keep AMH and BMH separate in this model _is_bound = true; _arg_slot = BoundMethodHandle_vmargslot(); oop target = MethodHandle_vmtarget_oop(); - if (!is_bound() || java_dyn_MethodHandle::is_instance(target)) { + if (!is_bound() || java_lang_invoke_MethodHandle::is_instance(target)) { _arg_type = compute_bound_arg_type(target, NULL, _arg_slot, CHECK); } else if (target != NULL && target->is_method()) { methodOop m = (methodOop) target; @@ -100,13 +100,12 @@ BasicType MethodHandleChain::compute_bound_arg_type(oop target, methodOop m, int arg_slot, TRAPS) { // There is no direct indication of whether the argument is primitive or not. // It is implied by the _vmentry code, and by the MethodType of the target. - // FIXME: Make it explicit MethodHandleImpl refactors out from MethodHandle BasicType arg_type = T_VOID; if (target != NULL) { - oop mtype = java_dyn_MethodHandle::type(target); + oop mtype = java_lang_invoke_MethodHandle::type(target); int arg_num = MethodHandles::argument_slot_to_argnum(mtype, arg_slot); if (arg_num >= 0) { - oop ptype = java_dyn_MethodType::ptype(mtype, arg_num); + oop ptype = java_lang_invoke_MethodType::ptype(mtype, arg_num); arg_type = java_lang_Class::as_BasicType(ptype); } } else if (m != NULL) { @@ -205,28 +204,28 @@ int arg_slot = chain().adapter_arg_slot(); SlotState* arg_state = slot_state(arg_slot); if (arg_state == NULL - && conv_op > sun_dyn_AdapterMethodHandle::OP_RETYPE_RAW) { + && conv_op > java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW) { lose("bad argument index", CHECK_(empty)); } // perform the adapter action switch (chain().adapter_conversion_op()) { - case sun_dyn_AdapterMethodHandle::OP_RETYPE_ONLY: + case java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY: // No changes to arguments; pass the bits through. break; - case sun_dyn_AdapterMethodHandle::OP_RETYPE_RAW: { + case java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW: { // To keep the verifier happy, emit bitwise ("raw") conversions as needed. // See MethodHandles::same_basic_type_for_arguments for allowed conversions. Handle incoming_mtype(THREAD, chain().method_type_oop()); oop outgoing_mh_oop = chain().vmtarget_oop(); - if (!java_dyn_MethodHandle::is_instance(outgoing_mh_oop)) + if (!java_lang_invoke_MethodHandle::is_instance(outgoing_mh_oop)) lose("outgoing target not a MethodHandle", CHECK_(empty)); - Handle outgoing_mtype(THREAD, java_dyn_MethodHandle::type(outgoing_mh_oop)); + Handle outgoing_mtype(THREAD, java_lang_invoke_MethodHandle::type(outgoing_mh_oop)); outgoing_mh_oop = NULL; // GC safety - int nptypes = java_dyn_MethodType::ptype_count(outgoing_mtype()); - if (nptypes != java_dyn_MethodType::ptype_count(incoming_mtype())) + int nptypes = java_lang_invoke_MethodType::ptype_count(outgoing_mtype()); + if (nptypes != java_lang_invoke_MethodType::ptype_count(incoming_mtype())) lose("incoming and outgoing parameter count do not agree", CHECK_(empty)); for (int i = 0, slot = _outgoing.length() - 1; slot >= 0; slot--) { @@ -236,8 +235,8 @@ klassOop in_klass = NULL; klassOop out_klass = NULL; - BasicType inpbt = java_lang_Class::as_BasicType(java_dyn_MethodType::ptype(incoming_mtype(), i), &in_klass); - BasicType outpbt = java_lang_Class::as_BasicType(java_dyn_MethodType::ptype(outgoing_mtype(), i), &out_klass); + BasicType inpbt = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::ptype(incoming_mtype(), i), &in_klass); + BasicType outpbt = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::ptype(outgoing_mtype(), i), &out_klass); assert(inpbt == arg.basic_type(), "sanity"); if (inpbt != outpbt) { @@ -255,8 +254,8 @@ i++; // We need to skip void slots at the top of the loop. } - BasicType inrbt = java_lang_Class::as_BasicType(java_dyn_MethodType::rtype(incoming_mtype())); - BasicType outrbt = java_lang_Class::as_BasicType(java_dyn_MethodType::rtype(outgoing_mtype())); + BasicType inrbt = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(incoming_mtype())); + BasicType outrbt = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(outgoing_mtype())); if (inrbt != outrbt) { if (inrbt == T_INT && outrbt == T_VOID) { // See comments in MethodHandles::same_basic_type_for_arguments. @@ -268,7 +267,7 @@ break; } - case sun_dyn_AdapterMethodHandle::OP_CHECK_CAST: { + case java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST: { // checkcast the Nth outgoing argument in place klassOop dest_klass = NULL; BasicType dest = java_lang_Class::as_BasicType(chain().adapter_arg_oop(), &dest_klass); @@ -281,7 +280,7 @@ break; } - case sun_dyn_AdapterMethodHandle::OP_PRIM_TO_PRIM: { + case java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_PRIM: { // i2l, etc., on the Nth outgoing argument in place BasicType src = chain().adapter_conversion_src_type(), dest = chain().adapter_conversion_dest_type(); @@ -306,7 +305,7 @@ break; } - case sun_dyn_AdapterMethodHandle::OP_REF_TO_PRIM: { + case java_lang_invoke_AdapterMethodHandle::OP_REF_TO_PRIM: { // checkcast to wrapper type & call intValue, etc. BasicType dest = chain().adapter_conversion_dest_type(); ArgToken arg = arg_state->_arg; @@ -324,7 +323,7 @@ break; } - case sun_dyn_AdapterMethodHandle::OP_PRIM_TO_REF: { + case java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF: { // call wrapper type.valueOf BasicType src = chain().adapter_conversion_src_type(); ArgToken arg = arg_state->_arg; @@ -340,7 +339,7 @@ break; } - case sun_dyn_AdapterMethodHandle::OP_SWAP_ARGS: { + case java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS: { int dest_arg_slot = chain().adapter_conversion_vminfo(); if (!slot_has_argument(dest_arg_slot)) { lose("bad swap index", CHECK_(empty)); @@ -353,7 +352,7 @@ break; } - case sun_dyn_AdapterMethodHandle::OP_ROT_ARGS: { + case java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS: { int dest_arg_slot = chain().adapter_conversion_vminfo(); if (!slot_has_argument(dest_arg_slot) || arg_slot == dest_arg_slot) { lose("bad rotate index", CHECK_(empty)); @@ -379,7 +378,7 @@ break; } - case sun_dyn_AdapterMethodHandle::OP_DUP_ARGS: { + case java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS: { int dup_slots = chain().adapter_conversion_stack_pushes(); if (dup_slots <= 0) { lose("bad dup count", CHECK_(empty)); @@ -393,7 +392,7 @@ break; } - case sun_dyn_AdapterMethodHandle::OP_DROP_ARGS: { + case java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS: { int drop_slots = -chain().adapter_conversion_stack_pushes(); if (drop_slots <= 0) { lose("bad drop count", CHECK_(empty)); @@ -407,12 +406,12 @@ break; } - case sun_dyn_AdapterMethodHandle::OP_COLLECT_ARGS: { //NYI, may GC + case java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS: { //NYI, may GC lose("unimplemented", CHECK_(empty)); break; } - case sun_dyn_AdapterMethodHandle::OP_SPREAD_ARGS: { + case java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS: { klassOop array_klass_oop = NULL; BasicType array_type = java_lang_Class::as_BasicType(chain().adapter_arg_oop(), &array_klass_oop); @@ -470,8 +469,8 @@ break; } - case sun_dyn_AdapterMethodHandle::OP_FLYBY: //NYI, runs Java code - case sun_dyn_AdapterMethodHandle::OP_RICOCHET: //NYI, runs Java code + case java_lang_invoke_AdapterMethodHandle::OP_FLYBY: //NYI, runs Java code + case java_lang_invoke_AdapterMethodHandle::OP_RICOCHET: //NYI, runs Java code lose("unimplemented", CHECK_(empty)); break; @@ -533,7 +532,7 @@ // void MethodHandleWalker::walk_incoming_state(TRAPS) { Handle mtype(THREAD, chain().method_type_oop()); - int nptypes = java_dyn_MethodType::ptype_count(mtype()); + int nptypes = java_lang_invoke_MethodType::ptype_count(mtype()); _outgoing_argc = nptypes; int argp = nptypes - 1; if (argp >= 0) { @@ -542,7 +541,7 @@ for (int i = 0; i < nptypes; i++) { klassOop arg_type_klass = NULL; BasicType arg_type = java_lang_Class::as_BasicType( - java_dyn_MethodType::ptype(mtype(), i), &arg_type_klass); + java_lang_invoke_MethodType::ptype(mtype(), i), &arg_type_klass); int index = new_local_index(arg_type); ArgToken arg = make_parameter(arg_type, arg_type_klass, index, CHECK); debug_only(arg_type_klass = (klassOop) NULL); @@ -556,7 +555,7 @@ // call make_parameter at the end of the list for the return type klassOop ret_type_klass = NULL; BasicType ret_type = java_lang_Class::as_BasicType( - java_dyn_MethodType::rtype(mtype()), &ret_type_klass); + java_lang_invoke_MethodType::rtype(mtype()), &ret_type_klass); ArgToken ret = make_parameter(ret_type, ret_type_klass, -1, CHECK); // ignore ret; client can catch it if needed } @@ -631,7 +630,7 @@ // Get return type klass. Handle first_mtype(THREAD, chain().method_type_oop()); // _rklass is NULL for primitives. - _rtype = java_lang_Class::as_BasicType(java_dyn_MethodType::rtype(first_mtype()), &_rklass); + _rtype = java_lang_Class::as_BasicType(java_lang_invoke_MethodType::rtype(first_mtype()), &_rklass); if (_rtype == T_ARRAY) _rtype = T_OBJECT; int params = _callee->size_of_parameters(); // Incoming arguments plus receiver. @@ -960,6 +959,16 @@ if (m == NULL) { // Get the intrinsic methodOop. m = vmIntrinsics::method_for(iid); + if (m == NULL && iid == vmIntrinsics::_checkSpreadArgument && AllowTransitionalJSR292) { + m = vmIntrinsics::method_for(vmIntrinsics::_checkSpreadArgument_TRANS); + if (m == NULL) + // sun.dyn.MethodHandleImpl not found, look for java.dyn.MethodHandleNatives: + m = vmIntrinsics::method_for(vmIntrinsics::_checkSpreadArgument_TRANS2); + } + if (m == NULL) { + ArgToken zero; + lose(vmIntrinsics::name_at(iid), CHECK_(zero)); + } } klassOop klass = m->method_holder(); @@ -1396,7 +1405,7 @@ void print_method_handle(oop mh) { if (!mh->is_oop()) { tty->print_cr("*** not a method handle: "INTPTR_FORMAT, (intptr_t)mh); - } else if (java_dyn_MethodHandle::is_instance(mh)) { + } else if (java_lang_invoke_MethodHandle::is_instance(mh)) { //MethodHandlePrinter::print(mh); } else { tty->print("*** not a method handle: ");
--- a/src/share/vm/prims/methodHandleWalk.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/prims/methodHandleWalk.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -48,13 +48,13 @@ void set_last_method(oop target, TRAPS); static BasicType compute_bound_arg_type(oop target, methodOop m, int arg_slot, TRAPS); - oop MethodHandle_type_oop() { return java_dyn_MethodHandle::type(method_handle_oop()); } - oop MethodHandle_vmtarget_oop() { return java_dyn_MethodHandle::vmtarget(method_handle_oop()); } - int MethodHandle_vmslots() { return java_dyn_MethodHandle::vmslots(method_handle_oop()); } - int DirectMethodHandle_vmindex() { return sun_dyn_DirectMethodHandle::vmindex(method_handle_oop()); } - oop BoundMethodHandle_argument_oop() { return sun_dyn_BoundMethodHandle::argument(method_handle_oop()); } - int BoundMethodHandle_vmargslot() { return sun_dyn_BoundMethodHandle::vmargslot(method_handle_oop()); } - int AdapterMethodHandle_conversion() { return sun_dyn_AdapterMethodHandle::conversion(method_handle_oop()); } + oop MethodHandle_type_oop() { return java_lang_invoke_MethodHandle::type(method_handle_oop()); } + oop MethodHandle_vmtarget_oop() { return java_lang_invoke_MethodHandle::vmtarget(method_handle_oop()); } + int MethodHandle_vmslots() { return java_lang_invoke_MethodHandle::vmslots(method_handle_oop()); } + int DirectMethodHandle_vmindex() { return java_lang_invoke_DirectMethodHandle::vmindex(method_handle_oop()); } + oop BoundMethodHandle_argument_oop() { return java_lang_invoke_BoundMethodHandle::argument(method_handle_oop()); } + int BoundMethodHandle_vmargslot() { return java_lang_invoke_BoundMethodHandle::vmargslot(method_handle_oop()); } + int AdapterMethodHandle_conversion() { return java_lang_invoke_AdapterMethodHandle::conversion(method_handle_oop()); } public: MethodHandleChain(Handle root, TRAPS)
--- a/src/share/vm/prims/methodHandles.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/prims/methodHandles.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -163,9 +163,9 @@ // or it may use the klass/index form; both forms mean the same thing. methodOop m = decode_methodOop(methodOop(vmtarget), decode_flags_result); if ((decode_flags_result & _dmf_has_receiver) != 0 - && java_dyn_MethodType::is_instance(mtype)) { + && java_lang_invoke_MethodType::is_instance(mtype)) { // Extract receiver type restriction from mtype.ptypes[0]. - objArrayOop ptypes = java_dyn_MethodType::ptypes(mtype); + objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(mtype); oop ptype0 = (ptypes == NULL || ptypes->length() < 1) ? oop(NULL) : ptypes->obj_at(0); if (java_lang_Class::is_instance(ptype0)) receiver_limit_result = java_lang_Class::as_klassOop(ptype0); @@ -199,18 +199,18 @@ // (MemberName is the non-operational name used for queries and setup.) methodOop MethodHandles::decode_DirectMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) { - oop vmtarget = sun_dyn_DirectMethodHandle::vmtarget(mh); - int vmindex = sun_dyn_DirectMethodHandle::vmindex(mh); - oop mtype = sun_dyn_DirectMethodHandle::type(mh); + oop vmtarget = java_lang_invoke_DirectMethodHandle::vmtarget(mh); + int vmindex = java_lang_invoke_DirectMethodHandle::vmindex(mh); + oop mtype = java_lang_invoke_DirectMethodHandle::type(mh); return decode_vmtarget(vmtarget, vmindex, mtype, receiver_limit_result, decode_flags_result); } methodOop MethodHandles::decode_BoundMethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) { - assert(sun_dyn_BoundMethodHandle::is_instance(mh), ""); + assert(java_lang_invoke_BoundMethodHandle::is_instance(mh), ""); assert(mh->klass() != SystemDictionary::AdapterMethodHandle_klass(), ""); for (oop bmh = mh;;) { // Bound MHs can be stacked to bind several arguments. - oop target = java_dyn_MethodHandle::vmtarget(bmh); + oop target = java_lang_invoke_MethodHandle::vmtarget(bmh); if (target == NULL) return NULL; decode_flags_result |= MethodHandles::_dmf_binds_argument; klassOop tk = target->klass(); @@ -218,7 +218,7 @@ bmh = target; continue; } else { - if (java_dyn_MethodHandle::is_subclass(tk)) { + if (java_lang_invoke_MethodHandle::is_subclass(tk)) { //assert(tk == SystemDictionary::DirectMethodHandle_klass(), "end of BMH chain must be DMH"); return decode_MethodHandle(target, receiver_limit_result, decode_flags_result); } else { @@ -240,9 +240,9 @@ assert(mh->klass() == SystemDictionary::AdapterMethodHandle_klass(), ""); for (oop amh = mh;;) { // Adapter MHs can be stacked to convert several arguments. - int conv_op = adapter_conversion_op(sun_dyn_AdapterMethodHandle::conversion(amh)); + int conv_op = adapter_conversion_op(java_lang_invoke_AdapterMethodHandle::conversion(amh)); decode_flags_result |= (_dmf_adapter_lsb << conv_op) & _DMF_ADAPTER_MASK; - oop target = java_dyn_MethodHandle::vmtarget(amh); + oop target = java_lang_invoke_MethodHandle::vmtarget(amh); if (target == NULL) return NULL; klassOop tk = target->klass(); if (tk == SystemDictionary::AdapterMethodHandle_klass()) { @@ -258,14 +258,14 @@ methodOop MethodHandles::decode_MethodHandle(oop mh, klassOop& receiver_limit_result, int& decode_flags_result) { if (mh == NULL) return NULL; klassOop mhk = mh->klass(); - assert(java_dyn_MethodHandle::is_subclass(mhk), "must be a MethodHandle"); + assert(java_lang_invoke_MethodHandle::is_subclass(mhk), "must be a MethodHandle"); if (mhk == SystemDictionary::DirectMethodHandle_klass()) { return decode_DirectMethodHandle(mh, receiver_limit_result, decode_flags_result); } else if (mhk == SystemDictionary::BoundMethodHandle_klass()) { return decode_BoundMethodHandle(mh, receiver_limit_result, decode_flags_result); } else if (mhk == SystemDictionary::AdapterMethodHandle_klass()) { return decode_AdapterMethodHandle(mh, receiver_limit_result, decode_flags_result); - } else if (sun_dyn_BoundMethodHandle::is_subclass(mhk)) { + } else if (java_lang_invoke_BoundMethodHandle::is_subclass(mhk)) { // could be a JavaMethodHandle (but not an adapter MH) return decode_BoundMethodHandle(mh, receiver_limit_result, decode_flags_result); } else { @@ -308,7 +308,7 @@ } else if (xk == SystemDictionary::MemberName_klass()) { // Note: This only works if the MemberName has already been resolved. return decode_MemberName(x, receiver_limit_result, decode_flags_result); - } else if (java_dyn_MethodHandle::is_subclass(xk)) { + } else if (java_lang_invoke_MethodHandle::is_subclass(xk)) { return decode_MethodHandle(x, receiver_limit_result, decode_flags_result); } else if (xk == SystemDictionary::reflect_Method_klass()) { oop clazz = java_lang_reflect_Method::clazz(x); @@ -327,7 +327,7 @@ } else { // unrecognized object assert(!x->is_method(), "already checked"); - assert(!sun_dyn_MemberName::is_instance(x), "already checked"); + assert(!java_lang_invoke_MemberName::is_instance(x), "already checked"); } return NULL; } @@ -336,15 +336,15 @@ int MethodHandles::decode_MethodHandle_stack_pushes(oop mh) { if (mh->klass() == SystemDictionary::DirectMethodHandle_klass()) return 0; // no push/pop - int this_vmslots = java_dyn_MethodHandle::vmslots(mh); + int this_vmslots = java_lang_invoke_MethodHandle::vmslots(mh); int last_vmslots = 0; oop last_mh = mh; for (;;) { - oop target = java_dyn_MethodHandle::vmtarget(last_mh); + oop target = java_lang_invoke_MethodHandle::vmtarget(last_mh); if (target->klass() == SystemDictionary::DirectMethodHandle_klass()) { - last_vmslots = java_dyn_MethodHandle::vmslots(target); + last_vmslots = java_lang_invoke_MethodHandle::vmslots(target); break; - } else if (!java_dyn_MethodHandle::is_instance(target)) { + } else if (!java_lang_invoke_MethodHandle::is_instance(target)) { // might be klass or method assert(target->is_method(), "must get here with a direct ref to method"); last_vmslots = methodOop(target)->size_of_parameters(); @@ -361,16 +361,16 @@ // MemberName support -// import sun_dyn_MemberName.* +// import java_lang_invoke_MemberName.* enum { - IS_METHOD = sun_dyn_MemberName::MN_IS_METHOD, - IS_CONSTRUCTOR = sun_dyn_MemberName::MN_IS_CONSTRUCTOR, - IS_FIELD = sun_dyn_MemberName::MN_IS_FIELD, - IS_TYPE = sun_dyn_MemberName::MN_IS_TYPE, - SEARCH_SUPERCLASSES = sun_dyn_MemberName::MN_SEARCH_SUPERCLASSES, - SEARCH_INTERFACES = sun_dyn_MemberName::MN_SEARCH_INTERFACES, + IS_METHOD = java_lang_invoke_MemberName::MN_IS_METHOD, + IS_CONSTRUCTOR = java_lang_invoke_MemberName::MN_IS_CONSTRUCTOR, + IS_FIELD = java_lang_invoke_MemberName::MN_IS_FIELD, + IS_TYPE = java_lang_invoke_MemberName::MN_IS_TYPE, + SEARCH_SUPERCLASSES = java_lang_invoke_MemberName::MN_SEARCH_SUPERCLASSES, + SEARCH_INTERFACES = java_lang_invoke_MemberName::MN_SEARCH_INTERFACES, ALL_KINDS = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE, - VM_INDEX_UNINITIALIZED = sun_dyn_MemberName::VM_INDEX_UNINITIALIZED + VM_INDEX_UNINITIALIZED = java_lang_invoke_MemberName::VM_INDEX_UNINITIALIZED }; Handle MethodHandles::new_MemberName(TRAPS) { @@ -405,10 +405,10 @@ if (!do_dispatch || (flags & IS_CONSTRUCTOR) || m->can_be_statically_bound()) vmindex = methodOopDesc::nonvirtual_vtable_index; // implies never any dispatch assert(vmindex != VM_INDEX_UNINITIALIZED, "Java sentinel value"); - sun_dyn_MemberName::set_vmtarget(mname_oop, vmtarget); - sun_dyn_MemberName::set_vmindex(mname_oop, vmindex); - sun_dyn_MemberName::set_flags(mname_oop, flags); - sun_dyn_MemberName::set_clazz(mname_oop, Klass::cast(m->method_holder())->java_mirror()); + java_lang_invoke_MemberName::set_vmtarget(mname_oop, vmtarget); + java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex); + java_lang_invoke_MemberName::set_flags(mname_oop, flags); + java_lang_invoke_MemberName::set_clazz(mname_oop, Klass::cast(m->method_holder())->java_mirror()); } void MethodHandles::init_MemberName(oop mname_oop, klassOop field_holder, AccessFlags mods, int offset) { @@ -416,21 +416,21 @@ oop vmtarget = field_holder; int vmindex = offset; // determines the field uniquely when combined with static bit assert(vmindex != VM_INDEX_UNINITIALIZED, "bad alias on vmindex"); - sun_dyn_MemberName::set_vmtarget(mname_oop, vmtarget); - sun_dyn_MemberName::set_vmindex(mname_oop, vmindex); - sun_dyn_MemberName::set_flags(mname_oop, flags); - sun_dyn_MemberName::set_clazz(mname_oop, Klass::cast(field_holder)->java_mirror()); + java_lang_invoke_MemberName::set_vmtarget(mname_oop, vmtarget); + java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex); + java_lang_invoke_MemberName::set_flags(mname_oop, flags); + java_lang_invoke_MemberName::set_clazz(mname_oop, Klass::cast(field_holder)->java_mirror()); } methodOop MethodHandles::decode_MemberName(oop mname, klassOop& receiver_limit_result, int& decode_flags_result) { - int flags = sun_dyn_MemberName::flags(mname); + int flags = java_lang_invoke_MemberName::flags(mname); if ((flags & (IS_METHOD | IS_CONSTRUCTOR)) == 0) return NULL; // not invocable - oop vmtarget = sun_dyn_MemberName::vmtarget(mname); - int vmindex = sun_dyn_MemberName::vmindex(mname); + oop vmtarget = java_lang_invoke_MemberName::vmtarget(mname); + int vmindex = java_lang_invoke_MemberName::vmindex(mname); if (vmindex == VM_INDEX_UNINITIALIZED) return NULL; // not resolved methodOop m = decode_vmtarget(vmtarget, vmindex, NULL, receiver_limit_result, decode_flags_result); - oop clazz = sun_dyn_MemberName::clazz(mname); + oop clazz = java_lang_invoke_MemberName::clazz(mname); if (clazz != NULL && java_lang_Class::is_instance(clazz)) { klassOop klass = java_lang_Class::as_klassOop(clazz); if (klass != NULL) receiver_limit_result = klass; @@ -442,8 +442,8 @@ Symbol* MethodHandles::convert_to_signature(oop type_str, bool polymorphic, TRAPS) { - if (java_dyn_MethodType::is_instance(type_str)) { - return java_dyn_MethodType::as_signature(type_str, polymorphic, CHECK_NULL); + if (java_lang_invoke_MethodType::is_instance(type_str)) { + return java_lang_invoke_MethodType::as_signature(type_str, polymorphic, CHECK_NULL); } else if (java_lang_Class::is_instance(type_str)) { return java_lang_Class::as_signature(type_str, false, CHECK_NULL); } else if (java_lang_String::is_instance(type_str)) { @@ -461,7 +461,7 @@ // Resolving it plants a vmtarget/vmindex in it, // which refers dirctly to JVM internals. void MethodHandles::resolve_MemberName(Handle mname, TRAPS) { - assert(sun_dyn_MemberName::is_instance(mname()), ""); + assert(java_lang_invoke_MemberName::is_instance(mname()), ""); #ifdef ASSERT // If this assert throws, renegotiate the sentinel value used by the Java code, // so that it is distinct from any valid vtable index value, and any special @@ -472,12 +472,12 @@ const int sentinel_limit = methodOopDesc::highest_unused_vtable_index_value - sentinel_slop; assert(VM_INDEX_UNINITIALIZED < sentinel_limit, "Java sentinel != JVM sentinels"); #endif - if (sun_dyn_MemberName::vmindex(mname()) != VM_INDEX_UNINITIALIZED) + if (java_lang_invoke_MemberName::vmindex(mname()) != VM_INDEX_UNINITIALIZED) return; // already resolved - oop defc_oop = sun_dyn_MemberName::clazz(mname()); - oop name_str = sun_dyn_MemberName::name(mname()); - oop type_str = sun_dyn_MemberName::type(mname()); - int flags = sun_dyn_MemberName::flags(mname()); + oop defc_oop = java_lang_invoke_MemberName::clazz(mname()); + oop name_str = java_lang_invoke_MemberName::name(mname()); + oop type_str = java_lang_invoke_MemberName::type(mname()); + int flags = java_lang_invoke_MemberName::flags(mname()); if (defc_oop == NULL || name_str == NULL || type_str == NULL) { THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to resolve"); @@ -510,7 +510,7 @@ // convert the external string or reflective type to an internal signature TempNewSymbol type = convert_to_signature(type_str, polymorphic_signature, CHECK); - if (java_dyn_MethodType::is_instance(type_str) && polymorphic_signature) { + if (java_lang_invoke_MethodType::is_instance(type_str) && polymorphic_signature) { polymorphic_method_type = Handle(THREAD, type_str); //preserve exactly } @@ -557,9 +557,9 @@ vmtarget = result.resolved_klass()->as_klassOop(); } int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS); - sun_dyn_MemberName::set_vmtarget(mname(), vmtarget); - sun_dyn_MemberName::set_vmindex(mname(), vmindex); - sun_dyn_MemberName::set_modifiers(mname(), mods); + java_lang_invoke_MemberName::set_vmtarget(mname(), vmtarget); + java_lang_invoke_MemberName::set_vmindex(mname(), vmindex); + java_lang_invoke_MemberName::set_modifiers(mname(), mods); DEBUG_ONLY(int junk; klassOop junk2); assert(decode_MemberName(mname(), junk2, junk) == result.resolved_method()(), "properly stored for later decoding"); @@ -586,9 +586,9 @@ oop vmtarget = m(); int vmindex = methodOopDesc::nonvirtual_vtable_index; int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS); - sun_dyn_MemberName::set_vmtarget(mname(), vmtarget); - sun_dyn_MemberName::set_vmindex(mname(), vmindex); - sun_dyn_MemberName::set_modifiers(mname(), mods); + java_lang_invoke_MemberName::set_vmtarget(mname(), vmtarget); + java_lang_invoke_MemberName::set_vmindex(mname(), vmindex); + java_lang_invoke_MemberName::set_modifiers(mname(), mods); DEBUG_ONLY(int junk; klassOop junk2); assert(decode_MemberName(mname(), junk2, junk) == result.resolved_method()(), "properly stored for later decoding"); @@ -605,9 +605,9 @@ int vmindex = fd.offset(); int mods = (fd.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS); if (vmindex == VM_INDEX_UNINITIALIZED) break; // should not happen - sun_dyn_MemberName::set_vmtarget(mname(), vmtarget); - sun_dyn_MemberName::set_vmindex(mname(), vmindex); - sun_dyn_MemberName::set_modifiers(mname(), mods); + java_lang_invoke_MemberName::set_vmtarget(mname(), vmtarget); + java_lang_invoke_MemberName::set_vmindex(mname(), vmindex); + java_lang_invoke_MemberName::set_modifiers(mname(), mods); return; } default: @@ -618,11 +618,11 @@ if (polymorphic_method_type.not_null()) { // Look on a non-null class loader. Handle cur_class_loader; - const int nptypes = java_dyn_MethodType::ptype_count(polymorphic_method_type()); + const int nptypes = java_lang_invoke_MethodType::ptype_count(polymorphic_method_type()); for (int i = 0; i <= nptypes; i++) { oop type_mirror; - if (i < nptypes) type_mirror = java_dyn_MethodType::ptype(polymorphic_method_type(), i); - else type_mirror = java_dyn_MethodType::rtype(polymorphic_method_type()); + if (i < nptypes) type_mirror = java_lang_invoke_MethodType::ptype(polymorphic_method_type(), i); + else type_mirror = java_lang_invoke_MethodType::rtype(polymorphic_method_type()); klassOop example_type = java_lang_Class::as_klassOop(type_mirror); if (example_type == NULL) continue; oop class_loader = Klass::cast(example_type)->class_loader(); @@ -639,9 +639,9 @@ } if (m != NULL) { int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS); - sun_dyn_MemberName::set_vmtarget(mname(), m); - sun_dyn_MemberName::set_vmindex(mname(), m->vtable_index()); - sun_dyn_MemberName::set_modifiers(mname(), mods); + java_lang_invoke_MemberName::set_vmtarget(mname(), m); + java_lang_invoke_MemberName::set_vmindex(mname(), m->vtable_index()); + java_lang_invoke_MemberName::set_modifiers(mname(), mods); return; } } @@ -653,17 +653,17 @@ // Resolving it plants a vmtarget/vmindex in it, // which refers directly to JVM internals. void MethodHandles::expand_MemberName(Handle mname, int suppress, TRAPS) { - assert(sun_dyn_MemberName::is_instance(mname()), ""); - oop vmtarget = sun_dyn_MemberName::vmtarget(mname()); - int vmindex = sun_dyn_MemberName::vmindex(mname()); + assert(java_lang_invoke_MemberName::is_instance(mname()), ""); + oop vmtarget = java_lang_invoke_MemberName::vmtarget(mname()); + int vmindex = java_lang_invoke_MemberName::vmindex(mname()); if (vmtarget == NULL || vmindex == VM_INDEX_UNINITIALIZED) { THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to expand"); } - bool have_defc = (sun_dyn_MemberName::clazz(mname()) != NULL); - bool have_name = (sun_dyn_MemberName::name(mname()) != NULL); - bool have_type = (sun_dyn_MemberName::type(mname()) != NULL); - int flags = sun_dyn_MemberName::flags(mname()); + bool have_defc = (java_lang_invoke_MemberName::clazz(mname()) != NULL); + bool have_name = (java_lang_invoke_MemberName::name(mname()) != NULL); + bool have_type = (java_lang_invoke_MemberName::type(mname()) != NULL); + int flags = java_lang_invoke_MemberName::flags(mname()); if (suppress != 0) { if (suppress & _suppress_defc) have_defc = true; @@ -687,16 +687,16 @@ if (receiver_limit != NULL && receiver_limit != defc && Klass::cast(receiver_limit)->is_subtype_of(defc)) defc = receiver_limit; - sun_dyn_MemberName::set_clazz(mname(), Klass::cast(defc)->java_mirror()); + java_lang_invoke_MemberName::set_clazz(mname(), Klass::cast(defc)->java_mirror()); } if (!have_name) { //not java_lang_String::create_from_symbol; let's intern member names Handle name = StringTable::intern(m->name(), CHECK); - sun_dyn_MemberName::set_name(mname(), name()); + java_lang_invoke_MemberName::set_name(mname(), name()); } if (!have_type) { Handle type = java_lang_String::create_from_symbol(m->signature(), CHECK); - sun_dyn_MemberName::set_type(mname(), type()); + java_lang_invoke_MemberName::set_type(mname(), type()); } return; } @@ -711,16 +711,16 @@ if (!defc->find_field_from_offset(vmindex, is_static, &fd)) break; // cannot expand if (!have_defc) { - sun_dyn_MemberName::set_clazz(mname(), defc->java_mirror()); + java_lang_invoke_MemberName::set_clazz(mname(), defc->java_mirror()); } if (!have_name) { //not java_lang_String::create_from_symbol; let's intern member names Handle name = StringTable::intern(fd.name(), CHECK); - sun_dyn_MemberName::set_name(mname(), name()); + java_lang_invoke_MemberName::set_name(mname(), name()); } if (!have_type) { Handle type = java_lang_String::create_from_symbol(fd.signature(), CHECK); - sun_dyn_MemberName::set_type(mname(), type()); + java_lang_invoke_MemberName::set_type(mname(), type()); } return; } @@ -775,7 +775,7 @@ --rskip; } else if (rfill < rlimit) { oop result = results->obj_at(rfill++); - if (!sun_dyn_MemberName::is_instance(result)) + if (!java_lang_invoke_MemberName::is_instance(result)) return -99; // caller bug! MethodHandles::init_MemberName(result, st.klass()->as_klassOop(), st.access_flags(), st.offset()); } else if (++overflow >= overflow_limit) { @@ -823,7 +823,7 @@ --rskip; } else if (rfill < rlimit) { oop result = results->obj_at(rfill++); - if (!sun_dyn_MemberName::is_instance(result)) + if (!java_lang_invoke_MemberName::is_instance(result)) return -99; // caller bug! MethodHandles::init_MemberName(result, m, true); } else if (++overflow >= overflow_limit) { @@ -857,9 +857,9 @@ // Sanitize out methodOops, klassOops, and any other non-Java data. // This is for debugging and reflection. oop MethodHandles::encode_target(Handle mh, int format, TRAPS) { - assert(java_dyn_MethodHandle::is_instance(mh()), "must be a MH"); + assert(java_lang_invoke_MethodHandle::is_instance(mh()), "must be a MH"); if (format == ETF_HANDLE_OR_METHOD_NAME) { - oop target = java_dyn_MethodHandle::vmtarget(mh()); + oop target = java_lang_invoke_MethodHandle::vmtarget(mh()); if (target == NULL) { return NULL; // unformed MH } @@ -874,10 +874,10 @@ if (target->klass() == SystemDictionary::DirectMethodHandle_klass()) { return target; } - if (!java_dyn_MethodHandle::is_instance(target)){ + if (!java_lang_invoke_MethodHandle::is_instance(target)){ return NULL; // unformed MH } - target = java_dyn_MethodHandle::vmtarget(target); + target = java_lang_invoke_MethodHandle::vmtarget(target); } } // cases of metadata in MH.vmtarget: @@ -904,7 +904,7 @@ instanceKlassHandle mname_klass(THREAD, SystemDictionary::MemberName_klass()); mname_klass->initialize(CHECK_NULL); Handle mname = mname_klass->allocate_instance_handle(CHECK_NULL); - sun_dyn_MemberName::set_vmindex(mname(), VM_INDEX_UNINITIALIZED); + java_lang_invoke_MemberName::set_vmindex(mname(), VM_INDEX_UNINITIALIZED); bool do_dispatch = ((decode_flags & MethodHandles::_dmf_does_dispatch) != 0); init_MemberName(mname(), m, do_dispatch); expand_MemberName(mname, 0, CHECK_NULL); @@ -923,6 +923,7 @@ "java/lang/Null", //"java/lang/Nothing", "sun/dyn/empty/Empty", + "sun/invoke/empty/Empty", NULL }; @@ -1025,7 +1026,7 @@ int first_ptype_pos, KlassHandle insert_ptype, TRAPS) { - objArrayHandle ptypes(THREAD, java_dyn_MethodType::ptypes(mtype())); + objArrayHandle ptypes(THREAD, java_lang_invoke_MethodType::ptypes(mtype())); int pnum = first_ptype_pos; int pmax = ptypes->length(); int mnum = 0; // method argument @@ -1036,7 +1037,7 @@ if (ss.at_return_type()) { if (pnum != pmax) { err = "too many arguments"; break; } - ptype_oop = java_dyn_MethodType::rtype(mtype()); + ptype_oop = java_lang_invoke_MethodType::rtype(mtype()); } else { if (pnum >= pmax) { err = "not enough arguments"; break; } @@ -1111,7 +1112,7 @@ } if (m_needs_receiver && err == NULL) { - objArrayOop ptypes = java_dyn_MethodType::ptypes(mtype()); + objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(mtype()); if (ptypes->length() < first_ptype_pos) { err = "receiver argument is missing"; goto die; } if (has_bound_recv) @@ -1131,15 +1132,15 @@ void MethodHandles::verify_vmslots(Handle mh, TRAPS) { // Verify vmslots. - int check_slots = argument_slot_count(java_dyn_MethodHandle::type(mh())); - if (java_dyn_MethodHandle::vmslots(mh()) != check_slots) { + int check_slots = argument_slot_count(java_lang_invoke_MethodHandle::type(mh())); + if (java_lang_invoke_MethodHandle::vmslots(mh()) != check_slots) { THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in BMH"); } } void MethodHandles::verify_vmargslot(Handle mh, int argnum, int argslot, TRAPS) { // Verify that argslot points at the given argnum. - int check_slot = argument_slot(java_dyn_MethodHandle::type(mh()), argnum); + int check_slot = argument_slot(java_lang_invoke_MethodHandle::type(mh()), argnum); if (argslot != check_slot || argslot < 0) { const char* fmt = "for argnum of %d, vmargslot is %d, should be %d"; size_t msglen = strlen(fmt) + 3*11 + 1; @@ -1160,8 +1161,8 @@ int delete_argnum, oop dst_mtype, int dst_beg, int dst_end, bool raw) { - objArrayOop src_ptypes = java_dyn_MethodType::ptypes(src_mtype); - objArrayOop dst_ptypes = java_dyn_MethodType::ptypes(dst_mtype); + objArrayOop src_ptypes = java_lang_invoke_MethodType::ptypes(src_mtype); + objArrayOop dst_ptypes = java_lang_invoke_MethodType::ptypes(dst_mtype); int src_max = src_ptypes->length(); int dst_max = dst_ptypes->length(); @@ -1224,8 +1225,8 @@ } // Now compare return types also. - oop src_rtype = java_dyn_MethodType::rtype(src_mtype); - oop dst_rtype = java_dyn_MethodType::rtype(dst_mtype); + oop src_rtype = java_lang_invoke_MethodType::rtype(src_mtype); + oop dst_rtype = java_lang_invoke_MethodType::rtype(dst_mtype); if (src_rtype != dst_rtype) { err = check_return_type_change(dst_rtype, src_rtype, raw); // note reversal! if (err != NULL) return err; @@ -1314,7 +1315,7 @@ // then return a negative number. Otherwise, the result // is in the range [0..vmslots] inclusive. int MethodHandles::argument_slot(oop method_type, int arg) { - objArrayOop ptypes = java_dyn_MethodType::ptypes(method_type); + objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(method_type); int argslot = 0; int len = ptypes->length(); if (arg < -1 || arg >= len) return -99; @@ -1328,7 +1329,7 @@ // Given a slot number, return the argument number. int MethodHandles::argument_slot_to_argnum(oop method_type, int query_argslot) { - objArrayOop ptypes = java_dyn_MethodType::ptypes(method_type); + objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(method_type); int argslot = 0; int len = ptypes->length(); for (int i = len-1; i >= 0; i--) { @@ -1394,11 +1395,11 @@ void MethodHandles::verify_DirectMethodHandle(Handle mh, methodHandle m, TRAPS) { // Verify type. - Handle mtype(THREAD, java_dyn_MethodHandle::type(mh())); + Handle mtype(THREAD, java_lang_invoke_MethodHandle::type(mh())); verify_method_type(m, mtype, false, KlassHandle(), CHECK); // Verify vmslots. - if (java_dyn_MethodHandle::vmslots(mh()) != m->size_of_parameters()) { + if (java_lang_invoke_MethodHandle::vmslots(mh()) != m->size_of_parameters()) { THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in DMH"); } } @@ -1410,7 +1411,7 @@ THROW(vmSymbols::java_lang_InternalError()); } - java_dyn_MethodHandle::init_vmslots(mh()); + java_lang_invoke_MethodHandle::init_vmslots(mh()); if (VerifyMethodHandles) { // The privileged code which invokes this routine should not make @@ -1470,8 +1471,8 @@ if (me == NULL) { THROW(vmSymbols::java_lang_InternalError()); } - sun_dyn_DirectMethodHandle::set_vmtarget(mh(), vmtarget); - sun_dyn_DirectMethodHandle::set_vmindex(mh(), vmindex); + java_lang_invoke_DirectMethodHandle::set_vmtarget(mh(), vmtarget); + java_lang_invoke_DirectMethodHandle::set_vmindex(mh(), vmindex); DEBUG_ONLY(int flags; klassOop rlimit); assert(MethodHandles::decode_method(mh(), rlimit, flags) == m(), "properly stored for later decoding"); @@ -1482,15 +1483,15 @@ assert(decode_MethodHandle_stack_pushes(mh()) == 0, "DMH does not move stack"); // Done! - java_dyn_MethodHandle::set_vmentry(mh(), me); + java_lang_invoke_MethodHandle::set_vmentry(mh(), me); } void MethodHandles::verify_BoundMethodHandle_with_receiver(Handle mh, methodHandle m, TRAPS) { // Verify type. - oop receiver = sun_dyn_BoundMethodHandle::argument(mh()); - Handle mtype(THREAD, java_dyn_MethodHandle::type(mh())); + oop receiver = java_lang_invoke_BoundMethodHandle::argument(mh()); + Handle mtype(THREAD, java_lang_invoke_MethodHandle::type(mh())); KlassHandle bound_recv_type; if (receiver != NULL) bound_recv_type = KlassHandle(THREAD, receiver->klass()); verify_method_type(m, mtype, true, bound_recv_type, CHECK); @@ -1498,11 +1499,11 @@ int receiver_pos = m->size_of_parameters() - 1; // Verify MH.vmargslot, which should point at the bound receiver. - verify_vmargslot(mh, -1, sun_dyn_BoundMethodHandle::vmargslot(mh()), CHECK); + verify_vmargslot(mh, -1, java_lang_invoke_BoundMethodHandle::vmargslot(mh()), CHECK); //verify_vmslots(mh, CHECK); // Verify vmslots. - if (java_dyn_MethodHandle::vmslots(mh()) != receiver_pos) { + if (java_lang_invoke_MethodHandle::vmslots(mh()) != receiver_pos) { THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in BMH (receiver)"); } } @@ -1520,7 +1521,7 @@ KlassHandle receiver_klass; { - oop receiver_oop = sun_dyn_BoundMethodHandle::argument(mh()); + oop receiver_oop = java_lang_invoke_BoundMethodHandle::argument(mh()); if (receiver_oop != NULL) receiver_klass = KlassHandle(THREAD, receiver_oop->klass()); } @@ -1531,31 +1532,31 @@ if (m.is_null()) { THROW(vmSymbols::java_lang_InternalError()); } if (m->is_abstract()) { THROW(vmSymbols::java_lang_AbstractMethodError()); } - java_dyn_MethodHandle::init_vmslots(mh()); + java_lang_invoke_MethodHandle::init_vmslots(mh()); if (VerifyMethodHandles) { verify_BoundMethodHandle_with_receiver(mh, m, CHECK); } - sun_dyn_BoundMethodHandle::set_vmtarget(mh(), m()); + java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), m()); DEBUG_ONLY(int junk; klassOop junk2); assert(MethodHandles::decode_method(mh(), junk2, junk) == m(), "properly stored for later decoding"); assert(decode_MethodHandle_stack_pushes(mh()) == 1, "BMH pushes one stack slot"); // Done! - java_dyn_MethodHandle::set_vmentry(mh(), MethodHandles::entry(MethodHandles::_bound_ref_direct_mh)); + java_lang_invoke_MethodHandle::set_vmentry(mh(), MethodHandles::entry(MethodHandles::_bound_ref_direct_mh)); } void MethodHandles::verify_BoundMethodHandle(Handle mh, Handle target, int argnum, bool direct_to_method, TRAPS) { Handle ptype_handle(THREAD, - java_dyn_MethodType::ptype(java_dyn_MethodHandle::type(target()), argnum)); + java_lang_invoke_MethodType::ptype(java_lang_invoke_MethodHandle::type(target()), argnum)); KlassHandle ptype_klass; BasicType ptype = java_lang_Class::as_BasicType(ptype_handle(), &ptype_klass); int slots_pushed = type2size[ptype]; - oop argument = sun_dyn_BoundMethodHandle::argument(mh()); + oop argument = java_lang_invoke_BoundMethodHandle::argument(mh()); const char* err = NULL; @@ -1623,9 +1624,9 @@ if (err == NULL) { // Verify the rest of the method type. - err = check_method_type_insertion(java_dyn_MethodHandle::type(mh()), + err = check_method_type_insertion(java_lang_invoke_MethodHandle::type(mh()), argnum, ptype_handle(), - java_dyn_MethodHandle::type(target())); + java_lang_invoke_MethodHandle::type(target())); } if (err != NULL) { @@ -1635,20 +1636,20 @@ void MethodHandles::init_BoundMethodHandle(Handle mh, Handle target, int argnum, TRAPS) { // Check arguments. - if (mh.is_null() || target.is_null() || !java_dyn_MethodHandle::is_instance(target())) { + if (mh.is_null() || target.is_null() || !java_lang_invoke_MethodHandle::is_instance(target())) { THROW(vmSymbols::java_lang_InternalError()); } - java_dyn_MethodHandle::init_vmslots(mh()); + java_lang_invoke_MethodHandle::init_vmslots(mh()); if (VerifyMethodHandles) { int insert_after = argnum - 1; - verify_vmargslot(mh, insert_after, sun_dyn_BoundMethodHandle::vmargslot(mh()), CHECK); + verify_vmargslot(mh, insert_after, java_lang_invoke_BoundMethodHandle::vmargslot(mh()), CHECK); verify_vmslots(mh, CHECK); } // Get bound type and required slots. - oop ptype_oop = java_dyn_MethodType::ptype(java_dyn_MethodHandle::type(target()), argnum); + oop ptype_oop = java_lang_invoke_MethodType::ptype(java_lang_invoke_MethodHandle::type(target()), argnum); BasicType ptype = java_lang_Class::as_BasicType(ptype_oop); int slots_pushed = type2size[ptype]; @@ -1659,12 +1660,12 @@ bool direct_to_method = false; if (OptimizeMethodHandles && target->klass() == SystemDictionary::DirectMethodHandle_klass() && - (argnum == 0 || sun_dyn_DirectMethodHandle::vmindex(target()) < 0)) { + (argnum == 0 || java_lang_invoke_DirectMethodHandle::vmindex(target()) < 0)) { int decode_flags = 0; klassOop receiver_limit_oop = NULL; methodHandle m(THREAD, decode_method(target(), receiver_limit_oop, decode_flags)); if (m.is_null()) { THROW_MSG(vmSymbols::java_lang_InternalError(), "DMH failed to decode"); } DEBUG_ONLY(int m_vmslots = m->size_of_parameters() - slots_pushed); // pos. of 1st arg. - assert(sun_dyn_BoundMethodHandle::vmslots(mh()) == m_vmslots, "type w/ m sig"); + assert(java_lang_invoke_BoundMethodHandle::vmslots(mh()) == m_vmslots, "type w/ m sig"); if (argnum == 0 && (decode_flags & _dmf_has_receiver) != 0) { KlassHandle receiver_limit(THREAD, receiver_limit_oop); init_BoundMethodHandle_with_receiver(mh, m, @@ -1677,11 +1678,11 @@ // to bind another argument and still invoke the methodOop directly. if (!(decode_flags & _dmf_does_dispatch)) { direct_to_method = true; - sun_dyn_BoundMethodHandle::set_vmtarget(mh(), m()); + java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), m()); } } if (!direct_to_method) - sun_dyn_BoundMethodHandle::set_vmtarget(mh(), target()); + java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), target()); if (VerifyMethodHandles) { verify_BoundMethodHandle(mh, target, argnum, direct_to_method, CHECK); @@ -1703,7 +1704,7 @@ } // Done! - java_dyn_MethodHandle::set_vmentry(mh(), me); + java_lang_invoke_MethodHandle::set_vmentry(mh(), me); } static void throw_InternalError_for_bad_conversion(int conversion, const char* err, TRAPS) { @@ -1713,8 +1714,8 @@ } void MethodHandles::verify_AdapterMethodHandle(Handle mh, int argnum, TRAPS) { - jint conversion = sun_dyn_AdapterMethodHandle::conversion(mh()); - int argslot = sun_dyn_AdapterMethodHandle::vmargslot(mh()); + jint conversion = java_lang_invoke_AdapterMethodHandle::conversion(mh()); + int argslot = java_lang_invoke_AdapterMethodHandle::vmargslot(mh()); verify_vmargslot(mh, argnum, argslot, CHECK); verify_vmslots(mh, CHECK); @@ -1731,10 +1732,10 @@ BasicType dest = adapter_conversion_dest_type(conversion); int vminfo = adapter_conversion_vminfo(conversion); // should be zero - Handle argument(THREAD, sun_dyn_AdapterMethodHandle::argument(mh())); - Handle target(THREAD, sun_dyn_AdapterMethodHandle::vmtarget(mh())); - Handle src_mtype(THREAD, java_dyn_MethodHandle::type(mh())); - Handle dst_mtype(THREAD, java_dyn_MethodHandle::type(target())); + Handle argument(THREAD, java_lang_invoke_AdapterMethodHandle::argument(mh())); + Handle target(THREAD, java_lang_invoke_AdapterMethodHandle::vmtarget(mh())); + Handle src_mtype(THREAD, java_lang_invoke_MethodHandle::type(mh())); + Handle dst_mtype(THREAD, java_lang_invoke_MethodHandle::type(target())); const char* err = NULL; @@ -1760,7 +1761,7 @@ break; case _adapter_flyby: case _adapter_ricochet: - if (!java_dyn_MethodHandle::is_instance(argument())) + if (!java_lang_invoke_MethodHandle::is_instance(argument())) { err = "MethodHandle adapter argument required"; break; } break; default: @@ -1806,9 +1807,9 @@ err = "adapter requires src/dest conversion subfields for swap"; break; } int swap_size = type2size[src]; - oop src_mtype = sun_dyn_AdapterMethodHandle::type(mh()); - oop dest_mtype = sun_dyn_AdapterMethodHandle::type(target()); - int slot_limit = sun_dyn_AdapterMethodHandle::vmslots(target()); + oop src_mtype = java_lang_invoke_AdapterMethodHandle::type(mh()); + oop dest_mtype = java_lang_invoke_AdapterMethodHandle::type(target()); + int slot_limit = java_lang_invoke_AdapterMethodHandle::vmslots(target()); int src_slot = argslot; int dest_slot = vminfo; bool rotate_up = (src_slot > dest_slot); // upward rotation @@ -1821,8 +1822,8 @@ } else if (ek == _adapter_swap_args && !(src_slot > dest_slot)) { err = "source of swap must be deeper in stack"; } else if (ek == _adapter_swap_args) { - err = check_argument_type_change(java_dyn_MethodType::ptype(src_mtype, dest_arg), - java_dyn_MethodType::ptype(dest_mtype, src_arg), + err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, dest_arg), + java_lang_invoke_MethodType::ptype(dest_mtype, src_arg), dest_arg); } else if (ek == _adapter_rot_args) { if (rotate_up) { @@ -1830,8 +1831,8 @@ // rotate up: [dest_slot..src_slot-ss] --> [dest_slot+ss..src_slot] // that is: [src_arg+1..dest_arg] --> [src_arg..dest_arg-1] for (int i = src_arg+1; i <= dest_arg && err == NULL; i++) { - err = check_argument_type_change(java_dyn_MethodType::ptype(src_mtype, i), - java_dyn_MethodType::ptype(dest_mtype, i-1), + err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, i), + java_lang_invoke_MethodType::ptype(dest_mtype, i-1), i); } } else { // rotate down @@ -1839,15 +1840,15 @@ // rotate down: [src_slot+ss..dest_slot] --> [src_slot..dest_slot-ss] // that is: [dest_arg..src_arg-1] --> [dst_arg+1..src_arg] for (int i = dest_arg; i <= src_arg-1 && err == NULL; i++) { - err = check_argument_type_change(java_dyn_MethodType::ptype(src_mtype, i), - java_dyn_MethodType::ptype(dest_mtype, i+1), + err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, i), + java_lang_invoke_MethodType::ptype(dest_mtype, i+1), i); } } } if (err == NULL) - err = check_argument_type_change(java_dyn_MethodType::ptype(src_mtype, src_arg), - java_dyn_MethodType::ptype(dest_mtype, dest_arg), + err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, src_arg), + java_lang_invoke_MethodType::ptype(dest_mtype, dest_arg), src_arg); } break; @@ -1918,8 +1919,8 @@ if (err == NULL) { // Make sure this adapter does not push too deeply. int slots_pushed = stack_move / stack_move_unit(); - int this_vmslots = java_dyn_MethodHandle::vmslots(mh()); - int target_vmslots = java_dyn_MethodHandle::vmslots(target()); + int this_vmslots = java_lang_invoke_MethodHandle::vmslots(mh()); + int target_vmslots = java_lang_invoke_MethodHandle::vmslots(target()); if (slots_pushed != (target_vmslots - this_vmslots)) { err = "stack_move inconsistent with previous and current MethodType vmslots"; } else if (slots_pushed > 0) { @@ -1961,7 +1962,7 @@ case _adapter_check_cast: { // The actual value being checked must be a reference: - err = check_argument_type_change(java_dyn_MethodType::ptype(src_mtype(), argnum), + err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype(), argnum), object_java_mirror(), argnum); if (err != NULL) break; @@ -1985,9 +1986,9 @@ } void MethodHandles::init_AdapterMethodHandle(Handle mh, Handle target, int argnum, TRAPS) { - oop argument = sun_dyn_AdapterMethodHandle::argument(mh()); - int argslot = sun_dyn_AdapterMethodHandle::vmargslot(mh()); - jint conversion = sun_dyn_AdapterMethodHandle::conversion(mh()); + oop argument = java_lang_invoke_AdapterMethodHandle::argument(mh()); + int argslot = java_lang_invoke_AdapterMethodHandle::vmargslot(mh()); + jint conversion = java_lang_invoke_AdapterMethodHandle::conversion(mh()); jint conv_op = adapter_conversion_op(conversion); // adjust the adapter code to the internal EntryKind enumeration: @@ -1995,11 +1996,11 @@ EntryKind ek_opt = ek_orig; // may be optimized // Finalize the vmtarget field (Java initialized it to null). - if (!java_dyn_MethodHandle::is_instance(target())) { + if (!java_lang_invoke_MethodHandle::is_instance(target())) { throw_InternalError_for_bad_conversion(conversion, "bad target", THREAD); return; } - sun_dyn_AdapterMethodHandle::set_vmtarget(mh(), target()); + java_lang_invoke_AdapterMethodHandle::set_vmtarget(mh(), target()); if (VerifyMethodHandles) { verify_AdapterMethodHandle(mh, argnum, CHECK); @@ -2083,7 +2084,7 @@ case _adapter_rot_args: { int swap_slots = type2size[src]; - int slot_limit = sun_dyn_AdapterMethodHandle::vmslots(mh()); + int slot_limit = java_lang_invoke_AdapterMethodHandle::vmslots(mh()); int src_slot = argslot; int dest_slot = vminfo; int rotate = (ek_orig == _adapter_swap_args) ? 0 : (src_slot > dest_slot) ? 1 : -1; @@ -2147,10 +2148,10 @@ jint new_conversion = adapter_conversion(conv_op, src, dest, stack_move, vminfo); // Finalize the conversion field. (Note that it is final to Java code.) - sun_dyn_AdapterMethodHandle::set_conversion(mh(), new_conversion); + java_lang_invoke_AdapterMethodHandle::set_conversion(mh(), new_conversion); // Done! - java_dyn_MethodHandle::set_vmentry(mh(), entry(ek_opt)); + java_lang_invoke_MethodHandle::set_vmentry(mh(), entry(ek_opt)); // There should be enough memory barriers on exit from native methods // to ensure that the MH is fully initialized to all threads before @@ -2158,7 +2159,7 @@ } // -// Here are the native methods on sun.dyn.MethodHandleImpl. +// Here are the native methods on sun.invoke.MethodHandleImpl. // They are the private interface between this JVM and the HotSpot-specific // Java code that implements JSR 292 method handles. // @@ -2168,7 +2169,7 @@ // direct method handles for invokestatic or invokespecial // void init(DirectMethodHandle self, MemberName ref, boolean doDispatch, Class<?> caller); -JVM_ENTRY(void, MHI_init_DMH(JNIEnv *env, jobject igcls, jobject mh_jh, +JVM_ENTRY(void, MHN_init_DMH(JNIEnv *env, jobject igcls, jobject mh_jh, jobject target_jh, jboolean do_dispatch, jobject caller_jh)) { ResourceMark rm; // for error messages @@ -2177,13 +2178,13 @@ Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); // Early returns out of this method leave the DMH in an unfinished state. - assert(java_dyn_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); + assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); // which method are we really talking about? if (target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } oop target_oop = JNIHandles::resolve_non_null(target_jh); - if (sun_dyn_MemberName::is_instance(target_oop) && - sun_dyn_MemberName::vmindex(target_oop) == VM_INDEX_UNINITIALIZED) { + if (java_lang_invoke_MemberName::is_instance(target_oop) && + java_lang_invoke_MemberName::vmindex(target_oop) == VM_INDEX_UNINITIALIZED) { Handle mname(THREAD, target_oop); MethodHandles::resolve_MemberName(mname, CHECK); target_oop = mname(); // in case of GC @@ -2232,7 +2233,7 @@ JVM_END // bound method handles -JVM_ENTRY(void, MHI_init_BMH(JNIEnv *env, jobject igcls, jobject mh_jh, +JVM_ENTRY(void, MHN_init_BMH(JNIEnv *env, jobject igcls, jobject mh_jh, jobject target_jh, int argnum)) { ResourceMark rm; // for error messages @@ -2241,12 +2242,12 @@ Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); // Early returns out of this method leave the BMH in an unfinished state. - assert(java_dyn_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); + assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); if (target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } Handle target(THREAD, JNIHandles::resolve_non_null(target_jh)); - if (!java_dyn_MethodHandle::is_instance(target())) { + if (!java_lang_invoke_MethodHandle::is_instance(target())) { // Target object is a reflective method. (%%% Do we need this alternate path?) Untested("init_BMH of non-MH"); if (argnum != 0) { THROW(vmSymbols::java_lang_InternalError()); } @@ -2269,7 +2270,7 @@ JVM_END // adapter method handles -JVM_ENTRY(void, MHI_init_AMH(JNIEnv *env, jobject igcls, jobject mh_jh, +JVM_ENTRY(void, MHN_init_AMH(JNIEnv *env, jobject igcls, jobject mh_jh, jobject target_jh, int argnum)) { // This is the guy we are initializing: if (mh_jh == NULL || target_jh == NULL) { @@ -2279,14 +2280,14 @@ Handle target(THREAD, JNIHandles::resolve_non_null(target_jh)); // Early returns out of this method leave the AMH in an unfinished state. - assert(java_dyn_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); + assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); MethodHandles::init_AdapterMethodHandle(mh, target, argnum, CHECK); } JVM_END // method type forms -JVM_ENTRY(void, MHI_init_MT(JNIEnv *env, jobject igcls, jobject erased_jh)) { +JVM_ENTRY(void, MHN_init_MT(JNIEnv *env, jobject igcls, jobject erased_jh)) { if (erased_jh == NULL) return; if (TraceMethodHandles) { tty->print("creating MethodType form "); @@ -2307,9 +2308,9 @@ JVM_END // debugging and reflection -JVM_ENTRY(jobject, MHI_getTarget(JNIEnv *env, jobject igcls, jobject mh_jh, jint format)) { +JVM_ENTRY(jobject, MHN_getTarget(JNIEnv *env, jobject igcls, jobject mh_jh, jint format)) { Handle mh(THREAD, JNIHandles::resolve(mh_jh)); - if (!java_dyn_MethodHandle::is_instance(mh())) { + if (!java_lang_invoke_MethodHandle::is_instance(mh())) { THROW_NULL(vmSymbols::java_lang_IllegalArgumentException()); } oop target = MethodHandles::encode_target(mh, format, CHECK_NULL); @@ -2317,7 +2318,7 @@ } JVM_END -JVM_ENTRY(jint, MHI_getConstant(JNIEnv *env, jobject igcls, jint which)) { +JVM_ENTRY(jint, MHN_getConstant(JNIEnv *env, jobject igcls, jint which)) { switch (which) { case MethodHandles::GC_JVM_PUSH_LIMIT: guarantee(MethodHandlePushLimit >= 2 && MethodHandlePushLimit <= 0xFF, @@ -2341,36 +2342,36 @@ template(MethodHandles,ETF_DIRECT_HANDLE) \ template(MethodHandles,ETF_METHOD_NAME) \ template(MethodHandles,ETF_REFLECT_METHOD) \ - template(sun_dyn_MemberName,MN_IS_METHOD) \ - template(sun_dyn_MemberName,MN_IS_CONSTRUCTOR) \ - template(sun_dyn_MemberName,MN_IS_FIELD) \ - template(sun_dyn_MemberName,MN_IS_TYPE) \ - template(sun_dyn_MemberName,MN_SEARCH_SUPERCLASSES) \ - template(sun_dyn_MemberName,MN_SEARCH_INTERFACES) \ - template(sun_dyn_MemberName,VM_INDEX_UNINITIALIZED) \ - template(sun_dyn_AdapterMethodHandle,OP_RETYPE_ONLY) \ - template(sun_dyn_AdapterMethodHandle,OP_RETYPE_RAW) \ - template(sun_dyn_AdapterMethodHandle,OP_CHECK_CAST) \ - template(sun_dyn_AdapterMethodHandle,OP_PRIM_TO_PRIM) \ - template(sun_dyn_AdapterMethodHandle,OP_REF_TO_PRIM) \ - template(sun_dyn_AdapterMethodHandle,OP_PRIM_TO_REF) \ - template(sun_dyn_AdapterMethodHandle,OP_SWAP_ARGS) \ - template(sun_dyn_AdapterMethodHandle,OP_ROT_ARGS) \ - template(sun_dyn_AdapterMethodHandle,OP_DUP_ARGS) \ - template(sun_dyn_AdapterMethodHandle,OP_DROP_ARGS) \ - template(sun_dyn_AdapterMethodHandle,OP_COLLECT_ARGS) \ - template(sun_dyn_AdapterMethodHandle,OP_SPREAD_ARGS) \ - template(sun_dyn_AdapterMethodHandle,OP_FLYBY) \ - template(sun_dyn_AdapterMethodHandle,OP_RICOCHET) \ - template(sun_dyn_AdapterMethodHandle,CONV_OP_LIMIT) \ - template(sun_dyn_AdapterMethodHandle,CONV_OP_MASK) \ - template(sun_dyn_AdapterMethodHandle,CONV_VMINFO_MASK) \ - template(sun_dyn_AdapterMethodHandle,CONV_VMINFO_SHIFT) \ - template(sun_dyn_AdapterMethodHandle,CONV_OP_SHIFT) \ - template(sun_dyn_AdapterMethodHandle,CONV_DEST_TYPE_SHIFT) \ - template(sun_dyn_AdapterMethodHandle,CONV_SRC_TYPE_SHIFT) \ - template(sun_dyn_AdapterMethodHandle,CONV_STACK_MOVE_SHIFT) \ - template(sun_dyn_AdapterMethodHandle,CONV_STACK_MOVE_MASK) \ + template(java_lang_invoke_MemberName,MN_IS_METHOD) \ + template(java_lang_invoke_MemberName,MN_IS_CONSTRUCTOR) \ + template(java_lang_invoke_MemberName,MN_IS_FIELD) \ + template(java_lang_invoke_MemberName,MN_IS_TYPE) \ + template(java_lang_invoke_MemberName,MN_SEARCH_SUPERCLASSES) \ + template(java_lang_invoke_MemberName,MN_SEARCH_INTERFACES) \ + template(java_lang_invoke_MemberName,VM_INDEX_UNINITIALIZED) \ + template(java_lang_invoke_AdapterMethodHandle,OP_RETYPE_ONLY) \ + template(java_lang_invoke_AdapterMethodHandle,OP_RETYPE_RAW) \ + template(java_lang_invoke_AdapterMethodHandle,OP_CHECK_CAST) \ + template(java_lang_invoke_AdapterMethodHandle,OP_PRIM_TO_PRIM) \ + template(java_lang_invoke_AdapterMethodHandle,OP_REF_TO_PRIM) \ + template(java_lang_invoke_AdapterMethodHandle,OP_PRIM_TO_REF) \ + template(java_lang_invoke_AdapterMethodHandle,OP_SWAP_ARGS) \ + template(java_lang_invoke_AdapterMethodHandle,OP_ROT_ARGS) \ + template(java_lang_invoke_AdapterMethodHandle,OP_DUP_ARGS) \ + template(java_lang_invoke_AdapterMethodHandle,OP_DROP_ARGS) \ + template(java_lang_invoke_AdapterMethodHandle,OP_COLLECT_ARGS) \ + template(java_lang_invoke_AdapterMethodHandle,OP_SPREAD_ARGS) \ + template(java_lang_invoke_AdapterMethodHandle,OP_FLYBY) \ + template(java_lang_invoke_AdapterMethodHandle,OP_RICOCHET) \ + template(java_lang_invoke_AdapterMethodHandle,CONV_OP_LIMIT) \ + template(java_lang_invoke_AdapterMethodHandle,CONV_OP_MASK) \ + template(java_lang_invoke_AdapterMethodHandle,CONV_VMINFO_MASK) \ + template(java_lang_invoke_AdapterMethodHandle,CONV_VMINFO_SHIFT) \ + template(java_lang_invoke_AdapterMethodHandle,CONV_OP_SHIFT) \ + template(java_lang_invoke_AdapterMethodHandle,CONV_DEST_TYPE_SHIFT) \ + template(java_lang_invoke_AdapterMethodHandle,CONV_SRC_TYPE_SHIFT) \ + template(java_lang_invoke_AdapterMethodHandle,CONV_STACK_MOVE_SHIFT) \ + template(java_lang_invoke_AdapterMethodHandle,CONV_STACK_MOVE_MASK) \ /*end*/ #define ONE_PLUS(scope,value) 1+ @@ -2386,7 +2387,7 @@ #undef EACH_NAMED_CON #endif -JVM_ENTRY(jint, MHI_getNamedCon(JNIEnv *env, jobject igcls, jint which, jobjectArray box_jh)) { +JVM_ENTRY(jint, MHN_getNamedCon(JNIEnv *env, jobject igcls, jint which, jobjectArray box_jh)) { #ifndef PRODUCT if (which >= 0 && which < con_value_count) { int con = con_values[which]; @@ -2406,7 +2407,7 @@ JVM_END // void init(MemberName self, AccessibleObject ref) -JVM_ENTRY(void, MHI_init_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jobject target_jh)) { +JVM_ENTRY(void, MHN_init_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jobject target_jh)) { if (mname_jh == NULL || target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); oop target_oop = JNIHandles::resolve_non_null(target_jh); @@ -2415,7 +2416,7 @@ JVM_END // void expand(MemberName self) -JVM_ENTRY(void, MHI_expand_Mem(JNIEnv *env, jobject igcls, jobject mname_jh)) { +JVM_ENTRY(void, MHN_expand_Mem(JNIEnv *env, jobject igcls, jobject mname_jh)) { if (mname_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); MethodHandles::expand_MemberName(mname, 0, CHECK); @@ -2423,14 +2424,14 @@ JVM_END // void resolve(MemberName self, Class<?> caller) -JVM_ENTRY(void, MHI_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jclass caller_jh)) { +JVM_ENTRY(void, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jclass caller_jh)) { if (mname_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); // The trusted Java code that calls this method should already have performed // access checks on behalf of the given caller. But, we can verify this. if (VerifyMethodHandles && caller_jh != NULL) { - klassOop reference_klass = java_lang_Class::as_klassOop(sun_dyn_MemberName::clazz(mname())); + klassOop reference_klass = java_lang_Class::as_klassOop(java_lang_invoke_MemberName::clazz(mname())); if (reference_klass != NULL) { // Emulate LinkResolver::check_klass_accessability. klassOop caller = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(caller_jh)); @@ -2448,7 +2449,7 @@ // static native int getMembers(Class<?> defc, String matchName, String matchSig, // int matchFlags, Class<?> caller, int skip, MemberName[] results); -JVM_ENTRY(jint, MHI_getMembers(JNIEnv *env, jobject igcls, +JVM_ENTRY(jint, MHN_getMembers(JNIEnv *env, jobject igcls, jclass clazz_jh, jstring name_jh, jstring sig_jh, int mflags, jclass caller_jh, jint skip, jobjectArray results_jh)) { if (clazz_jh == NULL || results_jh == NULL) return -1; @@ -2487,14 +2488,14 @@ } JVM_END -JVM_ENTRY(void, MHI_registerBootstrap(JNIEnv *env, jobject igcls, jclass caller_jh, jobject bsm_jh)) { +JVM_ENTRY(void, MHN_registerBootstrap(JNIEnv *env, jobject igcls, jclass caller_jh, jobject bsm_jh)) { instanceKlassHandle ik = MethodHandles::resolve_instance_klass(caller_jh, THREAD); if (!AllowTransitionalJSR292) { THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "registerBootstrapMethod is only supported in JSR 292 EDR"); } ik->link_class(CHECK); - if (!java_dyn_MethodHandle::is_instance(JNIHandles::resolve(bsm_jh))) { + if (!java_lang_invoke_MethodHandle::is_instance(JNIHandles::resolve(bsm_jh))) { THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "method handle"); } const char* err = NULL; @@ -2522,29 +2523,28 @@ } JVM_END -JVM_ENTRY(jobject, MHI_getBootstrap(JNIEnv *env, jobject igcls, jclass caller_jh)) { +JVM_ENTRY(jobject, MHN_getBootstrap(JNIEnv *env, jobject igcls, jclass caller_jh)) { + if (!AllowTransitionalJSR292) + THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "getBootstrap: transitional only"); instanceKlassHandle ik = MethodHandles::resolve_instance_klass(caller_jh, THREAD); return JNIHandles::make_local(THREAD, ik->bootstrap_method()); } JVM_END -JVM_ENTRY(void, MHI_setCallSiteTarget(JNIEnv *env, jobject igcls, jobject site_jh, jobject target_jh)) { - // No special action required, yet. - oop site_oop = JNIHandles::resolve(site_jh); - if (!java_dyn_CallSite::is_instance(site_oop)) - THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "not a CallSite"); - java_dyn_CallSite::set_target(site_oop, JNIHandles::resolve(target_jh)); +JVM_ENTRY(void, MHN_setCallSiteTarget(JNIEnv *env, jobject igcls, jobject site_jh, jobject target_jh)) { + if (!AllowTransitionalJSR292) + THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "setCallSite: transitional only"); } JVM_END /// JVM_RegisterMethodHandleMethods -#define ADR "J" - #define LANG "Ljava/lang/" -#define JDYN "Ljava/dyn/" -#define IDYN "Lsun/dyn/" +#define JLINV "Ljava/lang/invoke/" /* standard package */ +#define JDYN "Ljava/dyn/" /* alternative package to JLINV if AllowTransitionalJSR292 */ +#define IDYN "Lsun/dyn/" /* alternative package to JDYN if AllowTransitionalJSR292 */ +// FIXME: After AllowTransitionalJSR292 is removed, replace JDYN and IDYN by JLINV. #define OBJ LANG"Object;" #define CLS LANG"Class;" @@ -2552,7 +2552,6 @@ #define CST JDYN"CallSite;" #define MT JDYN"MethodType;" #define MH JDYN"MethodHandle;" -#define MHI IDYN"MethodHandleImpl;" #define MEM IDYN"MemberName;" #define AMH IDYN"AdapterMethodHandle;" #define BMH IDYN"BoundMethodHandle;" @@ -2561,32 +2560,58 @@ #define CC (char*) /*cast a literal from (const char*)*/ #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) -// These are the native methods on sun.dyn.MethodHandleNatives. +// These are the native methods on sun.invoke.MethodHandleNatives. static JNINativeMethod methods[] = { // void init(MemberName self, AccessibleObject ref) - {CC"init", CC"("AMH""MH"I)V", FN_PTR(MHI_init_AMH)}, - {CC"init", CC"("BMH""OBJ"I)V", FN_PTR(MHI_init_BMH)}, - {CC"init", CC"("DMH""OBJ"Z"CLS")V", FN_PTR(MHI_init_DMH)}, - {CC"init", CC"("MT")V", FN_PTR(MHI_init_MT)}, - {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHI_init_Mem)}, - {CC"expand", CC"("MEM")V", FN_PTR(MHI_expand_Mem)}, - {CC"resolve", CC"("MEM""CLS")V", FN_PTR(MHI_resolve_Mem)}, - {CC"getTarget", CC"("MH"I)"OBJ, FN_PTR(MHI_getTarget)}, - {CC"getConstant", CC"(I)I", FN_PTR(MHI_getConstant)}, + {CC"init", CC"("AMH""MH"I)V", FN_PTR(MHN_init_AMH)}, + {CC"init", CC"("BMH""OBJ"I)V", FN_PTR(MHN_init_BMH)}, + {CC"init", CC"("DMH""OBJ"Z"CLS")V", FN_PTR(MHN_init_DMH)}, + {CC"init", CC"("MT")V", FN_PTR(MHN_init_MT)}, + {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)}, + {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)}, + {CC"resolve", CC"("MEM""CLS")V", FN_PTR(MHN_resolve_Mem)}, + {CC"getTarget", CC"("MH"I)"OBJ, FN_PTR(MHN_getTarget)}, + {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, // static native int getNamedCon(int which, Object[] name) - {CC"getNamedCon", CC"(I["OBJ")I", FN_PTR(MHI_getNamedCon)}, + {CC"getNamedCon", CC"(I["OBJ")I", FN_PTR(MHN_getNamedCon)}, // static native int getMembers(Class<?> defc, String matchName, String matchSig, // int matchFlags, Class<?> caller, int skip, MemberName[] results); - {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHI_getMembers)} + {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)} }; // More entry points specifically for EnableInvokeDynamic. +// FIXME: Remove methods2 after AllowTransitionalJSR292 is removed. static JNINativeMethod methods2[] = { - {CC"registerBootstrap", CC"("CLS MH")V", FN_PTR(MHI_registerBootstrap)}, - {CC"getBootstrap", CC"("CLS")"MH, FN_PTR(MHI_getBootstrap)}, - {CC"setCallSiteTarget", CC"("CST MH")V", FN_PTR(MHI_setCallSiteTarget)} + {CC"registerBootstrap", CC"("CLS MH")V", FN_PTR(MHN_registerBootstrap)}, + {CC"getBootstrap", CC"("CLS")"MH, FN_PTR(MHN_getBootstrap)}, + {CC"setCallSiteTarget", CC"("CST MH")V", FN_PTR(MHN_setCallSiteTarget)} }; +static void hack_signatures(JNINativeMethod* methods, jint num_methods, const char* from_sig, const char* to_sig) { + for (int i = 0; i < num_methods; i++) { + const char* sig = methods[i].signature; + if (!strstr(sig, from_sig)) continue; + size_t buflen = strlen(sig) + 100; + char* buf = NEW_C_HEAP_ARRAY(char, buflen); + char* bufp = buf; + const char* sigp = sig; + size_t from_len = strlen(from_sig), to_len = strlen(to_sig); + while (*sigp != '\0') { + assert(bufp < buf + buflen - to_len - 1, "oob"); + if (strncmp(sigp, from_sig, from_len) != 0) { + *bufp++ = *sigp++; + } else { + strcpy(bufp, to_sig); + bufp += to_len; + sigp += from_len; + } + } + *bufp = '\0'; + methods[i].signature = buf; // replace with new signature + if (TraceMethodHandles) + tty->print_cr("MethodHandleNatives: %s: change signature %s => %s", methods[i].name, sig, buf); + } +} // This one function is exported, used by NativeLookup. @@ -2600,45 +2625,78 @@ return; // bind nothing } + if (SystemDictionary::MethodHandleNatives_klass() != NULL && + SystemDictionary::MethodHandleNatives_klass() != java_lang_Class::as_klassOop(JNIHandles::resolve(MHN_class))) { + warning("multiple versions of MethodHandleNatives in boot classpath; consider using -XX:+PreferTransitionalJSR292"); + THROW_MSG(vmSymbols::java_lang_InternalError(), "multiple versions of MethodHandleNatives in boot classpath; consider using -XX:+PreferTransitionalJSR292"); + } + bool enable_MH = true; - { + // Loop control. FIXME: Replace by dead reckoning after AllowTransitionalJSR292 is removed. + bool registered_natives = false; + bool try_plain = true, try_JDYN = true, try_IDYN = true; + for (;;) { ThreadToNativeFromVM ttnfv(thread); + if (try_plain) { try_plain = false; } + else if (try_JDYN) { try_JDYN = false; hack_signatures(methods, sizeof(methods)/sizeof(JNINativeMethod), IDYN, JDYN); } + else if (try_IDYN) { try_IDYN = false; hack_signatures(methods, sizeof(methods)/sizeof(JNINativeMethod), JDYN, JLINV); } + else { break; } int status = env->RegisterNatives(MHN_class, methods, sizeof(methods)/sizeof(JNINativeMethod)); if (env->ExceptionOccurred()) { - MethodHandles::set_enabled(false); - warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); - enable_MH = false; env->ExceptionClear(); + // and try again... + } else { + registered_natives = true; + break; } } + if (!registered_natives) { + MethodHandles::set_enabled(false); + warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); + enable_MH = false; + } if (enable_MH) { + bool found_raise_exception = false; + KlassHandle MHN_klass = SystemDictionaryHandles::MethodHandleNatives_klass(); KlassHandle MHI_klass = SystemDictionaryHandles::MethodHandleImpl_klass(); - if (MHI_klass.not_null()) { + // Loop control. FIXME: Replace by dead reckoning after AllowTransitionalJSR292 is removed. + bool try_MHN = true, try_MHI = AllowTransitionalJSR292; + for (;;) { + KlassHandle try_klass; + if (try_MHN) { try_MHN = false; try_klass = MHN_klass; } + else if (try_MHI) { try_MHI = false; try_klass = MHI_klass; } + else { break; } + if (try_klass.is_null()) continue; TempNewSymbol raiseException_name = SymbolTable::new_symbol("raiseException", CHECK); TempNewSymbol raiseException_sig = SymbolTable::new_symbol("(ILjava/lang/Object;Ljava/lang/Object;)V", CHECK); - methodOop raiseException_method = instanceKlass::cast(MHI_klass->as_klassOop()) + methodOop raiseException_method = instanceKlass::cast(try_klass->as_klassOop()) ->find_method(raiseException_name, raiseException_sig); if (raiseException_method != NULL && raiseException_method->is_static()) { MethodHandles::set_raise_exception_method(raiseException_method); - } else { - warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); - enable_MH = false; + found_raise_exception = true; + break; } - } else { + } + if (!found_raise_exception) { + warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); enable_MH = false; } } if (enable_MH) { - // We need to link the MethodHandleImpl klass before we generate - // the method handle adapters as the _raise_exception adapter uses - // one of its methods (and its c2i-adapter). - KlassHandle k = SystemDictionaryHandles::MethodHandleImpl_klass(); - instanceKlass* ik = instanceKlass::cast(k()); - ik->link_class(CHECK); + if (AllowTransitionalJSR292) { + // We need to link the MethodHandleImpl klass before we generate + // the method handle adapters as the _raise_exception adapter uses + // one of its methods (and its c2i-adapter). + klassOop k = SystemDictionary::MethodHandleImpl_klass(); + if (k != NULL) { + instanceKlass* ik = instanceKlass::cast(k); + ik->link_class(CHECK); + } + } MethodHandles::generate_adapters(); MethodHandles::set_enabled(true); @@ -2649,16 +2707,14 @@ return; // bind nothing } - { + if (AllowTransitionalJSR292) { ThreadToNativeFromVM ttnfv(thread); int status = env->RegisterNatives(MHN_class, methods2, sizeof(methods2)/sizeof(JNINativeMethod)); if (env->ExceptionOccurred()) { - MethodHandles::set_enabled(false); - warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); + // Don't do this, since it's too late: + // MethodHandles::set_enabled(false) env->ExceptionClear(); - } else { - MethodHandles::set_enabled(true); } } }
--- a/src/share/vm/prims/methodHandles.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/prims/methodHandles.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -37,8 +37,8 @@ class MethodHandles: AllStatic { // JVM support for MethodHandle, MethodType, and related types - // in java.dyn and java.dyn.hotspot. - // See also javaClasses for layouts java_dyn_Method{Handle,Type,Type::Form}. + // in java.lang.invoke and sun.invoke. + // See also javaClasses for layouts java_lang_invoke_Method{Handle,Type,Type::Form}. public: enum EntryKind { _raise_exception, // stub for error generation from other stubs @@ -54,21 +54,21 @@ _bound_long_direct_mh, _adapter_mh_first, // adapter sequence goes here... - _adapter_retype_only = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_RETYPE_ONLY, - _adapter_retype_raw = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_RETYPE_RAW, - _adapter_check_cast = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_CHECK_CAST, - _adapter_prim_to_prim = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_PRIM_TO_PRIM, - _adapter_ref_to_prim = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_REF_TO_PRIM, - _adapter_prim_to_ref = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_PRIM_TO_REF, - _adapter_swap_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_SWAP_ARGS, - _adapter_rot_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_ROT_ARGS, - _adapter_dup_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_DUP_ARGS, - _adapter_drop_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_DROP_ARGS, - _adapter_collect_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_COLLECT_ARGS, - _adapter_spread_args = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_SPREAD_ARGS, - _adapter_flyby = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_FLYBY, - _adapter_ricochet = _adapter_mh_first + sun_dyn_AdapterMethodHandle::OP_RICOCHET, - _adapter_mh_last = _adapter_mh_first + sun_dyn_AdapterMethodHandle::CONV_OP_LIMIT - 1, + _adapter_retype_only = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_RETYPE_ONLY, + _adapter_retype_raw = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_RETYPE_RAW, + _adapter_check_cast = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_CHECK_CAST, + _adapter_prim_to_prim = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_PRIM, + _adapter_ref_to_prim = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_REF_TO_PRIM, + _adapter_prim_to_ref = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF, + _adapter_swap_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_SWAP_ARGS, + _adapter_rot_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_ROT_ARGS, + _adapter_dup_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_DUP_ARGS, + _adapter_drop_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_DROP_ARGS, + _adapter_collect_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS, + _adapter_spread_args = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_SPREAD_ARGS, + _adapter_flyby = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_FLYBY, + _adapter_ricochet = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::OP_RICOCHET, + _adapter_mh_last = _adapter_mh_first + java_lang_invoke_AdapterMethodHandle::CONV_OP_LIMIT - 1, // Optimized adapter types @@ -107,16 +107,16 @@ static void set_enabled(bool z); private: - enum { // import sun_dyn_AdapterMethodHandle::CONV_OP_* - CONV_OP_LIMIT = sun_dyn_AdapterMethodHandle::CONV_OP_LIMIT, - CONV_OP_MASK = sun_dyn_AdapterMethodHandle::CONV_OP_MASK, - CONV_VMINFO_MASK = sun_dyn_AdapterMethodHandle::CONV_VMINFO_MASK, - CONV_VMINFO_SHIFT = sun_dyn_AdapterMethodHandle::CONV_VMINFO_SHIFT, - CONV_OP_SHIFT = sun_dyn_AdapterMethodHandle::CONV_OP_SHIFT, - CONV_DEST_TYPE_SHIFT = sun_dyn_AdapterMethodHandle::CONV_DEST_TYPE_SHIFT, - CONV_SRC_TYPE_SHIFT = sun_dyn_AdapterMethodHandle::CONV_SRC_TYPE_SHIFT, - CONV_STACK_MOVE_SHIFT = sun_dyn_AdapterMethodHandle::CONV_STACK_MOVE_SHIFT, - CONV_STACK_MOVE_MASK = sun_dyn_AdapterMethodHandle::CONV_STACK_MOVE_MASK + enum { // import java_lang_invoke_AdapterMethodHandle::CONV_OP_* + CONV_OP_LIMIT = java_lang_invoke_AdapterMethodHandle::CONV_OP_LIMIT, + CONV_OP_MASK = java_lang_invoke_AdapterMethodHandle::CONV_OP_MASK, + CONV_VMINFO_MASK = java_lang_invoke_AdapterMethodHandle::CONV_VMINFO_MASK, + CONV_VMINFO_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_VMINFO_SHIFT, + CONV_OP_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_OP_SHIFT, + CONV_DEST_TYPE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_DEST_TYPE_SHIFT, + CONV_SRC_TYPE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_SRC_TYPE_SHIFT, + CONV_STACK_MOVE_SHIFT = java_lang_invoke_AdapterMethodHandle::CONV_STACK_MOVE_SHIFT, + CONV_STACK_MOVE_MASK = java_lang_invoke_AdapterMethodHandle::CONV_STACK_MOVE_MASK }; static bool _enabled; @@ -471,7 +471,7 @@ }; -// Access methods for the "entry" field of a java.dyn.MethodHandle. +// Access methods for the "entry" field of a java.lang.invoke.MethodHandle. // The field is primarily a jump target for compiled calls. // However, we squirrel away some nice pointers for other uses, // just before the jump target.
--- a/src/share/vm/prims/nativeLookup.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/prims/nativeLookup.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -107,29 +107,30 @@ void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass); } +#define CC (char*) /* cast a literal from (const char*) */ +#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) + +static JNINativeMethod lookup_special_native_methods[] = { + // Next two functions only exist for compatibility with 1.3.1 and earlier. + { CC"Java_java_io_ObjectOutputStream_getPrimitiveFieldValues", NULL, FN_PTR(JVM_GetPrimitiveFieldValues) }, // intercept ObjectOutputStream getPrimitiveFieldValues for faster serialization + { CC"Java_java_io_ObjectInputStream_setPrimitiveFieldValues", NULL, FN_PTR(JVM_SetPrimitiveFieldValues) }, // intercept ObjectInputStream setPrimitiveFieldValues for faster serialization + + { CC"Java_sun_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterUnsafeMethods) }, + { CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) }, + { CC"Java_sun_dyn_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) }, // AllowTransitionalJSR292 + { CC"Java_java_dyn_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) }, // AllowTransitionalJSR292 + { CC"Java_sun_misc_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) } +}; + static address lookup_special_native(char* jni_name) { - // NB: To ignore the jni prefix and jni postfix strstr is used matching. - if (!JDK_Version::is_gte_jdk14x_version()) { - // These functions only exist for compatibility with 1.3.1 and earlier - // Intercept ObjectOutputStream getPrimitiveFieldValues for faster serialization - if (strstr(jni_name, "Java_java_io_ObjectOutputStream_getPrimitiveFieldValues") != NULL) { - return CAST_FROM_FN_PTR(address, JVM_GetPrimitiveFieldValues); - } - // Intercept ObjectInputStream setPrimitiveFieldValues for faster serialization - if (strstr(jni_name, "Java_java_io_ObjectInputStream_setPrimitiveFieldValues") != NULL) { - return CAST_FROM_FN_PTR(address, JVM_SetPrimitiveFieldValues); + int i = !JDK_Version::is_gte_jdk14x_version() ? 0 : 2; // see comment in lookup_special_native_methods + int count = sizeof(lookup_special_native_methods) / sizeof(JNINativeMethod); + for (; i < count; i++) { + // NB: To ignore the jni prefix and jni postfix strstr is used matching. + if (strstr(jni_name, lookup_special_native_methods[i].name) != NULL) { + return CAST_FROM_FN_PTR(address, lookup_special_native_methods[i].fnPtr); } } - if (strstr(jni_name, "Java_sun_misc_Unsafe_registerNatives") != NULL) { - return CAST_FROM_FN_PTR(address, JVM_RegisterUnsafeMethods); - } - if (strstr(jni_name, "Java_sun_dyn_MethodHandleNatives_registerNatives") != NULL) { - return CAST_FROM_FN_PTR(address, JVM_RegisterMethodHandleMethods); - } - if (strstr(jni_name, "Java_sun_misc_Perf_registerNatives") != NULL) { - return CAST_FROM_FN_PTR(address, JVM_RegisterPerfMethods); - } - return NULL; }
--- a/src/share/vm/prims/unsafe.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/prims/unsafe.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -110,6 +110,8 @@ inline void* index_oop_from_field_offset_long(oop p, jlong field_offset) { jlong byte_offset = field_offset_to_byte_offset(field_offset); + // Don't allow unsafe to be used to read or write the header word of oops + assert(p == NULL || field_offset >= oopDesc::header_size(), "offset must be outside of header"); #ifdef ASSERT if (p != NULL) { assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/vm/runtime/advancedThresholdPolicy.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -0,0 +1,450 @@ +/* +* Copyright (c) 2010, 2011 Oracle and/or its affiliates. All rights reserved. +* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. +*/ + +#include "precompiled.hpp" +#include "runtime/advancedThresholdPolicy.hpp" +#include "runtime/simpleThresholdPolicy.inline.hpp" + +#ifdef TIERED +// Print an event. +void AdvancedThresholdPolicy::print_specific(EventType type, methodHandle mh, methodHandle imh, + int bci, CompLevel level) { + tty->print(" rate: "); + if (mh->prev_time() == 0) tty->print("n/a"); + else tty->print("%f", mh->rate()); + + tty->print(" k: %.2lf,%.2lf", threshold_scale(CompLevel_full_profile, Tier3LoadFeedback), + threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback)); + +} + +void AdvancedThresholdPolicy::initialize() { + // Turn on ergonomic compiler count selection + if (FLAG_IS_DEFAULT(CICompilerCountPerCPU) && FLAG_IS_DEFAULT(CICompilerCount)) { + FLAG_SET_DEFAULT(CICompilerCountPerCPU, true); + } + int count = CICompilerCount; + if (CICompilerCountPerCPU) { + // Simple log n seems to grow too slowly for tiered, try something faster: log n * log log n + int log_cpu = log2_intptr(os::active_processor_count()); + int loglog_cpu = log2_intptr(MAX2(log_cpu, 1)); + count = MAX2(log_cpu * loglog_cpu, 1) * 3 / 2; + } + + set_c1_count(MAX2(count / 3, 1)); + set_c2_count(MAX2(count - count / 3, 1)); + + // Some inlining tuning +#ifdef X86 + if (FLAG_IS_DEFAULT(InlineSmallCode)) { + FLAG_SET_DEFAULT(InlineSmallCode, 2000); + } +#endif + +#ifdef SPARC + if (FLAG_IS_DEFAULT(InlineSmallCode)) { + FLAG_SET_DEFAULT(InlineSmallCode, 2500); + } +#endif + + + set_start_time(os::javaTimeMillis()); +} + +// update_rate() is called from select_task() while holding a compile queue lock. +void AdvancedThresholdPolicy::update_rate(jlong t, methodOop m) { + if (is_old(m)) { + // We don't remove old methods from the queue, + // so we can just zero the rate. + m->set_rate(0); + return; + } + + // We don't update the rate if we've just came out of a safepoint. + // delta_s is the time since last safepoint in milliseconds. + jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint(); + jlong delta_t = t - (m->prev_time() != 0 ? m->prev_time() : start_time()); // milliseconds since the last measurement + // How many events were there since the last time? + int event_count = m->invocation_count() + m->backedge_count(); + int delta_e = event_count - m->prev_event_count(); + + // We should be running for at least 1ms. + if (delta_s >= TieredRateUpdateMinTime) { + // And we must've taken the previous point at least 1ms before. + if (delta_t >= TieredRateUpdateMinTime && delta_e > 0) { + m->set_prev_time(t); + m->set_prev_event_count(event_count); + m->set_rate((float)delta_e / (float)delta_t); // Rate is events per millisecond + } else + if (delta_t > TieredRateUpdateMaxTime && delta_e == 0) { + // If nothing happened for 25ms, zero the rate. Don't modify prev values. + m->set_rate(0); + } + } +} + +// Check if this method has been stale from a given number of milliseconds. +// See select_task(). +bool AdvancedThresholdPolicy::is_stale(jlong t, jlong timeout, methodOop m) { + jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint(); + jlong delta_t = t - m->prev_time(); + if (delta_t > timeout && delta_s > timeout) { + int event_count = m->invocation_count() + m->backedge_count(); + int delta_e = event_count - m->prev_event_count(); + // Return true if there were no events. + return delta_e == 0; + } + return false; +} + +// We don't remove old methods from the compile queue even if they have +// very low activity. See select_task(). +bool AdvancedThresholdPolicy::is_old(methodOop method) { + return method->invocation_count() > 50000 || method->backedge_count() > 500000; +} + +double AdvancedThresholdPolicy::weight(methodOop method) { + return (method->rate() + 1) * ((method->invocation_count() + 1) * (method->backedge_count() + 1)); +} + +// Apply heuristics and return true if x should be compiled before y +bool AdvancedThresholdPolicy::compare_methods(methodOop x, methodOop y) { + if (x->highest_comp_level() > y->highest_comp_level()) { + // recompilation after deopt + return true; + } else + if (x->highest_comp_level() == y->highest_comp_level()) { + if (weight(x) > weight(y)) { + return true; + } + } + return false; +} + +// Is method profiled enough? +bool AdvancedThresholdPolicy::is_method_profiled(methodOop method) { + methodDataOop mdo = method->method_data(); + if (mdo != NULL) { + int i = mdo->invocation_count_delta(); + int b = mdo->backedge_count_delta(); + return call_predicate_helper<CompLevel_full_profile>(i, b, 1); + } + return false; +} + +// Called with the queue locked and with at least one element +CompileTask* AdvancedThresholdPolicy::select_task(CompileQueue* compile_queue) { + CompileTask *max_task = NULL; + methodOop max_method; + jlong t = os::javaTimeMillis(); + // Iterate through the queue and find a method with a maximum rate. + for (CompileTask* task = compile_queue->first(); task != NULL;) { + CompileTask* next_task = task->next(); + methodOop method = (methodOop)JNIHandles::resolve(task->method_handle()); + methodDataOop mdo = method->method_data(); + update_rate(t, method); + if (max_task == NULL) { + max_task = task; + max_method = method; + } else { + // If a method has been stale for some time, remove it from the queue. + if (is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) { + if (PrintTieredEvents) { + print_event(KILL, method, method, task->osr_bci(), (CompLevel)task->comp_level()); + } + CompileTaskWrapper ctw(task); // Frees the task + compile_queue->remove(task); + method->clear_queued_for_compilation(); + task = next_task; + continue; + } + + // Select a method with a higher rate + if (compare_methods(method, max_method)) { + max_task = task; + max_method = method; + } + } + task = next_task; + } + + if (max_task->comp_level() == CompLevel_full_profile && is_method_profiled(max_method)) { + max_task->set_comp_level(CompLevel_limited_profile); + if (PrintTieredEvents) { + print_event(UPDATE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level()); + } + } + + return max_task; +} + +double AdvancedThresholdPolicy::threshold_scale(CompLevel level, int feedback_k) { + double queue_size = CompileBroker::queue_size(level); + int comp_count = compiler_count(level); + double k = queue_size / (feedback_k * comp_count) + 1; + return k; +} + +// Call and loop predicates determine whether a transition to a higher +// compilation level should be performed (pointers to predicate functions +// are passed to common()). +// Tier?LoadFeedback is basically a coefficient that determines of +// how many methods per compiler thread can be in the queue before +// the threshold values double. +bool AdvancedThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) { + switch(cur_level) { + case CompLevel_none: + case CompLevel_limited_profile: { + double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback); + return loop_predicate_helper<CompLevel_none>(i, b, k); + } + case CompLevel_full_profile: { + double k = threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback); + return loop_predicate_helper<CompLevel_full_profile>(i, b, k); + } + default: + return true; + } +} + +bool AdvancedThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level) { + switch(cur_level) { + case CompLevel_none: + case CompLevel_limited_profile: { + double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback); + return call_predicate_helper<CompLevel_none>(i, b, k); + } + case CompLevel_full_profile: { + double k = threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback); + return call_predicate_helper<CompLevel_full_profile>(i, b, k); + } + default: + return true; + } +} + +// If a method is old enough and is still in the interpreter we would want to +// start profiling without waiting for the compiled method to arrive. +// We also take the load on compilers into the account. +bool AdvancedThresholdPolicy::should_create_mdo(methodOop method, CompLevel cur_level) { + if (cur_level == CompLevel_none && + CompileBroker::queue_size(CompLevel_full_optimization) <= + Tier3DelayOn * compiler_count(CompLevel_full_optimization)) { + int i = method->invocation_count(); + int b = method->backedge_count(); + double k = Tier0ProfilingStartPercentage / 100.0; + return call_predicate_helper<CompLevel_none>(i, b, k) || loop_predicate_helper<CompLevel_none>(i, b, k); + } + return false; +} + +// Create MDO if necessary. +void AdvancedThresholdPolicy::create_mdo(methodHandle mh, TRAPS) { + if (mh->is_native() || mh->is_abstract() || mh->is_accessor()) return; + if (mh->method_data() == NULL) { + methodOopDesc::build_interpreter_method_data(mh, THREAD); + if (HAS_PENDING_EXCEPTION) { + CLEAR_PENDING_EXCEPTION; + } + } +} + + +/* + * Method states: + * 0 - interpreter (CompLevel_none) + * 1 - pure C1 (CompLevel_simple) + * 2 - C1 with invocation and backedge counting (CompLevel_limited_profile) + * 3 - C1 with full profiling (CompLevel_full_profile) + * 4 - C2 (CompLevel_full_optimization) + * + * Common state transition patterns: + * a. 0 -> 3 -> 4. + * The most common path. But note that even in this straightforward case + * profiling can start at level 0 and finish at level 3. + * + * b. 0 -> 2 -> 3 -> 4. + * This case occures when the load on C2 is deemed too high. So, instead of transitioning + * into state 3 directly and over-profiling while a method is in the C2 queue we transition to + * level 2 and wait until the load on C2 decreases. This path is disabled for OSRs. + * + * c. 0 -> (3->2) -> 4. + * In this case we enqueue a method for compilation at level 3, but the C1 queue is long enough + * to enable the profiling to fully occur at level 0. In this case we change the compilation level + * of the method to 2, because it'll allow it to run much faster without full profiling while c2 + * is compiling. + * + * d. 0 -> 3 -> 1 or 0 -> 2 -> 1. + * After a method was once compiled with C1 it can be identified as trivial and be compiled to + * level 1. These transition can also occur if a method can't be compiled with C2 but can with C1. + * + * e. 0 -> 4. + * This can happen if a method fails C1 compilation (it will still be profiled in the interpreter) + * or because of a deopt that didn't require reprofiling (compilation won't happen in this case because + * the compiled version already exists). + * + * Note that since state 0 can be reached from any other state via deoptimization different loops + * are possible. + * + */ + +// Common transition function. Given a predicate determines if a method should transition to another level. +CompLevel AdvancedThresholdPolicy::common(Predicate p, methodOop method, CompLevel cur_level) { + if (is_trivial(method)) return CompLevel_simple; + + CompLevel next_level = cur_level; + int i = method->invocation_count(); + int b = method->backedge_count(); + + switch(cur_level) { + case CompLevel_none: + // If we were at full profile level, would we switch to full opt? + if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) { + next_level = CompLevel_full_optimization; + } else if ((this->*p)(i, b, cur_level)) { + // C1-generated fully profiled code is about 30% slower than the limited profile + // code that has only invocation and backedge counters. The observation is that + // if C2 queue is large enough we can spend too much time in the fully profiled code + // while waiting for C2 to pick the method from the queue. To alleviate this problem + // we introduce a feedback on the C2 queue size. If the C2 queue is sufficiently long + // we choose to compile a limited profiled version and then recompile with full profiling + // when the load on C2 goes down. + if (CompileBroker::queue_size(CompLevel_full_optimization) > + Tier3DelayOn * compiler_count(CompLevel_full_optimization)) { + next_level = CompLevel_limited_profile; + } else { + next_level = CompLevel_full_profile; + } + } + break; + case CompLevel_limited_profile: + if (is_method_profiled(method)) { + // Special case: we got here because this method was fully profiled in the interpreter. + next_level = CompLevel_full_optimization; + } else { + methodDataOop mdo = method->method_data(); + if (mdo != NULL) { + if (mdo->would_profile()) { + if (CompileBroker::queue_size(CompLevel_full_optimization) <= + Tier3DelayOff * compiler_count(CompLevel_full_optimization) && + (this->*p)(i, b, cur_level)) { + next_level = CompLevel_full_profile; + } + } else { + next_level = CompLevel_full_optimization; + } + } + } + break; + case CompLevel_full_profile: + { + methodDataOop mdo = method->method_data(); + if (mdo != NULL) { + if (mdo->would_profile()) { + int mdo_i = mdo->invocation_count_delta(); + int mdo_b = mdo->backedge_count_delta(); + if ((this->*p)(mdo_i, mdo_b, cur_level)) { + next_level = CompLevel_full_optimization; + } + } else { + next_level = CompLevel_full_optimization; + } + } + } + break; + } + return next_level; +} + +// Determine if a method should be compiled with a normal entry point at a different level. +CompLevel AdvancedThresholdPolicy::call_event(methodOop method, CompLevel cur_level) { + CompLevel osr_level = (CompLevel) method->highest_osr_comp_level(); + CompLevel next_level = common(&AdvancedThresholdPolicy::call_predicate, method, cur_level); + + // If OSR method level is greater than the regular method level, the levels should be + // equalized by raising the regular method level in order to avoid OSRs during each + // invocation of the method. + if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) { + methodDataOop mdo = method->method_data(); + guarantee(mdo != NULL, "MDO should not be NULL"); + if (mdo->invocation_count() >= 1) { + next_level = CompLevel_full_optimization; + } + } else { + next_level = MAX2(osr_level, next_level); + } + + return next_level; +} + +// Determine if we should do an OSR compilation of a given method. +CompLevel AdvancedThresholdPolicy::loop_event(methodOop method, CompLevel cur_level) { + if (cur_level == CompLevel_none) { + // If there is a live OSR method that means that we deopted to the interpreter + // for the transition. + CompLevel osr_level = (CompLevel)method->highest_osr_comp_level(); + if (osr_level > CompLevel_none) { + return osr_level; + } + } + return common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level); +} + +// Update the rate and submit compile +void AdvancedThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS) { + int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count(); + update_rate(os::javaTimeMillis(), mh()); + CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", THREAD); +} + + +// Handle the invocation event. +void AdvancedThresholdPolicy::method_invocation_event(methodHandle mh, methodHandle imh, + CompLevel level, TRAPS) { + if (should_create_mdo(mh(), level)) { + create_mdo(mh, THREAD); + } + if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, InvocationEntryBci)) { + CompLevel next_level = call_event(mh(), level); + if (next_level != level) { + compile(mh, InvocationEntryBci, next_level, THREAD); + } + } +} + +// Handle the back branch event. Notice that we can compile the method +// with a regular entry from here. +void AdvancedThresholdPolicy::method_back_branch_event(methodHandle mh, methodHandle imh, + int bci, CompLevel level, TRAPS) { + if (should_create_mdo(mh(), level)) { + create_mdo(mh, THREAD); + } + + // If the method is already compiling, quickly bail out. + if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, bci)) { + // Use loop event as an opportinity to also check there's been + // enough calls. + CompLevel cur_level = comp_level(mh()); + CompLevel next_level = call_event(mh(), cur_level); + CompLevel next_osr_level = loop_event(mh(), level); + if (next_osr_level == CompLevel_limited_profile) { + next_osr_level = CompLevel_full_profile; // OSRs are supposed to be for very hot methods. + } + next_level = MAX2(next_level, + next_osr_level < CompLevel_full_optimization ? next_osr_level : cur_level); + bool is_compiling = false; + if (next_level != cur_level) { + compile(mh, InvocationEntryBci, next_level, THREAD); + is_compiling = true; + } + + // Do the OSR version + if (!is_compiling && next_osr_level != level) { + compile(mh, bci, next_osr_level, THREAD); + } + } +} + +#endif // TIERED
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/vm/runtime/advancedThresholdPolicy.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -0,0 +1,207 @@ +/* +* Copyright (c) 2010, 2011 Oracle and/or its affiliates. All rights reserved. +* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. +*/ + +#ifndef SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP +#define SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP + +#include "runtime/simpleThresholdPolicy.hpp" + +#ifdef TIERED +class CompileTask; +class CompileQueue; + +/* + * The system supports 5 execution levels: + * * level 0 - interpreter + * * level 1 - C1 with full optimization (no profiling) + * * level 2 - C1 with invocation and backedge counters + * * level 3 - C1 with full profiling (level 2 + MDO) + * * level 4 - C2 + * + * Levels 0, 2 and 3 periodically notify the runtime about the current value of the counters + * (invocation counters and backedge counters). The frequency of these notifications is + * different at each level. These notifications are used by the policy to decide what transition + * to make. + * + * Execution starts at level 0 (interpreter), then the policy can decide either to compile the + * method at level 3 or level 2. The decision is based on the following factors: + * 1. The length of the C2 queue determines the next level. The observation is that level 2 + * is generally faster than level 3 by about 30%, therefore we would want to minimize the time + * a method spends at level 3. We should only spend the time at level 3 that is necessary to get + * adequate profiling. So, if the C2 queue is long enough it is more beneficial to go first to + * level 2, because if we transitioned to level 3 we would be stuck there until our C2 compile + * request makes its way through the long queue. When the load on C2 recedes we are going to + * recompile at level 3 and start gathering profiling information. + * 2. The length of C1 queue is used to dynamically adjust the thresholds, so as to introduce + * additional filtering if the compiler is overloaded. The rationale is that by the time a + * method gets compiled it can become unused, so it doesn't make sense to put too much onto the + * queue. + * + * After profiling is completed at level 3 the transition is made to level 4. Again, the length + * of the C2 queue is used as a feedback to adjust the thresholds. + * + * After the first C1 compile some basic information is determined about the code like the number + * of the blocks and the number of the loops. Based on that it can be decided that a method + * is trivial and compiling it with C1 will yield the same code. In this case the method is + * compiled at level 1 instead of 4. + * + * We also support profiling at level 0. If C1 is slow enough to produce the level 3 version of + * the code and the C2 queue is sufficiently small we can decide to start profiling in the + * interpreter (and continue profiling in the compiled code once the level 3 version arrives). + * If the profiling at level 0 is fully completed before level 3 version is produced, a level 2 + * version is compiled instead in order to run faster waiting for a level 4 version. + * + * Compile queues are implemented as priority queues - for each method in the queue we compute + * the event rate (the number of invocation and backedge counter increments per unit of time). + * When getting an element off the queue we pick the one with the largest rate. Maintaining the + * rate also allows us to remove stale methods (the ones that got on the queue but stopped + * being used shortly after that). +*/ + +/* Command line options: + * - Tier?InvokeNotifyFreqLog and Tier?BackedgeNotifyFreqLog control the frequency of method + * invocation and backedge notifications. Basically every n-th invocation or backedge a mutator thread + * makes a call into the runtime. + * + * - Tier?CompileThreshold, Tier?BackEdgeThreshold, Tier?MinInvocationThreshold control + * compilation thresholds. + * Level 2 thresholds are not used and are provided for option-compatibility and potential future use. + * Other thresholds work as follows: + * + * Transition from interpreter (level 0) to C1 with full profiling (level 3) happens when + * the following predicate is true (X is the level): + * + * i > TierXInvocationThreshold * s || (i > TierXMinInvocationThreshold * s && i + b > TierXCompileThreshold * s), + * + * where $i$ is the number of method invocations, $b$ number of backedges and $s$ is the scaling + * coefficient that will be discussed further. + * The intuition is to equalize the time that is spend profiling each method. + * The same predicate is used to control the transition from level 3 to level 4 (C2). It should be + * noted though that the thresholds are relative. Moreover i and b for the 0->3 transition come + * from methodOop and for 3->4 transition they come from MDO (since profiled invocations are + * counted separately). + * + * OSR transitions are controlled simply with b > TierXBackEdgeThreshold * s predicates. + * + * - Tier?LoadFeedback options are used to automatically scale the predicates described above depending + * on the compiler load. The scaling coefficients are computed as follows: + * + * s = queue_size_X / (TierXLoadFeedback * compiler_count_X) + 1, + * + * where queue_size_X is the current size of the compiler queue of level X, and compiler_count_X + * is the number of level X compiler threads. + * + * Basically these parameters describe how many methods should be in the compile queue + * per compiler thread before the scaling coefficient increases by one. + * + * This feedback provides the mechanism to automatically control the flow of compilation requests + * depending on the machine speed, mutator load and other external factors. + * + * - Tier3DelayOn and Tier3DelayOff parameters control another important feedback loop. + * Consider the following observation: a method compiled with full profiling (level 3) + * is about 30% slower than a method at level 2 (just invocation and backedge counters, no MDO). + * Normally, the following transitions will occur: 0->3->4. The problem arises when the C2 queue + * gets congested and the 3->4 transition is delayed. While the method is the C2 queue it continues + * executing at level 3 for much longer time than is required by the predicate and at suboptimal speed. + * The idea is to dynamically change the behavior of the system in such a way that if a substantial + * load on C2 is detected we would first do the 0->2 transition allowing a method to run faster. + * And then when the load decreases to allow 2->3 transitions. + * + * Tier3Delay* parameters control this switching mechanism. + * Tier3DelayOn is the number of methods in the C2 queue per compiler thread after which the policy + * no longer does 0->3 transitions but does 0->2 transitions instead. + * Tier3DelayOff switches the original behavior back when the number of methods in the C2 queue + * per compiler thread falls below the specified amount. + * The hysteresis is necessary to avoid jitter. + * + * - TieredCompileTaskTimeout is the amount of time an idle method can spend in the compile queue. + * Basically, since we use the event rate d(i + b)/dt as a value of priority when selecting a method to + * compile from the compile queue, we also can detect stale methods for which the rate has been + * 0 for some time in the same iteration. Stale methods can appear in the queue when an application + * abruptly changes its behavior. + * + * - TieredStopAtLevel, is used mostly for testing. It allows to bypass the policy logic and stick + * to a given level. For example it's useful to set TieredStopAtLevel = 1 in order to compile everything + * with pure c1. + * + * - Tier0ProfilingStartPercentage allows the interpreter to start profiling when the inequalities in the + * 0->3 predicate are already exceeded by the given percentage but the level 3 version of the + * method is still not ready. We can even go directly from level 0 to 4 if c1 doesn't produce a compiled + * version in time. This reduces the overall transition to level 4 and decreases the startup time. + * Note that this behavior is also guarded by the Tier3Delay mechanism: when the c2 queue is too long + * these is not reason to start profiling prematurely. + * + * - TieredRateUpdateMinTime and TieredRateUpdateMaxTime are parameters of the rate computation. + * Basically, the rate is not computed more frequently than TieredRateUpdateMinTime and is considered + * to be zero if no events occurred in TieredRateUpdateMaxTime. + */ + + +class AdvancedThresholdPolicy : public SimpleThresholdPolicy { + jlong _start_time; + + // Call and loop predicates determine whether a transition to a higher compilation + // level should be performed (pointers to predicate functions are passed to common(). + // Predicates also take compiler load into account. + typedef bool (AdvancedThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level); + bool call_predicate(int i, int b, CompLevel cur_level); + bool loop_predicate(int i, int b, CompLevel cur_level); + // Common transition function. Given a predicate determines if a method should transition to another level. + CompLevel common(Predicate p, methodOop method, CompLevel cur_level); + // Transition functions. + // call_event determines if a method should be compiled at a different + // level with a regular invocation entry. + CompLevel call_event(methodOop method, CompLevel cur_level); + // loop_event checks if a method should be OSR compiled at a different + // level. + CompLevel loop_event(methodOop method, CompLevel cur_level); + // Has a method been long around? + // We don't remove old methods from the compile queue even if they have + // very low activity (see select_task()). + inline bool is_old(methodOop method); + // Was a given method inactive for a given number of milliseconds. + // If it is, we would remove it from the queue (see select_task()). + inline bool is_stale(jlong t, jlong timeout, methodOop m); + // Compute the weight of the method for the compilation scheduling + inline double weight(methodOop method); + // Apply heuristics and return true if x should be compiled before y + inline bool compare_methods(methodOop x, methodOop y); + // Compute event rate for a given method. The rate is the number of event (invocations + backedges) + // per millisecond. + inline void update_rate(jlong t, methodOop m); + // Compute threshold scaling coefficient + inline double threshold_scale(CompLevel level, int feedback_k); + // If a method is old enough and is still in the interpreter we would want to + // start profiling without waiting for the compiled method to arrive. This function + // determines whether we should do that. + inline bool should_create_mdo(methodOop method, CompLevel cur_level); + // Create MDO if necessary. + void create_mdo(methodHandle mh, TRAPS); + // Is method profiled enough? + bool is_method_profiled(methodOop method); + +protected: + void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level); + + void set_start_time(jlong t) { _start_time = t; } + jlong start_time() const { return _start_time; } + + // Submit a given method for compilation (and update the rate). + virtual void submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS); + // event() from SimpleThresholdPolicy would call these. + virtual void method_invocation_event(methodHandle method, methodHandle inlinee, + CompLevel level, TRAPS); + virtual void method_back_branch_event(methodHandle method, methodHandle inlinee, + int bci, CompLevel level, TRAPS); +public: + AdvancedThresholdPolicy() : _start_time(0) { } + // Select task is called by CompileBroker. We should return a task or NULL. + virtual CompileTask* select_task(CompileQueue* compile_queue); + virtual void initialize(); +}; + +#endif // TIERED + +#endif // SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP
--- a/src/share/vm/runtime/arguments.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/arguments.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1005,8 +1005,9 @@ } void Arguments::set_tiered_flags() { + // With tiered, set default policy to AdvancedThresholdPolicy, which is 3. if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) { - FLAG_SET_DEFAULT(CompilationPolicyChoice, 2); + FLAG_SET_DEFAULT(CompilationPolicyChoice, 3); } if (CompilationPolicyChoice < 2) { vm_exit_during_initialization( @@ -2704,10 +2705,6 @@ if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) { FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1); } - // Temporary disable bulk zeroing reduction with G1. See CR 6627983. - if (UseG1GC) { - FLAG_SET_DEFAULT(ReduceBulkZeroing, false); - } #endif // If we are running in a headless jre, force java.awt.headless property @@ -3043,7 +3040,11 @@ // Turn off biased locking for locking debug mode flags, // which are subtlely different from each other but neither works with // biased locking. - if (!UseFastLocking || UseHeavyMonitors) { + if (UseHeavyMonitors +#ifdef COMPILER1 + || !UseFastLocking +#endif // COMPILER1 + ) { if (!FLAG_IS_DEFAULT(UseBiasedLocking) && UseBiasedLocking) { // flag set to true on command line; warn the user that they // can't enable biased locking here
--- a/src/share/vm/runtime/compilationPolicy.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/compilationPolicy.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,6 +32,7 @@ #include "oops/methodOop.hpp" #include "oops/oop.inline.hpp" #include "prims/nativeLookup.hpp" +#include "runtime/advancedThresholdPolicy.hpp" #include "runtime/compilationPolicy.hpp" #include "runtime/frame.hpp" #include "runtime/handles.inline.hpp" @@ -72,8 +73,15 @@ Unimplemented(); #endif break; + case 3: +#ifdef TIERED + CompilationPolicy::set_policy(new AdvancedThresholdPolicy()); +#else + Unimplemented(); +#endif + break; default: - fatal("CompilationPolicyChoice must be in the range: [0-2]"); + fatal("CompilationPolicyChoice must be in the range: [0-3]"); } CompilationPolicy::policy()->initialize(); }
--- a/src/share/vm/runtime/deoptimization.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/deoptimization.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -101,9 +101,9 @@ _frame_pcs = frame_pcs; _register_block = NEW_C_HEAP_ARRAY(intptr_t, RegisterMap::reg_count * 2); _return_type = return_type; + _initial_fp = 0; // PD (x86 only) _counter_temp = 0; - _initial_fp = 0; _unpack_kind = 0; _sender_sp_temp = 0; @@ -459,18 +459,9 @@ frame_sizes, frame_pcs, return_type); -#if defined(IA32) || defined(AMD64) - // We need a way to pass fp to the unpacking code so the skeletal frames - // come out correct. This is only needed for x86 because of c2 using ebp - // as an allocatable register. So this update is useless (and harmless) - // on the other platforms. It would be nice to do this in a different - // way but even the old style deoptimization had a problem with deriving - // this value. NEEDS_CLEANUP - // Note: now that c1 is using c2's deopt blob we must do this on all - // x86 based platforms - intptr_t** fp_addr = (intptr_t**) (((address)info) + info->initial_fp_offset_in_bytes()); - *fp_addr = array->sender().fp(); // was adapter_caller -#endif /* IA32 || AMD64 */ + // On some platforms, we need a way to pass fp to the unpacking code + // so the skeletal frames come out correct. + info->set_initial_fp((intptr_t) array->sender().fp()); if (array->frames() > 1) { if (VerifyStack && TraceDeoptimization) {
--- a/src/share/vm/runtime/deoptimization.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/deoptimization.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -136,12 +136,12 @@ address* _frame_pcs; // Array of frame pc's, in bytes, for unrolling the stack intptr_t* _register_block; // Block for storing callee-saved registers. BasicType _return_type; // Tells if we have to restore double or long return value + intptr_t _initial_fp; // FP of the sender frame // The following fields are used as temps during the unpacking phase // (which is tight on registers, especially on x86). They really ought // to be PD variables but that involves moving this class into its own // file to use the pd include mechanism. Maybe in a later cleanup ... intptr_t _counter_temp; // SHOULD BE PD VARIABLE (x86 frame count temp) - intptr_t _initial_fp; // SHOULD BE PD VARIABLE (x86/c2 initial ebp) intptr_t _unpack_kind; // SHOULD BE PD VARIABLE (x86 unpack kind) intptr_t _sender_sp_temp; // SHOULD BE PD VARIABLE (x86 sender_sp) public: @@ -165,6 +165,8 @@ // Returns the total size of frames int size_of_frames() const; + void set_initial_fp(intptr_t fp) { _initial_fp = fp; } + // Accessors used by the code generator for the unpack stub. static int size_of_deoptimized_frame_offset_in_bytes() { return offset_of(UnrollBlock, _size_of_deoptimized_frame); } static int caller_adjustment_offset_in_bytes() { return offset_of(UnrollBlock, _caller_adjustment); }
--- a/src/share/vm/runtime/globals.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/globals.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -2606,9 +2606,6 @@ develop(bool, CompileTheWorldPreloadClasses, true, \ "Preload all classes used by a class before start loading") \ \ - notproduct(bool, CompileTheWorldIgnoreInitErrors, false, \ - "Compile all methods although class initializer failed") \ - \ notproduct(intx, CompileTheWorldSafepointInterval, 100, \ "Force a safepoint every n compiles so sweeper can keep up") \ \ @@ -3715,6 +3712,13 @@ experimental(bool, AllowTransitionalJSR292, true, \ "recognize pre-PFD formats of invokedynamic") \ \ + experimental(bool, PreferTransitionalJSR292, false, \ + "prefer pre-PFD APIs on boot class path, if they exist") \ + \ + experimental(bool, AllowInvokeForInvokeGeneric, false, \ + "accept MethodHandle.invoke and MethodHandle.invokeGeneric " \ + "as equivalent methods") \ + \ develop(bool, TraceInvokeDynamic, false, \ "trace internal invoke dynamic operations") \ \
--- a/src/share/vm/runtime/os.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/os.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -633,10 +633,10 @@ *q = (u_char)freeBlockPad; } if (PrintMalloc && tty != NULL) - fprintf(stderr, "os::free " SIZE_FORMAT " bytes --> " PTR_FORMAT "\n", size, memblock); + fprintf(stderr, "os::free " SIZE_FORMAT " bytes --> " PTR_FORMAT "\n", size, (uintptr_t)memblock); } else if (PrintMalloc && tty != NULL) { // tty->print_cr("os::free %p", memblock); - fprintf(stderr, "os::free " PTR_FORMAT "\n", memblock); + fprintf(stderr, "os::free " PTR_FORMAT "\n", (uintptr_t)memblock); } #endif ::free((char*)memblock - space_before);
--- a/src/share/vm/runtime/serviceThread.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/serviceThread.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -70,11 +70,10 @@ java_lang_Thread::set_priority(thread_oop(), NearMaxPriority); java_lang_Thread::set_daemon(thread_oop()); thread->set_threadObj(thread_oop()); + _instance = thread; Threads::add(thread); Thread::start(thread); - - _instance = thread; } }
--- a/src/share/vm/runtime/sharedRuntime.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/sharedRuntime.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -431,25 +431,24 @@ // previous frame depending on the return address. address SharedRuntime::raw_exception_handler_for_return_address(JavaThread* thread, address return_address) { - assert(frame::verify_return_pc(return_address), "must be a return pc"); - - // Reset MethodHandle flag. + assert(frame::verify_return_pc(return_address), err_msg("must be a return address: " INTPTR_FORMAT, return_address)); + + // Reset method handle flag. thread->set_is_method_handle_return(false); - // the fastest case first + // The fastest case first CodeBlob* blob = CodeCache::find_blob(return_address); - if (blob != NULL && blob->is_nmethod()) { - nmethod* code = (nmethod*)blob; - assert(code != NULL, "nmethod must be present"); - // Check if the return address is a MethodHandle call site. - thread->set_is_method_handle_return(code->is_method_handle_return(return_address)); + nmethod* nm = (blob != NULL) ? blob->as_nmethod_or_null() : NULL; + if (nm != NULL) { + // Set flag if return address is a method handle call site. + thread->set_is_method_handle_return(nm->is_method_handle_return(return_address)); // native nmethods don't have exception handlers - assert(!code->is_native_method(), "no exception handler"); - assert(code->header_begin() != code->exception_begin(), "no exception handler"); - if (code->is_deopt_pc(return_address)) { + assert(!nm->is_native_method(), "no exception handler"); + assert(nm->header_begin() != nm->exception_begin(), "no exception handler"); + if (nm->is_deopt_pc(return_address)) { return SharedRuntime::deopt_blob()->unpack_with_exception(); } else { - return code->exception_begin(); + return nm->exception_begin(); } } @@ -462,22 +461,9 @@ return Interpreter::rethrow_exception_entry(); } - // Compiled code - if (CodeCache::contains(return_address)) { - CodeBlob* blob = CodeCache::find_blob(return_address); - if (blob->is_nmethod()) { - nmethod* code = (nmethod*)blob; - assert(code != NULL, "nmethod must be present"); - // Check if the return address is a MethodHandle call site. - thread->set_is_method_handle_return(code->is_method_handle_return(return_address)); - assert(code->header_begin() != code->exception_begin(), "no exception handler"); - return code->exception_begin(); - } - if (blob->is_runtime_stub()) { - ShouldNotReachHere(); // callers are responsible for skipping runtime stub frames - } - } + guarantee(blob == NULL || !blob->is_runtime_stub(), "caller should have skipped stub"); guarantee(!VtableStubs::contains(return_address), "NULL exceptions in vtables should have been handled already!"); + #ifndef PRODUCT { ResourceMark rm; tty->print_cr("No exception handler found for exception at " INTPTR_FORMAT " - potential problems:", return_address); @@ -485,6 +471,7 @@ tty->print_cr("b) other problem"); } #endif // PRODUCT + ShouldNotReachHere(); return NULL; }
--- a/src/share/vm/runtime/stubRoutines.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/stubRoutines.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -80,30 +80,36 @@ jint StubRoutines::_fpu_subnormal_bias2[3] = { 0, 0, 0 }; // Compiled code entry points default values -// The dafault functions don't have separate disjoint versions. +// The default functions don't have separate disjoint versions. address StubRoutines::_jbyte_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::jbyte_copy); address StubRoutines::_jshort_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::jshort_copy); address StubRoutines::_jint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::jint_copy); address StubRoutines::_jlong_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::jlong_copy); address StubRoutines::_oop_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::oop_copy); +address StubRoutines::_oop_arraycopy_uninit = CAST_FROM_FN_PTR(address, StubRoutines::oop_copy_uninit); address StubRoutines::_jbyte_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::jbyte_copy); address StubRoutines::_jshort_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::jshort_copy); address StubRoutines::_jint_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::jint_copy); address StubRoutines::_jlong_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::jlong_copy); address StubRoutines::_oop_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::oop_copy); +address StubRoutines::_oop_disjoint_arraycopy_uninit = CAST_FROM_FN_PTR(address, StubRoutines::oop_copy_uninit); address StubRoutines::_arrayof_jbyte_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jbyte_copy); address StubRoutines::_arrayof_jshort_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jshort_copy); address StubRoutines::_arrayof_jint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jint_copy); address StubRoutines::_arrayof_jlong_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jlong_copy); address StubRoutines::_arrayof_oop_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_oop_copy); +address StubRoutines::_arrayof_oop_arraycopy_uninit = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_oop_copy_uninit); address StubRoutines::_arrayof_jbyte_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jbyte_copy); address StubRoutines::_arrayof_jshort_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jshort_copy); address StubRoutines::_arrayof_jint_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jint_copy); address StubRoutines::_arrayof_jlong_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_jlong_copy); -address StubRoutines::_arrayof_oop_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_oop_copy); +address StubRoutines::_arrayof_oop_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_oop_copy); +address StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = CAST_FROM_FN_PTR(address, StubRoutines::arrayof_oop_copy_uninit); + address StubRoutines::_checkcast_arraycopy = NULL; +address StubRoutines::_checkcast_arraycopy_uninit = NULL; address StubRoutines::_unsafe_arraycopy = NULL; address StubRoutines::_generic_arraycopy = NULL; @@ -282,12 +288,12 @@ // Default versions of arraycopy functions // -static void gen_arraycopy_barrier_pre(oop* dest, size_t count) { +static void gen_arraycopy_barrier_pre(oop* dest, size_t count, bool dest_uninitialized) { assert(count != 0, "count should be non-zero"); assert(count <= (size_t)max_intx, "count too large"); BarrierSet* bs = Universe::heap()->barrier_set(); assert(bs->has_write_ref_array_pre_opt(), "Must have pre-barrier opt"); - bs->write_ref_array_pre(dest, (int)count); + bs->write_ref_array_pre(dest, (int)count, dest_uninitialized); } static void gen_arraycopy_barrier(oop* dest, size_t count) { @@ -330,7 +336,17 @@ SharedRuntime::_oop_array_copy_ctr++; // Slow-path oop array copy #endif // !PRODUCT assert(count != 0, "count should be non-zero"); - gen_arraycopy_barrier_pre(dest, count); + gen_arraycopy_barrier_pre(dest, count, /*dest_uninitialized*/false); + Copy::conjoint_oops_atomic(src, dest, count); + gen_arraycopy_barrier(dest, count); +JRT_END + +JRT_LEAF(void, StubRoutines::oop_copy_uninit(oop* src, oop* dest, size_t count)) +#ifndef PRODUCT + SharedRuntime::_oop_array_copy_ctr++; // Slow-path oop array copy +#endif // !PRODUCT + assert(count != 0, "count should be non-zero"); + gen_arraycopy_barrier_pre(dest, count, /*dest_uninitialized*/true); Copy::conjoint_oops_atomic(src, dest, count); gen_arraycopy_barrier(dest, count); JRT_END @@ -368,11 +384,20 @@ SharedRuntime::_oop_array_copy_ctr++; // Slow-path oop array copy #endif // !PRODUCT assert(count != 0, "count should be non-zero"); - gen_arraycopy_barrier_pre((oop *) dest, count); + gen_arraycopy_barrier_pre((oop *) dest, count, /*dest_uninitialized*/false); Copy::arrayof_conjoint_oops(src, dest, count); gen_arraycopy_barrier((oop *) dest, count); JRT_END +JRT_LEAF(void, StubRoutines::arrayof_oop_copy_uninit(HeapWord* src, HeapWord* dest, size_t count)) +#ifndef PRODUCT + SharedRuntime::_oop_array_copy_ctr++; // Slow-path oop array copy +#endif // !PRODUCT + assert(count != 0, "count should be non-zero"); + gen_arraycopy_barrier_pre((oop *) dest, count, /*dest_uninitialized*/true); + Copy::arrayof_conjoint_oops(src, dest, count); + gen_arraycopy_barrier((oop *) dest, count); +JRT_END address StubRoutines::select_fill_function(BasicType t, bool aligned, const char* &name) { #define RETURN_STUB(xxx_fill) { \
--- a/src/share/vm/runtime/stubRoutines.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/stubRoutines.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -164,12 +164,12 @@ static address _jshort_arraycopy; static address _jint_arraycopy; static address _jlong_arraycopy; - static address _oop_arraycopy; + static address _oop_arraycopy, _oop_arraycopy_uninit; static address _jbyte_disjoint_arraycopy; static address _jshort_disjoint_arraycopy; static address _jint_disjoint_arraycopy; static address _jlong_disjoint_arraycopy; - static address _oop_disjoint_arraycopy; + static address _oop_disjoint_arraycopy, _oop_disjoint_arraycopy_uninit; // arraycopy operands aligned on zero'th element boundary // These are identical to the ones aligned aligned on an @@ -179,15 +179,15 @@ static address _arrayof_jshort_arraycopy; static address _arrayof_jint_arraycopy; static address _arrayof_jlong_arraycopy; - static address _arrayof_oop_arraycopy; + static address _arrayof_oop_arraycopy, _arrayof_oop_arraycopy_uninit; static address _arrayof_jbyte_disjoint_arraycopy; static address _arrayof_jshort_disjoint_arraycopy; static address _arrayof_jint_disjoint_arraycopy; static address _arrayof_jlong_disjoint_arraycopy; - static address _arrayof_oop_disjoint_arraycopy; + static address _arrayof_oop_disjoint_arraycopy, _arrayof_oop_disjoint_arraycopy_uninit; // these are recommended but optional: - static address _checkcast_arraycopy; + static address _checkcast_arraycopy, _checkcast_arraycopy_uninit; static address _unsafe_arraycopy; static address _generic_arraycopy; @@ -286,26 +286,36 @@ static address jshort_arraycopy() { return _jshort_arraycopy; } static address jint_arraycopy() { return _jint_arraycopy; } static address jlong_arraycopy() { return _jlong_arraycopy; } - static address oop_arraycopy() { return _oop_arraycopy; } + static address oop_arraycopy(bool dest_uninitialized = false) { + return dest_uninitialized ? _oop_arraycopy_uninit : _oop_arraycopy; + } static address jbyte_disjoint_arraycopy() { return _jbyte_disjoint_arraycopy; } static address jshort_disjoint_arraycopy() { return _jshort_disjoint_arraycopy; } static address jint_disjoint_arraycopy() { return _jint_disjoint_arraycopy; } static address jlong_disjoint_arraycopy() { return _jlong_disjoint_arraycopy; } - static address oop_disjoint_arraycopy() { return _oop_disjoint_arraycopy; } + static address oop_disjoint_arraycopy(bool dest_uninitialized = false) { + return dest_uninitialized ? _oop_disjoint_arraycopy_uninit : _oop_disjoint_arraycopy; + } static address arrayof_jbyte_arraycopy() { return _arrayof_jbyte_arraycopy; } static address arrayof_jshort_arraycopy() { return _arrayof_jshort_arraycopy; } static address arrayof_jint_arraycopy() { return _arrayof_jint_arraycopy; } static address arrayof_jlong_arraycopy() { return _arrayof_jlong_arraycopy; } - static address arrayof_oop_arraycopy() { return _arrayof_oop_arraycopy; } + static address arrayof_oop_arraycopy(bool dest_uninitialized = false) { + return dest_uninitialized ? _arrayof_oop_arraycopy_uninit : _arrayof_oop_arraycopy; + } static address arrayof_jbyte_disjoint_arraycopy() { return _arrayof_jbyte_disjoint_arraycopy; } static address arrayof_jshort_disjoint_arraycopy() { return _arrayof_jshort_disjoint_arraycopy; } static address arrayof_jint_disjoint_arraycopy() { return _arrayof_jint_disjoint_arraycopy; } static address arrayof_jlong_disjoint_arraycopy() { return _arrayof_jlong_disjoint_arraycopy; } - static address arrayof_oop_disjoint_arraycopy() { return _arrayof_oop_disjoint_arraycopy; } + static address arrayof_oop_disjoint_arraycopy(bool dest_uninitialized = false) { + return dest_uninitialized ? _arrayof_oop_disjoint_arraycopy_uninit : _arrayof_oop_disjoint_arraycopy; + } - static address checkcast_arraycopy() { return _checkcast_arraycopy; } + static address checkcast_arraycopy(bool dest_uninitialized = false) { + return dest_uninitialized ? _checkcast_arraycopy_uninit : _checkcast_arraycopy; + } static address unsafe_arraycopy() { return _unsafe_arraycopy; } static address generic_arraycopy() { return _generic_arraycopy; } @@ -352,17 +362,19 @@ // Default versions of the above arraycopy functions for platforms which do // not have specialized versions // - static void jbyte_copy (jbyte* src, jbyte* dest, size_t count); - static void jshort_copy(jshort* src, jshort* dest, size_t count); - static void jint_copy (jint* src, jint* dest, size_t count); - static void jlong_copy (jlong* src, jlong* dest, size_t count); - static void oop_copy (oop* src, oop* dest, size_t count); + static void jbyte_copy (jbyte* src, jbyte* dest, size_t count); + static void jshort_copy (jshort* src, jshort* dest, size_t count); + static void jint_copy (jint* src, jint* dest, size_t count); + static void jlong_copy (jlong* src, jlong* dest, size_t count); + static void oop_copy (oop* src, oop* dest, size_t count); + static void oop_copy_uninit(oop* src, oop* dest, size_t count); - static void arrayof_jbyte_copy (HeapWord* src, HeapWord* dest, size_t count); - static void arrayof_jshort_copy(HeapWord* src, HeapWord* dest, size_t count); - static void arrayof_jint_copy (HeapWord* src, HeapWord* dest, size_t count); - static void arrayof_jlong_copy (HeapWord* src, HeapWord* dest, size_t count); - static void arrayof_oop_copy (HeapWord* src, HeapWord* dest, size_t count); + static void arrayof_jbyte_copy (HeapWord* src, HeapWord* dest, size_t count); + static void arrayof_jshort_copy (HeapWord* src, HeapWord* dest, size_t count); + static void arrayof_jint_copy (HeapWord* src, HeapWord* dest, size_t count); + static void arrayof_jlong_copy (HeapWord* src, HeapWord* dest, size_t count); + static void arrayof_oop_copy (HeapWord* src, HeapWord* dest, size_t count); + static void arrayof_oop_copy_uninit(HeapWord* src, HeapWord* dest, size_t count); }; #endif // SHARE_VM_RUNTIME_STUBROUTINES_HPP
--- a/src/share/vm/runtime/sweeper.cpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/runtime/sweeper.cpp Fri Mar 18 09:03:43 2011 -0700 @@ -426,9 +426,7 @@ tty->vprint(format, ap); va_end(ap); } - tty->print_cr(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'" - " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'", - CodeCache::nof_blobs(), CodeCache::nof_nmethods(), CodeCache::nof_adapters(), CodeCache::unallocated_capacity()); + CodeCache::log_state(tty); tty->cr(); } if (LogCompilation && (xtty != NULL)) { @@ -440,9 +438,7 @@ xtty->vprint(format, ap); va_end(ap); } - xtty->print(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'" - " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'", - CodeCache::nof_blobs(), CodeCache::nof_nmethods(), CodeCache::nof_adapters(), CodeCache::unallocated_capacity()); + CodeCache::log_state(xtty); xtty->stamp(); xtty->end_elem(); }
--- a/src/share/vm/utilities/macros.hpp Thu Mar 17 10:32:46 2011 -0700 +++ b/src/share/vm/utilities/macros.hpp Fri Mar 18 09:03:43 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -161,6 +161,14 @@ #define NOT_WINDOWS(code) code #endif +#ifdef _WIN64 +#define WIN64_ONLY(code) code +#define NOT_WIN64(code) +#else +#define WIN64_ONLY(code) +#define NOT_WIN64(code) code +#endif + #if defined(IA32) || defined(AMD64) #define X86 #define X86_ONLY(code) code
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/compiler/6942326/Test.java Fri Mar 18 09:03:43 2011 -0700 @@ -0,0 +1,409 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test + * @bug 6942326 + * @summary x86 code in string_indexof() could read beyond reserved heap space + * + * @run main/othervm/timeout=300 -Xmx32m -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:CompileCommand=exclude,Test,main -XX:CompileCommand=exclude,Test,test_varsub_indexof -XX:CompileCommand=exclude,Test,test_varstr_indexof -XX:CompileCommand=exclude,Test,test_missub_indexof -XX:CompileCommand=exclude,Test,test_consub_indexof -XX:CompileCommand=exclude,Test,test_conmis_indexof -XX:CompileCommand=exclude,Test,test_subcon Test + * + */ + +public class Test { + + static String[] strings = new String[1024]; + private static final int ITERATIONS = 100000; + + public static void main(String[] args) { + + long start_total = System.currentTimeMillis(); + + // search variable size substring in string (33 chars). + String a = " 1111111111111xx1111111111111xx11y"; // +1 to execute a.substring(1) first + String b = "1111111111111xx1111111111111xx11y"; + test_varsub_indexof(a, b); + + // search variable size substring in string (32 chars). + a = " 1111111111111xx1111111111111xx1y"; + b = "1111111111111xx1111111111111xx1y"; + test_varsub_indexof(a, b); + + // search variable size substring in string (17 chars). + a = " 1111111111111xx1y"; + b = "1111111111111xx1y"; + test_varsub_indexof(a, b); + + // search variable size substring in string (16 chars). + a = " 111111111111xx1y"; + b = "111111111111xx1y"; + test_varsub_indexof(a, b); + + // search variable size substring in string (8 chars). + a = " 1111xx1y"; + b = "1111xx1y"; + test_varsub_indexof(a, b); + + // search variable size substring in string (7 chars). + a = " 111xx1y"; + b = "111xx1y"; + test_varsub_indexof(a, b); + + + + // search substring (17 chars) in variable size string. + a = "1111111111111xx1x"; + b = " 1111111111111xx1111111111111xx1x"; // +1 to execute b.substring(1) first + test_varstr_indexof(a, b); + + // search substring (16 chars) in variable size string. + a = "111111111111xx1x"; + b = " 1111111111111xx1111111111111xx1x"; + test_varstr_indexof(a, b); + + // search substring (9 chars) in variable size string. + a = "11111xx1x"; + b = " 1111111111111xx1111111111111xx1x"; + test_varstr_indexof(a, b); + + // search substring (8 chars) in variable size string. + a = "1111xx1x"; + b = " 1111111111111xx1111111111111xx1x"; + test_varstr_indexof(a, b); + + // search substring (4 chars) in variable size string. + a = "xx1x"; + b = " 1111111111111xx1111111111111xx1x"; + test_varstr_indexof(a, b); + + // search substring (3 chars) in variable size string. + a = "x1x"; + b = " 1111111111111xx1111111111111xx1x"; + test_varstr_indexof(a, b); + + // search substring (2 chars) in variable size string. + a = "1y"; + b = " 1111111111111xx1111111111111xx1y"; + test_varstr_indexof(a, b); + + + + // search non matching variable size substring in string (33 chars). + a = " 1111111111111xx1111111111111xx11z"; // +1 to execute a.substring(1) first + b = "1111111111111xx1111111111111xx11y"; + test_missub_indexof(a, b); + + // search non matching variable size substring in string (32 chars). + a = " 1111111111111xx1111111111111xx1z"; + b = "1111111111111xx1111111111111xx1y"; + test_missub_indexof(a, b); + + // search non matching variable size substring in string (17 chars). + a = " 1111111111111xx1z"; + b = "1111111111111xx1y"; + test_missub_indexof(a, b); + + // search non matching variable size substring in string (16 chars). + a = " 111111111111xx1z"; + b = "111111111111xx1y"; + test_missub_indexof(a, b); + + // search non matching variable size substring in string (8 chars). + a = " 1111xx1z"; + b = "1111xx1y"; + test_missub_indexof(a, b); + + // search non matching variable size substring in string (7 chars). + a = " 111xx1z"; + b = "111xx1y"; + test_missub_indexof(a, b); + + + + // Testing constant substring search in variable size string. + + // search constant substring (17 chars). + b = " 1111111111111xx1111111111111xx1x"; // +1 to execute b.substring(1) first + TestCon tc = new TestCon17(); + test_consub_indexof(tc, b); + + // search constant substring (16 chars). + b = " 1111111111111xx1111111111111xx1x"; + tc = new TestCon16(); + test_consub_indexof(tc, b); + + // search constant substring (9 chars). + b = " 1111111111111xx1111111111111xx1x"; + tc = new TestCon9(); + test_consub_indexof(tc, b); + + // search constant substring (8 chars). + b = " 1111111111111xx1111111111111xx1x"; + tc = new TestCon8(); + test_consub_indexof(tc, b); + + // search constant substring (4 chars). + b = " 1111111111111xx1111111111111xx1x"; + tc = new TestCon4(); + test_consub_indexof(tc, b); + + // search constant substring (3 chars). + b = " 1111111111111xx1111111111111xx1x"; + tc = new TestCon3(); + test_consub_indexof(tc, b); + + // search constant substring (2 chars). + b = " 1111111111111xx1111111111111xx1y"; + tc = new TestCon2(); + test_consub_indexof(tc, b); + + // search constant substring (1 chars). + b = " 1111111111111xx1111111111111xx1y"; + tc = new TestCon1(); + test_consub_indexof(tc, b); + + + // search non matching constant substring (17 chars). + b = " 1111111111111xx1111111111111xx1z"; // +1 to execute b.substring(1) first + tc = new TestCon17(); + test_conmis_indexof(tc, b); + + // search non matching constant substring (16 chars). + b = " 1111111111111xx1111111111111xx1z"; + tc = new TestCon16(); + test_conmis_indexof(tc, b); + + // search non matching constant substring (9 chars). + b = " 1111111111111xx1111111111111xx1z"; + tc = new TestCon9(); + test_conmis_indexof(tc, b); + + // search non matching constant substring (8 chars). + b = " 1111111111111xx1111111111111xx1z"; + tc = new TestCon8(); + test_conmis_indexof(tc, b); + + // search non matching constant substring (4 chars). + b = " 1111111111111xx1111111111111xx1z"; + tc = new TestCon4(); + test_conmis_indexof(tc, b); + + // search non matching constant substring (3 chars). + b = " 1111111111111xx1111111111111xx1z"; + tc = new TestCon3(); + test_conmis_indexof(tc, b); + + // search non matching constant substring (2 chars). + b = " 1111111111111xx1111111111111xx1z"; + tc = new TestCon2(); + test_conmis_indexof(tc, b); + + // search non matching constant substring (1 chars). + b = " 1111111111111xx1111111111111xx1z"; + tc = new TestCon1(); + test_conmis_indexof(tc, b); + + long end_total = System.currentTimeMillis(); + System.out.println("End run time: " + (end_total - start_total)); + + } + + public static long test_init(String a, String b) { + for (int i = 0; i < 512; i++) { + strings[i * 2] = new String(b.toCharArray()); + strings[i * 2 + 1] = new String(a.toCharArray()); + } + System.out.print(a.length() + " " + b.length() + " "); + return System.currentTimeMillis(); + } + + public static void test_end(String a, String b, int v, int expected, long start) { + long end = System.currentTimeMillis(); + int res = (v/ITERATIONS); + System.out.print(" " + res); + System.out.println(" time:" + (end - start)); + if (res != expected) { + System.out.println("wrong indexOf result: " + res + ", expected " + expected); + System.out.println("\"" + b + "\".indexOf(\"" + a + "\")"); + System.exit(97); + } + } + + public static int test_subvar() { + int s = 0; + int v = 0; + for (int i = 0; i < ITERATIONS; i++) { + v += strings[s].indexOf(strings[s + 1]); + s += 2; + if (s >= strings.length) s = 0; + } + return v; + } + + public static void test_varsub_indexof(String a, String b) { + System.out.println("Start search variable size substring in string (" + b.length() + " chars)"); + long start_it = System.currentTimeMillis(); + int limit = 1; // last a.length() == 1 + while (a.length() > limit) { + a = a.substring(1); + long start = test_init(a, b); + int v = test_subvar(); + test_end(a, b, v, (b.length() - a.length()), start); + } + long end_it = System.currentTimeMillis(); + System.out.println("End search variable size substring in string (" + b.length() + " chars), time: " + (end_it - start_it)); + } + + public static void test_varstr_indexof(String a, String b) { + System.out.println("Start search substring (" + a.length() + " chars) in variable size string"); + long start_it = System.currentTimeMillis(); + int limit = a.length(); + while (b.length() > limit) { + b = b.substring(1); + long start = test_init(a, b); + int v = test_subvar(); + test_end(a, b, v, (b.length() - a.length()), start); + } + long end_it = System.currentTimeMillis(); + System.out.println("End search substring (" + a.length() + " chars) in variable size string, time: " + (end_it - start_it)); + } + + public static void test_missub_indexof(String a, String b) { + System.out.println("Start search non matching variable size substring in string (" + b.length() + " chars)"); + long start_it = System.currentTimeMillis(); + int limit = 1; // last a.length() == 1 + while (a.length() > limit) { + a = a.substring(1); + long start = test_init(a, b); + int v = test_subvar(); + test_end(a, b, v, (-1), start); + } + long end_it = System.currentTimeMillis(); + System.out.println("End search non matching variable size substring in string (" + b.length() + " chars), time: " + (end_it - start_it)); + } + + + + public static void test_consub_indexof(TestCon tc, String b) { + System.out.println("Start search constant substring (" + tc.constr().length() + " chars)"); + long start_it = System.currentTimeMillis(); + int limit = tc.constr().length(); + while (b.length() > limit) { + b = b.substring(1); + long start = test_init(tc.constr(), b); + int v = test_subcon(tc); + test_end(tc.constr(), b, v, (b.length() - tc.constr().length()), start); + } + long end_it = System.currentTimeMillis(); + System.out.println("End search constant substring (" + tc.constr().length() + " chars), time: " + (end_it - start_it)); + } + + public static void test_conmis_indexof(TestCon tc, String b) { + System.out.println("Start search non matching constant substring (" + tc.constr().length() + " chars)"); + long start_it = System.currentTimeMillis(); + int limit = tc.constr().length(); + while (b.length() > limit) { + b = b.substring(1); + long start = test_init(tc.constr(), b); + int v = test_subcon(tc); + test_end(tc.constr(), b, v, (-1), start); + } + long end_it = System.currentTimeMillis(); + System.out.println("End search non matching constant substring (" + tc.constr().length() + " chars), time: " + (end_it - start_it)); + } + + public static int test_subcon(TestCon tc) { + int s = 0; + int v = 0; + for (int i = 0; i < ITERATIONS; i++) { + v += tc.indexOf(strings[s]); + s += 2; + if (s >= strings.length) s = 0; + } + return v; + } + + private interface TestCon { + public String constr(); + public int indexOf(String str); + } + + // search constant substring (17 chars). + private final static class TestCon17 implements TestCon { + private static final String constr = "1111111111111xx1x"; + public String constr() { return constr; } + public int indexOf(String str) { return str.indexOf(constr); } + } + + // search constant substring (16 chars). + private final static class TestCon16 implements TestCon { + private static final String constr = "111111111111xx1x"; + public String constr() { return constr; } + public int indexOf(String str) { return str.indexOf(constr); } + } + + // search constant substring (9 chars). + private final static class TestCon9 implements TestCon { + private static final String constr = "11111xx1x"; + public String constr() { return constr; } + public int indexOf(String str) { return str.indexOf(constr); } + } + + // search constant substring (8 chars). + private final static class TestCon8 implements TestCon { + private static final String constr = "1111xx1x"; + public String constr() { return constr; } + public int indexOf(String str) { return str.indexOf(constr); } + } + + // search constant substring (4 chars). + private final static class TestCon4 implements TestCon { + private static final String constr = "xx1x"; + public String constr() { return constr; } + public int indexOf(String str) { return str.indexOf(constr); } + } + + // search constant substring (3 chars). + private final static class TestCon3 implements TestCon { + private static final String constr = "x1x"; + public String constr() { return constr; } + public int indexOf(String str) { return str.indexOf(constr); } + } + + // search constant substring (2 chars). + private final static class TestCon2 implements TestCon { + private static final String constr = "1y"; + public String constr() { return constr; } + public int indexOf(String str) { return str.indexOf(constr); } + } + + + // search constant substring (1 chars). + private final static class TestCon1 implements TestCon { + private static final String constr = "y"; + public String constr() { return constr; } + public int indexOf(String str) { return str.indexOf(constr); } + } +} +