diff --git a/make/hotspot/gensrc/GensrcAdlc.gmk b/make/hotspot/gensrc/GensrcAdlc.gmk index 8dada3cec0a..ddb2c3e33e5 100644 --- a/make/hotspot/gensrc/GensrcAdlc.gmk +++ b/make/hotspot/gensrc/GensrcAdlc.gmk @@ -200,6 +200,13 @@ ifeq ($(call check-jvm-feature, compiler2), true) ))) endif + ifeq ($(call check-jvm-feature, g1gc), true) + AD_SRC_FILES += $(call uniq, $(wildcard $(foreach d, $(AD_SRC_ROOTS), \ + $d/cpu/$(HOTSPOT_TARGET_CPU_ARCH)/gc/g1/g1_$(HOTSPOT_TARGET_CPU).ad \ + $d/cpu/$(HOTSPOT_TARGET_CPU_ARCH)/gc/g1/g1_$(HOTSPOT_TARGET_CPU_ARCH).ad \ + ))) + endif + SINGLE_AD_SRCFILE := $(ADLC_SUPPORT_DIR)/all-ad-src.ad INSERT_FILENAME_AWK_SCRIPT := \ diff --git a/make/jdk/src/classes/build/tools/tzdb/TzdbZoneRulesCompiler.java b/make/jdk/src/classes/build/tools/tzdb/TzdbZoneRulesCompiler.java index 630d3a390d1..426d0bb10ed 100644 --- a/make/jdk/src/classes/build/tools/tzdb/TzdbZoneRulesCompiler.java +++ b/make/jdk/src/classes/build/tools/tzdb/TzdbZoneRulesCompiler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -273,7 +273,7 @@ private void outputFile(Path dstFile, String version, // link version-region-rules out.writeShort(builtZones.size()); for (Map.Entry entry : builtZones.entrySet()) { - int regionIndex = Arrays.binarySearch(regionArray, entry.getKey()); + int regionIndex = findRegionIndex(regionArray, entry.getKey()); int rulesIndex = rulesList.indexOf(entry.getValue()); out.writeShort(regionIndex); out.writeShort(rulesIndex); @@ -281,8 +281,8 @@ private void outputFile(Path dstFile, String version, // alias-region out.writeShort(links.size()); for (Map.Entry entry : links.entrySet()) { - int aliasIndex = Arrays.binarySearch(regionArray, entry.getKey()); - int regionIndex = Arrays.binarySearch(regionArray, entry.getValue()); + int aliasIndex = findRegionIndex(regionArray, entry.getKey()); + int regionIndex = findRegionIndex(regionArray, entry.getValue()); out.writeShort(aliasIndex); out.writeShort(regionIndex); } @@ -294,6 +294,14 @@ private void outputFile(Path dstFile, String version, } } + private static int findRegionIndex(String[] regionArray, String region) { + int index = Arrays.binarySearch(regionArray, region); + if (index < 0) { + throw new IllegalArgumentException("Unknown region: " + region); + } + return index; + } + /** Whether to output verbose messages. */ private boolean verbose; diff --git a/src/hotspot/cpu/aarch64/aarch64.ad b/src/hotspot/cpu/aarch64/aarch64.ad index 39eae43a287..7d2a35cefd8 100644 --- a/src/hotspot/cpu/aarch64/aarch64.ad +++ b/src/hotspot/cpu/aarch64/aarch64.ad @@ -2620,7 +2620,8 @@ static bool is_vector_bitwise_not_pattern(Node* n, Node* m) { bool Matcher::pd_clone_node(Node* n, Node* m, Matcher::MStack& mstack) { if (is_vshift_con_pattern(n, m) || is_vector_bitwise_not_pattern(n, m) || - is_valid_sve_arith_imm_pattern(n, m)) { + is_valid_sve_arith_imm_pattern(n, m) || + is_encode_and_store_pattern(n, m)) { mstack.push(m, Visit); return true; } @@ -6410,7 +6411,7 @@ instruct loadP(iRegPNoSp dst, memory mem) instruct loadN(iRegNNoSp dst, memory mem) %{ match(Set dst (LoadN mem)); - predicate(!needs_acquiring_load(n)); + predicate(!needs_acquiring_load(n) && n->as_Load()->barrier_data() == 0); ins_cost(4 * INSN_COST); format %{ "ldrw $dst, $mem\t# compressed ptr" %} @@ -6839,7 +6840,7 @@ instruct storeimmP0(immP0 zero, memory mem) instruct storeN(iRegN src, memory mem) %{ match(Set mem (StoreN mem src)); - predicate(!needs_releasing_store(n)); + predicate(!needs_releasing_store(n) && n->as_Store()->barrier_data() == 0); ins_cost(INSN_COST); format %{ "strw $src, $mem\t# compressed ptr" %} @@ -6852,7 +6853,7 @@ instruct storeN(iRegN src, memory mem) instruct storeImmN0(immN0 zero, memory mem) %{ match(Set mem (StoreN mem zero)); - predicate(!needs_releasing_store(n)); + predicate(!needs_releasing_store(n) && n->as_Store()->barrier_data() == 0); ins_cost(INSN_COST); format %{ "strw zr, $mem\t# compressed ptr" %} @@ -7086,6 +7087,7 @@ instruct loadP_volatile(iRegPNoSp dst, /* sync_memory*/indirect mem) instruct loadN_volatile(iRegNNoSp dst, /* sync_memory*/indirect mem) %{ match(Set dst (LoadN mem)); + predicate(n->as_Load()->barrier_data() == 0); ins_cost(VOLATILE_REF_COST); format %{ "ldarw $dst, $mem\t# compressed ptr" %} @@ -7253,6 +7255,7 @@ instruct storeimmP0_volatile(immP0 zero, /* sync_memory*/indirect mem) instruct storeN_volatile(iRegN src, /* sync_memory*/indirect mem) %{ match(Set mem (StoreN mem src)); + predicate(n->as_Store()->barrier_data() == 0); ins_cost(VOLATILE_REF_COST); format %{ "stlrw $src, $mem\t# compressed ptr" %} @@ -7265,6 +7268,7 @@ instruct storeN_volatile(iRegN src, /* sync_memory*/indirect mem) instruct storeimmN0_volatile(immN0 zero, /* sync_memory*/indirect mem) %{ match(Set mem (StoreN mem zero)); + predicate(n->as_Store()->barrier_data() == 0); ins_cost(VOLATILE_REF_COST); format %{ "stlrw zr, $mem\t# compressed ptr" %} @@ -8061,6 +8065,7 @@ instruct compareAndSwapP(iRegINoSp res, indirect mem, iRegP oldval, iRegP newval instruct compareAndSwapN(iRegINoSp res, indirect mem, iRegNNoSp oldval, iRegNNoSp newval, rFlagsReg cr) %{ match(Set res (CompareAndSwapN mem (Binary oldval newval))); + predicate(n->as_LoadStore()->barrier_data() == 0); ins_cost(2 * VOLATILE_REF_COST); effect(KILL cr); @@ -8175,7 +8180,7 @@ instruct compareAndSwapPAcq(iRegINoSp res, indirect mem, iRegP oldval, iRegP new instruct compareAndSwapNAcq(iRegINoSp res, indirect mem, iRegNNoSp oldval, iRegNNoSp newval, rFlagsReg cr) %{ - predicate(needs_acquiring_load_exclusive(n)); + predicate(needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() == 0); match(Set res (CompareAndSwapN mem (Binary oldval newval))); ins_cost(VOLATILE_REF_COST); @@ -8280,6 +8285,7 @@ instruct compareAndExchangeL(iRegLNoSp res, indirect mem, iRegL oldval, iRegL ne // This pattern is generated automatically from cas.m4. // DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE instruct compareAndExchangeN(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, rFlagsReg cr) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); match(Set res (CompareAndExchangeN mem (Binary oldval newval))); ins_cost(2 * VOLATILE_REF_COST); effect(TEMP_DEF res, KILL cr); @@ -8389,7 +8395,7 @@ instruct compareAndExchangeLAcq(iRegLNoSp res, indirect mem, iRegL oldval, iRegL // This pattern is generated automatically from cas.m4. // DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE instruct compareAndExchangeNAcq(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, rFlagsReg cr) %{ - predicate(needs_acquiring_load_exclusive(n)); + predicate(needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() == 0); match(Set res (CompareAndExchangeN mem (Binary oldval newval))); ins_cost(VOLATILE_REF_COST); effect(TEMP_DEF res, KILL cr); @@ -8501,6 +8507,7 @@ instruct weakCompareAndSwapL(iRegINoSp res, indirect mem, iRegL oldval, iRegL ne // This pattern is generated automatically from cas.m4. // DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE instruct weakCompareAndSwapN(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval, rFlagsReg cr) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); ins_cost(2 * VOLATILE_REF_COST); effect(KILL cr); @@ -8620,7 +8627,7 @@ instruct weakCompareAndSwapLAcq(iRegINoSp res, indirect mem, iRegL oldval, iRegL // This pattern is generated automatically from cas.m4. // DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE instruct weakCompareAndSwapNAcq(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval, rFlagsReg cr) %{ - predicate(needs_acquiring_load_exclusive(n)); + predicate(needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() == 0); match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); ins_cost(VOLATILE_REF_COST); effect(KILL cr); @@ -8681,6 +8688,7 @@ instruct get_and_setL(indirect mem, iRegL newv, iRegLNoSp prev) %{ %} instruct get_and_setN(indirect mem, iRegN newv, iRegINoSp prev) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); match(Set prev (GetAndSetN mem newv)); ins_cost(2 * VOLATILE_REF_COST); format %{ "atomic_xchgw $prev, $newv, [$mem]" %} @@ -8724,7 +8732,7 @@ instruct get_and_setLAcq(indirect mem, iRegL newv, iRegLNoSp prev) %{ %} instruct get_and_setNAcq(indirect mem, iRegN newv, iRegINoSp prev) %{ - predicate(needs_acquiring_load_exclusive(n)); + predicate(needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() == 0); match(Set prev (GetAndSetN mem newv)); ins_cost(VOLATILE_REF_COST); format %{ "atomic_xchgw_acq $prev, $newv, [$mem]" %} diff --git a/src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp index b4c12ecd4a8..62831ee72ba 100644 --- a/src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/c2_MacroAssembler_aarch64.cpp @@ -150,10 +150,12 @@ void C2_MacroAssembler::fast_unlock(Register objectReg, Register boxReg, Registe Register oop = objectReg; Register box = boxReg; Register disp_hdr = tmpReg; + Register owner_addr = tmpReg; Register tmp = tmp2Reg; Label cont; Label object_has_monitor; Label count, no_count; + Label unlocked; assert(LockingMode != LM_LIGHTWEIGHT, "lightweight locking should use fast_unlock_lightweight"); assert_different_registers(oop, box, tmp, disp_hdr); @@ -204,14 +206,40 @@ void C2_MacroAssembler::fast_unlock(Register objectReg, Register boxReg, Registe b(cont); bind(notRecursive); + + // Compute owner address. + lea(owner_addr, Address(tmp, ObjectMonitor::owner_offset())); + + // Set owner to null. + // Release to satisfy the JMM + stlr(zr, owner_addr); + // We need a full fence after clearing owner to avoid stranding. + // StoreLoad achieves this. + membar(StoreLoad); + + // Check if the entry lists are empty. ldr(rscratch1, Address(tmp, ObjectMonitor::EntryList_offset())); - ldr(disp_hdr, Address(tmp, ObjectMonitor::cxq_offset())); - orr(rscratch1, rscratch1, disp_hdr); // Will be 0 if both are 0. - cmp(rscratch1, zr); // Sets flags for result - cbnz(rscratch1, cont); - // need a release store here - lea(tmp, Address(tmp, ObjectMonitor::owner_offset())); - stlr(zr, tmp); // set unowned + ldr(tmpReg, Address(tmp, ObjectMonitor::cxq_offset())); + orr(rscratch1, rscratch1, tmpReg); + cmp(rscratch1, zr); + br(Assembler::EQ, cont); // If so we are done. + + // Check if there is a successor. + ldr(rscratch1, Address(tmp, ObjectMonitor::succ_offset())); + cmp(rscratch1, zr); + br(Assembler::NE, unlocked); // If so we are done. + + // Save the monitor pointer in the current thread, so we can try to + // reacquire the lock in SharedRuntime::monitor_exit_helper(). + str(tmp, Address(rthread, JavaThread::unlocked_inflated_monitor_offset())); + + cmp(zr, rthread); // Set Flag to NE => slow path + b(cont); + + bind(unlocked); + cmp(zr, zr); // Set Flag to EQ => fast path + + // Intentional fall-through bind(cont); // flag == EQ indicates success @@ -498,33 +526,41 @@ void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register box, Regi bind(not_recursive); - Label release; const Register t2_owner_addr = t2; // Compute owner address. lea(t2_owner_addr, Address(t1_monitor, ObjectMonitor::owner_offset())); + // Set owner to null. + // Release to satisfy the JMM + stlr(zr, t2_owner_addr); + // We need a full fence after clearing owner to avoid stranding. + // StoreLoad achieves this. + membar(StoreLoad); + // Check if the entry lists are empty. ldr(rscratch1, Address(t1_monitor, ObjectMonitor::EntryList_offset())); ldr(t3_t, Address(t1_monitor, ObjectMonitor::cxq_offset())); orr(rscratch1, rscratch1, t3_t); cmp(rscratch1, zr); - br(Assembler::EQ, release); + br(Assembler::EQ, unlocked); // If so we are done. - // The owner may be anonymous and we removed the last obj entry in - // the lock-stack. This loses the information about the owner. - // Write the thread to the owner field so the runtime knows the owner. - str(rthread, Address(t2_owner_addr)); - b(slow_path); + // Check if there is a successor. + ldr(rscratch1, Address(t1_monitor, ObjectMonitor::succ_offset())); + cmp(rscratch1, zr); + br(Assembler::NE, unlocked); // If so we are done. - bind(release); - // Set owner to null. - // Release to satisfy the JMM - stlr(zr, t2_owner_addr); + // Save the monitor pointer in the current thread, so we can try to + // reacquire the lock in SharedRuntime::monitor_exit_helper(). + str(t1_monitor, Address(rthread, JavaThread::unlocked_inflated_monitor_offset())); + + cmp(zr, rthread); // Set Flag to NE => slow path + b(slow_path); } bind(unlocked); decrement(Address(rthread, JavaThread::held_monitor_count_offset())); + cmp(zr, zr); // Set Flags to EQ => fast path #ifdef ASSERT // Check that unlocked label is reached with Flags == EQ. diff --git a/src/hotspot/cpu/aarch64/cas.m4 b/src/hotspot/cpu/aarch64/cas.m4 index f8aac0c4939..7e13e153db1 100644 --- a/src/hotspot/cpu/aarch64/cas.m4 +++ b/src/hotspot/cpu/aarch64/cas.m4 @@ -45,7 +45,9 @@ define(`CAS_INSN', // DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE instruct compareAndExchange$1$6(iReg$2NoSp res, indirect mem, iReg$2 oldval, iReg$2 newval, rFlagsReg cr) %{ ifelse($1$6,PAcq,INDENT(predicate(needs_acquiring_load_exclusive(n) && (n->as_LoadStore()->barrier_data() == 0));), + $1$6,NAcq,INDENT(predicate(needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() == 0);), $1,P,INDENT(predicate(n->as_LoadStore()->barrier_data() == 0);), + $1,N,INDENT(predicate(n->as_LoadStore()->barrier_data() == 0);), $6,Acq,INDENT(predicate(needs_acquiring_load_exclusive(n));), `dnl') match(Set res (CompareAndExchange$1 mem (Binary oldval newval))); @@ -122,7 +124,9 @@ define(`CAS_INSN3', // DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE instruct weakCompareAndSwap$1$6(iRegINoSp res, indirect mem, iReg$2 oldval, iReg$2 newval, rFlagsReg cr) %{ ifelse($1$6,PAcq,INDENT(predicate(needs_acquiring_load_exclusive(n) && (n->as_LoadStore()->barrier_data() == 0));), + $1$6,NAcq,INDENT(predicate(needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() == 0);), $1,P,INDENT(predicate(n->as_LoadStore()->barrier_data() == 0);), + $1,N,INDENT(predicate(n->as_LoadStore()->barrier_data() == 0);), $6,Acq,INDENT(predicate(needs_acquiring_load_exclusive(n));), `dnl') match(Set res (WeakCompareAndSwap$1 mem (Binary oldval newval))); diff --git a/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.cpp index d02038b6e91..b978c350ce1 100644 --- a/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.cpp @@ -38,7 +38,10 @@ #include "c1/c1_LIRAssembler.hpp" #include "c1/c1_MacroAssembler.hpp" #include "gc/g1/c1/g1BarrierSetC1.hpp" -#endif +#endif // COMPILER1 +#ifdef COMPILER2 +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#endif // COMPILER2 #define __ masm-> @@ -95,6 +98,54 @@ void G1BarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* mas __ pop(saved_regs, sp); } +static void generate_queue_test_and_insertion(MacroAssembler* masm, ByteSize index_offset, ByteSize buffer_offset, Label& runtime, + const Register thread, const Register value, const Register temp1, const Register temp2) { + // Can we store a value in the given thread's buffer? + // (The index field is typed as size_t.) + __ ldr(temp1, Address(thread, in_bytes(index_offset))); // temp1 := *(index address) + __ cbz(temp1, runtime); // jump to runtime if index == 0 (full buffer) + // The buffer is not full, store value into it. + __ sub(temp1, temp1, wordSize); // temp1 := next index + __ str(temp1, Address(thread, in_bytes(index_offset))); // *(index address) := next index + __ ldr(temp2, Address(thread, in_bytes(buffer_offset))); // temp2 := buffer address + __ str(value, Address(temp2, temp1)); // *(buffer address + next index) := value +} + +static void generate_pre_barrier_fast_path(MacroAssembler* masm, + const Register thread, + const Register tmp1) { + Address in_progress(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset())); + // Is marking active? + if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { + __ ldrw(tmp1, in_progress); + } else { + assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); + __ ldrb(tmp1, in_progress); + } +} + +static void generate_pre_barrier_slow_path(MacroAssembler* masm, + const Register obj, + const Register pre_val, + const Register thread, + const Register tmp1, + const Register tmp2, + Label& done, + Label& runtime) { + // Do we need to load the previous value? + if (obj != noreg) { + __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW); + } + // Is the previous value null? + __ cbz(pre_val, done); + generate_queue_test_and_insertion(masm, + G1ThreadLocalData::satb_mark_queue_index_offset(), + G1ThreadLocalData::satb_mark_queue_buffer_offset(), + runtime, + thread, pre_val, tmp1, tmp2); + __ b(done); +} + void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Register obj, Register pre_val, @@ -115,43 +166,10 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, assert_different_registers(obj, pre_val, tmp1, tmp2); assert(pre_val != noreg && tmp1 != noreg && tmp2 != noreg, "expecting a register"); - Address in_progress(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset())); - Address index(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_index_offset())); - Address buffer(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_buffer_offset())); - - // Is marking active? - if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { - __ ldrw(tmp1, in_progress); - } else { - assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); - __ ldrb(tmp1, in_progress); - } + generate_pre_barrier_fast_path(masm, thread, tmp1); + // If marking is not active (*(mark queue active address) == 0), jump to done __ cbzw(tmp1, done); - - // Do we need to load the previous value? - if (obj != noreg) { - __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW); - } - - // Is the previous value null? - __ cbz(pre_val, done); - - // Can we store original value in the thread's buffer? - // Is index == 0? - // (The index field is typed as size_t.) - - __ ldr(tmp1, index); // tmp := *index_adr - __ cbz(tmp1, runtime); // tmp == 0? - // If yes, goto runtime - - __ sub(tmp1, tmp1, wordSize); // tmp := tmp - wordSize - __ str(tmp1, index); // *index_adr := tmp - __ ldr(tmp2, buffer); - __ add(tmp1, tmp1, tmp2); // tmp := tmp + *buffer_adr - - // Record the previous value - __ str(pre_val, Address(tmp1, 0)); - __ b(done); + generate_pre_barrier_slow_path(masm, obj, pre_val, thread, tmp1, tmp2, done, runtime); __ bind(runtime); @@ -182,6 +200,50 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, } +static void generate_post_barrier_fast_path(MacroAssembler* masm, + const Register store_addr, + const Register new_val, + const Register tmp1, + const Register tmp2, + Label& done, + bool new_val_may_be_null) { + // Does store cross heap regions? + __ eor(tmp1, store_addr, new_val); // tmp1 := store address ^ new value + __ lsr(tmp1, tmp1, G1HeapRegion::LogOfHRGrainBytes); // tmp1 := ((store address ^ new value) >> LogOfHRGrainBytes) + __ cbz(tmp1, done); + // Crosses regions, storing null? + if (new_val_may_be_null) { + __ cbz(new_val, done); + } + // Storing region crossing non-null, is card young? + __ lsr(tmp1, store_addr, CardTable::card_shift()); // tmp1 := card address relative to card table base + __ load_byte_map_base(tmp2); // tmp2 := card table base address + __ add(tmp1, tmp1, tmp2); // tmp1 := card address + __ ldrb(tmp2, Address(tmp1)); // tmp2 := card + __ cmpw(tmp2, (int)G1CardTable::g1_young_card_val()); // tmp2 := card == young_card_val? +} + +static void generate_post_barrier_slow_path(MacroAssembler* masm, + const Register thread, + const Register tmp1, + const Register tmp2, + Label& done, + Label& runtime) { + __ membar(Assembler::StoreLoad); // StoreLoad membar + __ ldrb(tmp2, Address(tmp1)); // tmp2 := card + __ cbzw(tmp2, done); + // Storing a region crossing, non-null oop, card is clean. + // Dirty card and log. + STATIC_ASSERT(CardTable::dirty_card_val() == 0); + __ strb(zr, Address(tmp1)); // *(card address) := dirty_card_val + generate_queue_test_and_insertion(masm, + G1ThreadLocalData::dirty_card_queue_index_offset(), + G1ThreadLocalData::dirty_card_queue_buffer_offset(), + runtime, + thread, tmp1, tmp2, rscratch1); + __ b(done); +} + void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, Register store_addr, Register new_val, @@ -194,70 +256,116 @@ void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, assert(store_addr != noreg && new_val != noreg && tmp1 != noreg && tmp2 != noreg, "expecting a register"); - Address queue_index(thread, in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset())); - Address buffer(thread, in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset())); - - BarrierSet* bs = BarrierSet::barrier_set(); - CardTableBarrierSet* ctbs = barrier_set_cast(bs); - CardTable* ct = ctbs->card_table(); - Label done; Label runtime; - // Does store cross heap regions? + generate_post_barrier_fast_path(masm, store_addr, new_val, tmp1, tmp2, done, true /* new_val_may_be_null */); + // If card is young, jump to done + __ br(Assembler::EQ, done); + generate_post_barrier_slow_path(masm, thread, tmp1, tmp2, done, runtime); - __ eor(tmp1, store_addr, new_val); - __ lsr(tmp1, tmp1, G1HeapRegion::LogOfHRGrainBytes); - __ cbz(tmp1, done); + __ bind(runtime); + // save the live input values + RegSet saved = RegSet::of(store_addr); + __ push(saved, sp); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry), tmp1, thread); + __ pop(saved, sp); - // crosses regions, storing null? + __ bind(done); +} - __ cbz(new_val, done); +#if defined(COMPILER2) - // storing region crossing non-null, is card already dirty? +static void generate_c2_barrier_runtime_call(MacroAssembler* masm, G1BarrierStubC2* stub, const Register arg, const address runtime_path) { + SaveLiveRegisters save_registers(masm, stub); + if (c_rarg0 != arg) { + __ mov(c_rarg0, arg); + } + __ mov(c_rarg1, rthread); + __ mov(rscratch1, runtime_path); + __ blr(rscratch1); +} - const Register card_addr = tmp1; +void G1BarrierSetAssembler::g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register thread, + Register tmp1, + Register tmp2, + G1PreBarrierStubC2* stub) { + assert(thread == rthread, "must be"); + assert_different_registers(obj, pre_val, tmp1, tmp2); + assert(pre_val != noreg && tmp1 != noreg && tmp2 != noreg, "expecting a register"); - __ lsr(card_addr, store_addr, CardTable::card_shift()); + stub->initialize_registers(obj, pre_val, thread, tmp1, tmp2); - // get the address of the card - __ load_byte_map_base(tmp2); - __ add(card_addr, card_addr, tmp2); - __ ldrb(tmp2, Address(card_addr)); - __ cmpw(tmp2, (int)G1CardTable::g1_young_card_val()); - __ br(Assembler::EQ, done); + generate_pre_barrier_fast_path(masm, thread, tmp1); + // If marking is active (*(mark queue active address) != 0), jump to stub (slow path) + __ cbnzw(tmp1, *stub->entry()); - assert((int)CardTable::dirty_card_val() == 0, "must be 0"); + __ bind(*stub->continuation()); +} - __ membar(Assembler::StoreLoad); +void G1BarrierSetAssembler::generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const { + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + Register obj = stub->obj(); + Register pre_val = stub->pre_val(); + Register thread = stub->thread(); + Register tmp1 = stub->tmp1(); + Register tmp2 = stub->tmp2(); - __ ldrb(tmp2, Address(card_addr)); - __ cbzw(tmp2, done); + __ bind(*stub->entry()); + generate_pre_barrier_slow_path(masm, obj, pre_val, thread, tmp1, tmp2, *stub->continuation(), runtime); - // storing a region crossing, non-null oop, card is clean. - // dirty card and log. + __ bind(runtime); + generate_c2_barrier_runtime_call(masm, stub, pre_val, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_pre_entry)); + __ b(*stub->continuation()); +} - __ strb(zr, Address(card_addr)); +void G1BarrierSetAssembler::g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register thread, + Register tmp1, + Register tmp2, + G1PostBarrierStubC2* stub) { + assert(thread == rthread, "must be"); + assert_different_registers(store_addr, new_val, thread, tmp1, tmp2, + rscratch1); + assert(store_addr != noreg && new_val != noreg && tmp1 != noreg + && tmp2 != noreg, "expecting a register"); - __ ldr(rscratch1, queue_index); - __ cbz(rscratch1, runtime); - __ sub(rscratch1, rscratch1, wordSize); - __ str(rscratch1, queue_index); + stub->initialize_registers(thread, tmp1, tmp2); - __ ldr(tmp2, buffer); - __ str(card_addr, Address(tmp2, rscratch1)); - __ b(done); + bool new_val_may_be_null = (stub->barrier_data() & G1C2BarrierPostNotNull) == 0; + generate_post_barrier_fast_path(masm, store_addr, new_val, tmp1, tmp2, *stub->continuation(), new_val_may_be_null); + // If card is not young, jump to stub (slow path) + __ br(Assembler::NE, *stub->entry()); - __ bind(runtime); - // save the live input values - RegSet saved = RegSet::of(store_addr); - __ push(saved, sp); - __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry), card_addr, thread); - __ pop(saved, sp); + __ bind(*stub->continuation()); +} - __ bind(done); +void G1BarrierSetAssembler::generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const { + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + Register thread = stub->thread(); + Register tmp1 = stub->tmp1(); // tmp1 holds the card address. + Register tmp2 = stub->tmp2(); + assert(stub->tmp3() == noreg, "not needed in this platform"); + + __ bind(*stub->entry()); + generate_post_barrier_slow_path(masm, thread, tmp1, tmp2, *stub->continuation(), runtime); + + __ bind(runtime); + generate_c2_barrier_runtime_call(masm, stub, tmp1, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry)); + __ b(*stub->continuation()); } +#endif // COMPILER2 + void G1BarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register dst, Address src, Register tmp1, Register tmp2) { bool on_oop = is_reference_type(type); diff --git a/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.hpp b/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.hpp index 7b4bc8cdc49..4baa18cb945 100644 --- a/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.hpp +++ b/src/hotspot/cpu/aarch64/gc/g1/g1BarrierSetAssembler_aarch64.hpp @@ -33,6 +33,8 @@ class LIR_Assembler; class StubAssembler; class G1PreBarrierStub; class G1PostBarrierStub; +class G1PreBarrierStubC2; +class G1PostBarrierStubC2; class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { protected: @@ -69,6 +71,27 @@ class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { void generate_c1_post_barrier_runtime_stub(StubAssembler* sasm); #endif +#ifdef COMPILER2 + void g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register thread, + Register tmp1, + Register tmp2, + G1PreBarrierStubC2* c2_stub); + void generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const; + void g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register thread, + Register tmp1, + Register tmp2, + G1PostBarrierStubC2* c2_stub); + void generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const; +#endif + void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register dst, Address src, Register tmp1, Register tmp2); }; diff --git a/src/hotspot/cpu/aarch64/gc/g1/g1_aarch64.ad b/src/hotspot/cpu/aarch64/gc/g1/g1_aarch64.ad new file mode 100644 index 00000000000..081a67d6880 --- /dev/null +++ b/src/hotspot/cpu/aarch64/gc/g1/g1_aarch64.ad @@ -0,0 +1,680 @@ +// +// Copyright (c) 2024, 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. +// + +source_hpp %{ + +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#include "gc/shared/gc_globals.hpp" + +%} + +source %{ + +#include "gc/g1/g1BarrierSetAssembler_aarch64.hpp" +#include "gc/g1/g1BarrierSetRuntime.hpp" + +static void write_barrier_pre(MacroAssembler* masm, + const MachNode* node, + Register obj, + Register pre_val, + Register tmp1, + Register tmp2, + RegSet preserve = RegSet(), + RegSet no_preserve = RegSet()) { + if (!G1PreBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PreBarrierStubC2* const stub = G1PreBarrierStubC2::create(node); + for (RegSetIterator reg = preserve.begin(); *reg != noreg; ++reg) { + stub->preserve(*reg); + } + for (RegSetIterator reg = no_preserve.begin(); *reg != noreg; ++reg) { + stub->dont_preserve(*reg); + } + g1_asm->g1_write_barrier_pre_c2(masm, obj, pre_val, rthread, tmp1, tmp2, stub); +} + +static void write_barrier_post(MacroAssembler* masm, + const MachNode* node, + Register store_addr, + Register new_val, + Register tmp1, + Register tmp2) { + if (!G1PostBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PostBarrierStubC2* const stub = G1PostBarrierStubC2::create(node); + g1_asm->g1_write_barrier_post_c2(masm, store_addr, new_val, rthread, tmp1, tmp2, stub); +} + +%} + +// BEGIN This section of the file is automatically generated. Do not edit -------------- + +// This section is generated from g1_aarch64.m4 + + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1StoreP(indirect mem, iRegP src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_releasing_store(n) && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreP mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(INSN_COST); + format %{ "str $src, $mem\t# ptr" %} + ins_encode %{ + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ str($src$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(istore_reg_mem); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1StorePVolatile(indirect mem, iRegP src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && needs_releasing_store(n) && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreP mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(VOLATILE_REF_COST); + format %{ "stlr $src, $mem\t# ptr" %} + ins_encode %{ + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ stlr($src$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_class_memory); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1StoreN(indirect mem, iRegN src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_releasing_store(n) && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(INSN_COST); + format %{ "strw $src, $mem\t# compressed ptr" %} + ins_encode %{ + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ strw($src$$Register, $mem$$Register); + if ((barrier_data() & G1C2BarrierPost) != 0) { + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ decode_heap_oop($tmp1$$Register, $src$$Register); + } else { + __ decode_heap_oop_not_null($tmp1$$Register, $src$$Register); + } + } + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(istore_reg_mem); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1StoreNVolatile(indirect mem, iRegN src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && needs_releasing_store(n) && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(VOLATILE_REF_COST); + format %{ "stlrw $src, $mem\t# compressed ptr" %} + ins_encode %{ + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ stlrw($src$$Register, $mem$$Register); + if ((barrier_data() & G1C2BarrierPost) != 0) { + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ decode_heap_oop($tmp1$$Register, $src$$Register); + } else { + __ decode_heap_oop_not_null($tmp1$$Register, $src$$Register); + } + } + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_class_memory); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1EncodePAndStoreN(indirect mem, iRegP src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_releasing_store(n) && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem (EncodeP src))); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(INSN_COST); + format %{ "encode_heap_oop $tmp1, $src\n\t" + "strw $tmp1, $mem\t# compressed ptr" %} + ins_encode %{ + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ encode_heap_oop($tmp1$$Register, $src$$Register); + } else { + __ encode_heap_oop_not_null($tmp1$$Register, $src$$Register); + } + __ strw($tmp1$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(istore_reg_mem); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1EncodePAndStoreNVolatile(indirect mem, iRegP src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && needs_releasing_store(n) && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem (EncodeP src))); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(VOLATILE_REF_COST); + format %{ "encode_heap_oop $tmp1, $src\n\t" + "stlrw $tmp1, $mem\t# compressed ptr" %} + ins_encode %{ + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ encode_heap_oop($tmp1$$Register, $src$$Register); + } else { + __ encode_heap_oop_not_null($tmp1$$Register, $src$$Register); + } + __ stlrw($tmp1$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_class_memory); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndExchangeP(iRegPNoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "cmpxchg $res = $mem, $oldval, $newval\t# ptr" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + // Pass $oldval to the pre-barrier (instead of loading from $mem), because + // $oldval is the only value that can be overwritten. + // The same holds for g1CompareAndSwapP and its Acq variant. + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::xword, + false /* acquire */, true /* release */, false /* weak */, $res$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndExchangePAcq(iRegPNoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, rFlagsReg cr) +%{ + predicate(UseG1GC && needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(VOLATILE_REF_COST); + format %{ "cmpxchg_acq $res = $mem, $oldval, $newval\t# ptr" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + // Pass $oldval to the pre-barrier (instead of loading from $mem), because + // $oldval is the only value that can be overwritten. + // The same holds for g1CompareAndSwapP and its Acq variant. + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::xword, + true /* acquire */, true /* release */, false /* weak */, $res$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndExchangeN(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "cmpxchg $res = $mem, $oldval, $newval\t# narrow oop" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::word, + false /* acquire */, true /* release */, false /* weak */, $res$$Register); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndExchangeNAcq(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(VOLATILE_REF_COST); + format %{ "cmpxchg_acq $res = $mem, $oldval, $newval\t# narrow oop" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::word, + true /* acquire */, true /* release */, false /* weak */, $res$$Register); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndSwapP(iRegINoSp res, indirect mem, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegP oldval, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapP mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "cmpxchg $mem, $oldval, $newval\t# (ptr)\n\t" + "cset $res, EQ" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::xword, + false /* acquire */, true /* release */, false /* weak */, noreg); + __ cset($res$$Register, Assembler::EQ); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndSwapPAcq(iRegINoSp res, indirect mem, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegP oldval, rFlagsReg cr) +%{ + predicate(UseG1GC && needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapP mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(VOLATILE_REF_COST); + format %{ "cmpxchg_acq $mem, $oldval, $newval\t# (ptr)\n\t" + "cset $res, EQ" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::xword, + true /* acquire */, true /* release */, false /* weak */, noreg); + __ cset($res$$Register, Assembler::EQ); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndSwapN(iRegINoSp res, indirect mem, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, iRegN oldval, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapN mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "cmpxchg $mem, $oldval, $newval\t# (narrow oop)\n\t" + "cset $res, EQ" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::word, + false /* acquire */, true /* release */, false /* weak */, noreg); + __ cset($res$$Register, Assembler::EQ); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndSwapNAcq(iRegINoSp res, indirect mem, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, iRegN oldval, rFlagsReg cr) +%{ + predicate(UseG1GC && needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapN mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(VOLATILE_REF_COST); + format %{ "cmpxchg_acq $mem, $oldval, $newval\t# (narrow oop)\n\t" + "cset $res, EQ" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::word, + true /* acquire */, true /* release */, false /* weak */, noreg); + __ cset($res$$Register, Assembler::EQ); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1GetAndSetP(indirect mem, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp preval, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetP mem newval)); + effect(TEMP preval, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "atomic_xchg $preval, $newval, [$mem]" %} + ins_encode %{ + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $preval$$Register /* pre_val (as a temporary register) */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + __ atomic_xchg($preval$$Register, $newval$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_serial); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1GetAndSetPAcq(indirect mem, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp preval, rFlagsReg cr) +%{ + predicate(UseG1GC && needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetP mem newval)); + effect(TEMP preval, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(VOLATILE_REF_COST); + format %{ "atomic_xchg_acq $preval, $newval, [$mem]" %} + ins_encode %{ + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $preval$$Register /* pre_val (as a temporary register) */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + __ atomic_xchgal($preval$$Register, $newval$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_serial); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1GetAndSetN(indirect mem, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, iRegNNoSp preval, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetN mem newval)); + effect(TEMP preval, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "atomic_xchgw $preval, $newval, [$mem]" %} + ins_encode %{ + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + __ atomic_xchgw($preval$$Register, $newval$$Register, $mem$$Register); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_serial); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1GetAndSetNAcq(indirect mem, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, iRegNNoSp preval, rFlagsReg cr) +%{ + predicate(UseG1GC && needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetN mem newval)); + effect(TEMP preval, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(VOLATILE_REF_COST); + format %{ "atomic_xchgw_acq $preval, $newval, [$mem]" %} + ins_encode %{ + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + __ atomic_xchgalw($preval$$Register, $newval$$Register, $mem$$Register); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_serial); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1LoadP(iRegPNoSp dst, indirect mem, iRegPNoSp tmp1, iRegPNoSp tmp2, rFlagsReg cr) +%{ + // This instruction does not need an acquiring counterpart because it is only + // used for reference loading (Reference::get()). The same holds for g1LoadN. + predicate(UseG1GC && !needs_acquiring_load(n) && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadP mem)); + effect(TEMP dst, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(4 * INSN_COST); + format %{ "ldr $dst, $mem\t# ptr" %} + ins_encode %{ + __ ldr($dst$$Register, $mem$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $dst$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(iload_reg_mem); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1LoadN(iRegNNoSp dst, indirect mem, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_acquiring_load(n) && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadN mem)); + effect(TEMP dst, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(4 * INSN_COST); + format %{ "ldrw $dst, $mem\t# compressed ptr" %} + ins_encode %{ + __ ldrw($dst$$Register, $mem$$Register); + if ((barrier_data() & G1C2BarrierPre) != 0) { + __ decode_heap_oop($tmp1$$Register, $dst$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + } + %} + ins_pipe(iload_reg_mem); +%} + +// END This section of the file is automatically generated. Do not edit -------------- diff --git a/src/hotspot/cpu/aarch64/gc/g1/g1_aarch64.m4 b/src/hotspot/cpu/aarch64/gc/g1/g1_aarch64.m4 new file mode 100644 index 00000000000..8fb1f7e8e42 --- /dev/null +++ b/src/hotspot/cpu/aarch64/gc/g1/g1_aarch64.m4 @@ -0,0 +1,384 @@ +dnl Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. +dnl DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +dnl +dnl This code is free software; you can redistribute it and/or modify it +dnl under the terms of the GNU General Public License version 2 only, as +dnl published by the Free Software Foundation. +dnl +dnl This code is distributed in the hope that it will be useful, but WITHOUT +dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +dnl FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +dnl version 2 for more details (a copy is included in the LICENSE file that +dnl accompanied this code). +dnl +dnl You should have received a copy of the GNU General Public License version +dnl 2 along with this work; if not, write to the Free Software Foundation, +dnl Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +dnl +dnl Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +dnl or visit www.oracle.com if you need additional information or have any +dnl questions. +dnl +// BEGIN This section of the file is automatically generated. Do not edit -------------- + +// This section is generated from g1_aarch64.m4 + +define(`STOREP_INSN', +` +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1StoreP$1(indirect mem, iRegP src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && ifelse($1,Volatile,'needs_releasing_store(n)`,'!needs_releasing_store(n)`) && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreP mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(ifelse($1,Volatile,VOLATILE_REF_COST,INSN_COST)); + format %{ "$2 $src, $mem\t# ptr" %} + ins_encode %{ + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ $2($src$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(ifelse($1,Volatile,pipe_class_memory,istore_reg_mem)); +%}')dnl +STOREP_INSN(,str) +STOREP_INSN(Volatile,stlr) +dnl +define(`STOREN_INSN', +` +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1StoreN$1(indirect mem, iRegN src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && ifelse($1,Volatile,'needs_releasing_store(n)`,'!needs_releasing_store(n)`) && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(ifelse($1,Volatile,VOLATILE_REF_COST,INSN_COST)); + format %{ "$2 $src, $mem\t# compressed ptr" %} + ins_encode %{ + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ $2($src$$Register, $mem$$Register); + if ((barrier_data() & G1C2BarrierPost) != 0) { + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ decode_heap_oop($tmp1$$Register, $src$$Register); + } else { + __ decode_heap_oop_not_null($tmp1$$Register, $src$$Register); + } + } + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(ifelse($1,Volatile,pipe_class_memory,istore_reg_mem)); +%}')dnl +STOREN_INSN(,strw) +STOREN_INSN(Volatile,stlrw) +dnl +define(`ENCODESTOREN_INSN', +` +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1EncodePAndStoreN$1(indirect mem, iRegP src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && ifelse($1,Volatile,'needs_releasing_store(n)`,'!needs_releasing_store(n)`) && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem (EncodeP src))); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(ifelse($1,Volatile,VOLATILE_REF_COST,INSN_COST)); + format %{ "encode_heap_oop $tmp1, $src\n\t" + "$2 $tmp1, $mem\t# compressed ptr" %} + ins_encode %{ + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ encode_heap_oop($tmp1$$Register, $src$$Register); + } else { + __ encode_heap_oop_not_null($tmp1$$Register, $src$$Register); + } + __ $2($tmp1$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(ifelse($1,Volatile,pipe_class_memory,istore_reg_mem)); +%}')dnl +ENCODESTOREN_INSN(,strw) +ENCODESTOREN_INSN(Volatile,stlrw) +dnl +define(`CAEP_INSN', +` +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndExchangeP$1(iRegPNoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, rFlagsReg cr) +%{ + predicate(UseG1GC && ifelse($1,Acq,'needs_acquiring_load_exclusive(n)`,'!needs_acquiring_load_exclusive(n)`) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(ifelse($1,Acq,VOLATILE_REF_COST,2 * VOLATILE_REF_COST)); + format %{ "cmpxchg$2 $res = $mem, $oldval, $newval\t# ptr" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + // Pass $oldval to the pre-barrier (instead of loading from $mem), because + // $oldval is the only value that can be overwritten. + // The same holds for g1CompareAndSwapP and its Acq variant. + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::xword, + $3 /* acquire */, true /* release */, false /* weak */, $res$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%}')dnl +CAEP_INSN(,,false) +CAEP_INSN(Acq,_acq,true) +dnl +define(`CAEN_INSN', +` +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndExchangeN$1(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && ifelse($1,Acq,'needs_acquiring_load_exclusive(n)`,'!needs_acquiring_load_exclusive(n)`) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(ifelse($1,Acq,VOLATILE_REF_COST,2 * VOLATILE_REF_COST)); + format %{ "cmpxchg$2 $res = $mem, $oldval, $newval\t# narrow oop" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::word, + $3 /* acquire */, true /* release */, false /* weak */, $res$$Register); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%}')dnl +CAEN_INSN(,,false) +CAEN_INSN(Acq,_acq,true) +dnl +define(`CASP_INSN', +` +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndSwapP$1(iRegINoSp res, indirect mem, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegP oldval, rFlagsReg cr) +%{ + predicate(UseG1GC && ifelse($1,Acq,'needs_acquiring_load_exclusive(n)`,'!needs_acquiring_load_exclusive(n)`) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapP mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(ifelse($1,Acq,VOLATILE_REF_COST,2 * VOLATILE_REF_COST)); + format %{ "cmpxchg$2 $mem, $oldval, $newval\t# (ptr)\n\t" + "cset $res, EQ" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::xword, + $3 /* acquire */, true /* release */, false /* weak */, noreg); + __ cset($res$$Register, Assembler::EQ); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%}')dnl +CASP_INSN(,,false) +CASP_INSN(Acq,_acq,true) +dnl +define(`CASN_INSN', +` +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1CompareAndSwapN$1(iRegINoSp res, indirect mem, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, iRegN oldval, rFlagsReg cr) +%{ + predicate(UseG1GC && ifelse($1,Acq,'needs_acquiring_load_exclusive(n)`,'!needs_acquiring_load_exclusive(n)`) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapN mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(ifelse($1,Acq,VOLATILE_REF_COST,2 * VOLATILE_REF_COST)); + format %{ "cmpxchg$2 $mem, $oldval, $newval\t# (narrow oop)\n\t" + "cset $res, EQ" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::word, + $3 /* acquire */, true /* release */, false /* weak */, noreg); + __ cset($res$$Register, Assembler::EQ); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%}')dnl +CASN_INSN(,,false) +CASN_INSN(Acq,_acq,true) +dnl +define(`XCHGP_INSN', +` +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1GetAndSetP$1(indirect mem, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp preval, rFlagsReg cr) +%{ + predicate(UseG1GC && ifelse($1,Acq,'needs_acquiring_load_exclusive(n)`,'!needs_acquiring_load_exclusive(n)`) && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetP mem newval)); + effect(TEMP preval, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(ifelse($1,Acq,VOLATILE_REF_COST,2 * VOLATILE_REF_COST)); + format %{ "atomic_xchg$2 $preval, $newval, [$mem]" %} + ins_encode %{ + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $preval$$Register /* pre_val (as a temporary register) */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + __ $3($preval$$Register, $newval$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_serial); +%}')dnl +XCHGP_INSN(,,atomic_xchg) +XCHGP_INSN(Acq,_acq,atomic_xchgal) +dnl +define(`XCHGN_INSN', +` +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1GetAndSetN$1(indirect mem, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, iRegNNoSp preval, rFlagsReg cr) +%{ + predicate(UseG1GC && ifelse($1,Acq,'needs_acquiring_load_exclusive(n)`,'!needs_acquiring_load_exclusive(n)`) && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetN mem newval)); + effect(TEMP preval, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(ifelse($1,Acq,VOLATILE_REF_COST,2 * VOLATILE_REF_COST)); + format %{ "$2 $preval, $newval, [$mem]" %} + ins_encode %{ + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + __ $3($preval$$Register, $newval$$Register, $mem$$Register); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_serial); +%}')dnl +XCHGN_INSN(,atomic_xchgw,atomic_xchgw) +XCHGN_INSN(Acq,atomic_xchgw_acq,atomic_xchgalw) + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1LoadP(iRegPNoSp dst, indirect mem, iRegPNoSp tmp1, iRegPNoSp tmp2, rFlagsReg cr) +%{ + // This instruction does not need an acquiring counterpart because it is only + // used for reference loading (Reference::get()). The same holds for g1LoadN. + predicate(UseG1GC && !needs_acquiring_load(n) && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadP mem)); + effect(TEMP dst, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(4 * INSN_COST); + format %{ "ldr $dst, $mem\t# ptr" %} + ins_encode %{ + __ ldr($dst$$Register, $mem$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $dst$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(iload_reg_mem); +%} + +// This pattern is generated automatically from g1_aarch64.m4. +// DO NOT EDIT ANYTHING IN THIS SECTION OF THE FILE +instruct g1LoadN(iRegNNoSp dst, indirect mem, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && !needs_acquiring_load(n) && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadN mem)); + effect(TEMP dst, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(4 * INSN_COST); + format %{ "ldrw $dst, $mem\t# compressed ptr" %} + ins_encode %{ + __ ldrw($dst$$Register, $mem$$Register); + if ((barrier_data() & G1C2BarrierPre) != 0) { + __ decode_heap_oop($tmp1$$Register, $dst$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + } + %} + ins_pipe(iload_reg_mem); +%} + +// END This section of the file is automatically generated. Do not edit -------------- diff --git a/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp index 06f43820156..84d06dbcc7b 100644 --- a/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp @@ -67,9 +67,9 @@ void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, Dec __ push(saved_regs, sp); if (UseCompressedOops) { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_narrow_oop_entry), src, dst, count); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_narrow_oop), src, dst, count); } else { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_oop_entry), src, dst, count); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_oop), src, dst, count); } __ pop(saved_regs, sp); __ bind(done); @@ -164,9 +164,9 @@ void ShenandoahBarrierSetAssembler::satb_write_barrier_pre(MacroAssembler* masm, if (expand_call) { assert(pre_val != c_rarg1, "smashed arg"); - __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread); + __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), pre_val, thread); } else { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), pre_val, thread); } __ pop(saved, sp); @@ -698,7 +698,7 @@ void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAss __ bind(runtime); __ push_call_clobbered_registers(); __ load_parameter(0, pre_val); - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), pre_val, thread); __ pop_call_clobbered_registers(); __ bind(done); diff --git a/src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp b/src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp index 1b02108b00f..52996f4c4a5 100644 --- a/src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp @@ -2234,7 +2234,7 @@ void SharedRuntime::generate_deopt_blob() { int reexecute_offset = __ pc() - start; #if INCLUDE_JVMCI && !defined(COMPILER1) - if (EnableJVMCI && UseJVMCICompiler) { + if (UseJVMCICompiler) { // JVMCI does not use this kind of deoptimization __ should_not_reach_here(); } diff --git a/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp b/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp index b3513a586de..eb235f8472c 100644 --- a/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp @@ -3417,15 +3417,15 @@ class StubGenerator: public StubCodeGenerator { Register rscratch3 = r10; Register rscratch4 = r11; - __ andw(rscratch3, r2, r4); - __ bicw(rscratch4, r3, r4); reg_cache.extract_u32(rscratch1, k); __ movw(rscratch2, t); - __ orrw(rscratch3, rscratch3, rscratch4); __ addw(rscratch4, r1, rscratch2); __ addw(rscratch4, rscratch4, rscratch1); - __ addw(rscratch3, rscratch3, rscratch4); - __ rorw(rscratch2, rscratch3, 32 - s); + __ bicw(rscratch2, r3, r4); + __ andw(rscratch3, r2, r4); + __ addw(rscratch2, rscratch2, rscratch4); + __ addw(rscratch2, rscratch2, rscratch3); + __ rorw(rscratch2, rscratch2, 32 - s); __ addw(r1, rscratch2, r2); } diff --git a/src/hotspot/cpu/arm/arm.ad b/src/hotspot/cpu/arm/arm.ad index 2c7de0a58a2..716f6d87230 100644 --- a/src/hotspot/cpu/arm/arm.ad +++ b/src/hotspot/cpu/arm/arm.ad @@ -3890,6 +3890,7 @@ instruct loadRange(iRegI dst, memoryI mem) %{ instruct loadP(iRegP dst, memoryP mem) %{ + predicate(!(UseG1GC && n->as_Load()->barrier_data() != 0)); match(Set dst (LoadP mem)); ins_cost(MEMORY_REF_COST); size(4); @@ -4356,6 +4357,7 @@ instruct movSP(store_ptr_RegP dst, SPRegP src) %{ instruct storeP(memoryP mem, store_ptr_RegP src) %{ + predicate(!(UseG1GC && n->as_Store()->barrier_data() != 0)); match(Set mem (StoreP mem src)); ins_cost(MEMORY_REF_COST); size(4); @@ -5390,6 +5392,7 @@ instruct compareAndSwapI_bool(memoryex mem, iRegI oldval, iRegI newval, iRegI re %} instruct compareAndSwapP_bool(memoryex mem, iRegP oldval, iRegP newval, iRegI res, iRegI tmp, flagsReg ccr ) %{ + predicate(!(UseG1GC && n->as_LoadStore()->barrier_data() != 0)); match(Set res (CompareAndSwapP mem (Binary oldval newval))); effect( KILL ccr, TEMP tmp); size(28); @@ -5659,6 +5662,7 @@ instruct xchgL(memoryex mem, iRegLd newval, iRegLd res, iRegI tmp, flagsReg ccr) %} instruct xchgP(memoryex mem, iRegP newval, iRegP res, iRegI tmp, flagsReg ccr) %{ + predicate(!(UseG1GC && n->as_LoadStore()->barrier_data() != 0)); match(Set res (GetAndSetP mem newval)); effect(KILL ccr, TEMP tmp, TEMP res); size(16); diff --git a/src/hotspot/cpu/arm/assembler_arm_32.hpp b/src/hotspot/cpu/arm/assembler_arm_32.hpp index dd04ad1ab3a..e53eefac097 100644 --- a/src/hotspot/cpu/arm/assembler_arm_32.hpp +++ b/src/hotspot/cpu/arm/assembler_arm_32.hpp @@ -119,8 +119,9 @@ class RegisterSet { } friend RegisterSet operator | (const RegisterSet set1, const RegisterSet set2) { - assert((set1._encoding & set2._encoding) == 0, - "encoding constraint"); +// why so strong constraint? +// assert((set1._encoding & set2._encoding) == 0, +// "encoding constraint"); return RegisterSet(set1._encoding | set2._encoding); } @@ -142,6 +143,11 @@ class RegisterSet { } return count; } + + static RegisterSet from(RegSet set) { + assert(set.size(), "RegSet must not be empty"); + return RegisterSet(set.bits()); + } }; #if R9_IS_SCRATCHED @@ -157,6 +163,10 @@ class FloatRegisterSet { public: + FloatRegisterSet() { + _encoding = 0; + } + FloatRegisterSet(FloatRegister reg) { if (reg->hi_bit() == 0) { _encoding = reg->hi_bits() << 12 | reg->lo_bit() << 22 | 1; @@ -185,6 +195,15 @@ class FloatRegisterSet { return (_encoding & 0xFFFFFF00) | ((_encoding & 0xFF) << 1); } + static FloatRegisterSet from(FloatRegSet set) { + assert(set.size(), "FloatRegSet must not be empty"); + // the vector load/store instructions operate on a set of consecutive registers. + // for the sake of simplicity, write all registers between the first and last in the set + size_t range = (*set.rbegin())->encoding() - (*set.begin())->encoding() + 1; + // push_float stores float regisgters by pairs + return FloatRegisterSet(*set.begin(), (range+1)/2); + } + }; diff --git a/src/hotspot/cpu/arm/gc/g1/g1BarrierSetAssembler_arm.cpp b/src/hotspot/cpu/arm/gc/g1/g1BarrierSetAssembler_arm.cpp index 3c5e29aa871..56ae7707fbf 100644 --- a/src/hotspot/cpu/arm/gc/g1/g1BarrierSetAssembler_arm.cpp +++ b/src/hotspot/cpu/arm/gc/g1/g1BarrierSetAssembler_arm.cpp @@ -39,8 +39,10 @@ #include "c1/c1_LIRAssembler.hpp" #include "c1/c1_MacroAssembler.hpp" #include "gc/g1/c1/g1BarrierSetC1.hpp" -#endif - +#endif // COMPILER1 +#ifdef COMPILER2 +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#endif // COMPILER2 #define __ masm-> #ifdef PRODUCT @@ -106,70 +108,87 @@ void G1BarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* mas #endif // !R9_IS_SCRATCHED } -// G1 pre-barrier. -// Blows all volatile registers R0-R3, Rtemp, LR). -// If store_addr != noreg, then previous value is loaded from [store_addr]; -// in such case store_addr and new_val registers are preserved; -// otherwise pre_val register is preserved. -void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, - Register store_addr, - Register new_val, - Register pre_val, - Register tmp1, - Register tmp2) { - Label done; - Label runtime; - - if (store_addr != noreg) { - assert_different_registers(store_addr, new_val, pre_val, tmp1, tmp2, noreg); - } else { - assert (new_val == noreg, "should be"); - assert_different_registers(pre_val, tmp1, tmp2, noreg); - } - - Address in_progress(Rthread, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset())); - Address index(Rthread, in_bytes(G1ThreadLocalData::satb_mark_queue_index_offset())); - Address buffer(Rthread, in_bytes(G1ThreadLocalData::satb_mark_queue_buffer_offset())); +static void generate_queue_test_and_insertion(MacroAssembler* masm, ByteSize index_offset, ByteSize buffer_offset, Label& runtime, + const Register thread, const Register value, const Register temp1, const Register temp2) { + assert_different_registers(value, temp1, temp2); + // Can we store original value in the thread's buffer? + // (The index field is typed as size_t.) + __ ldr(temp1, Address(thread, in_bytes(index_offset))); // temp1 := *(index address) + __ cbz(temp1, runtime); // jump to runtime if index == 0 (full buffer) + // The buffer is not full, store value into it. + __ sub(temp1, temp1, wordSize); // temp1 := next index + __ str(temp1, Address(thread, in_bytes(index_offset))); // *(index address) := next index + __ ldr(temp2, Address(thread, in_bytes(buffer_offset))); // temp2 := buffer address + // Record the previous value + __ str(value, Address(temp2, temp1)); // *(buffer address + next index) := value + } +static void generate_pre_barrier_fast_path(MacroAssembler* masm, + const Register thread, + const Register tmp1) { + Address in_progress(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset())); // Is marking active? assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "adjust this code"); __ ldrb(tmp1, in_progress); - __ cbz(tmp1, done); +} +static void generate_pre_barrier_slow_path(MacroAssembler* masm, + const Register obj, + const Register pre_val, + const Register thread, + const Register tmp1, + const Register tmp2, + Label& done, + Label& runtime) { // Do we need to load the previous value? - if (store_addr != noreg) { - __ load_heap_oop(pre_val, Address(store_addr, 0)); + if (obj != noreg) { + __ load_heap_oop(pre_val, Address(obj, 0)); } // Is the previous value null? __ cbz(pre_val, done); - // Can we store original value in the thread's buffer? - // Is index == 0? - // (The index field is typed as size_t.) + generate_queue_test_and_insertion(masm, + G1ThreadLocalData::satb_mark_queue_index_offset(), + G1ThreadLocalData::satb_mark_queue_buffer_offset(), + runtime, + thread, pre_val, tmp1, tmp2); + __ b(done); +} - __ ldr(tmp1, index); // tmp1 := *index_adr - __ ldr(tmp2, buffer); +// G1 pre-barrier. +// Blows all volatile registers R0-R3, LR). +// If obj != noreg, then previous value is loaded from [obj]; +// in such case obj and pre_val registers is preserved; +// otherwise pre_val register is preserved. +void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, + Register obj, + Register pre_val, + Register tmp1, + Register tmp2) { + Label done; + Label runtime; - __ subs(tmp1, tmp1, wordSize); // tmp1 := tmp1 - wordSize - __ b(runtime, lt); // If negative, goto runtime + assert_different_registers(obj, pre_val, tmp1, tmp2, noreg); - __ str(tmp1, index); // *index_adr := tmp1 + generate_pre_barrier_fast_path(masm, Rthread, tmp1); + // If marking is not active (*(mark queue active address) == 0), jump to done + __ cbz(tmp1, done); - // Record the previous value - __ str(pre_val, Address(tmp2, tmp1)); - __ b(done); + generate_pre_barrier_slow_path(masm, obj, pre_val, Rthread, tmp1, tmp2, done, runtime); __ bind(runtime); // save the live input values - if (store_addr != noreg) { - // avoid raw_push to support any ordering of store_addr and new_val - __ push(RegisterSet(store_addr) | RegisterSet(new_val)); - } else { - __ push(pre_val); + RegisterSet set = RegisterSet(pre_val) | RegisterSet(R0, R3) | RegisterSet(R12); + // save the live input values + if (obj != noreg) { + // avoid raw_push to support any ordering of store_addr and pre_val + set = set | RegisterSet(obj); } + __ push(set); + if (pre_val != R0) { __ mov(R0, pre_val); } @@ -177,33 +196,17 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_pre_entry), R0, R1); - if (store_addr != noreg) { - __ pop(RegisterSet(store_addr) | RegisterSet(new_val)); - } else { - __ pop(pre_val); - } - + __ pop(set); __ bind(done); } -// G1 post-barrier. -// Blows all volatile registers R0-R3, Rtemp, LR). -void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, - Register store_addr, - Register new_val, - Register tmp1, - Register tmp2, - Register tmp3) { - - Address queue_index(Rthread, in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset())); - Address buffer(Rthread, in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset())); - - BarrierSet* bs = BarrierSet::barrier_set(); - CardTableBarrierSet* ctbs = barrier_set_cast(bs); - CardTable* ct = ctbs->card_table(); - Label done; - Label runtime; - +static void generate_post_barrier_fast_path(MacroAssembler* masm, + const Register store_addr, + const Register new_val, + const Register tmp1, + const Register tmp2, + Label& done, + bool new_val_may_be_null) { // Does store cross heap regions? __ eor(tmp1, store_addr, new_val); @@ -211,22 +214,31 @@ void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, __ b(done, eq); // crosses regions, storing null? - - __ cbz(new_val, done); - + if (new_val_may_be_null) { + __ cbz(new_val, done); + } // storing region crossing non-null, is card already dirty? const Register card_addr = tmp1; - __ mov_address(tmp2, (address)ct->byte_map_base()); + CardTableBarrierSet* ct = barrier_set_cast(BarrierSet::barrier_set()); + __ mov_address(tmp2, (address)ct->card_table()->byte_map_base()); __ add(card_addr, tmp2, AsmOperand(store_addr, lsr, CardTable::card_shift())); __ ldrb(tmp2, Address(card_addr)); __ cmp(tmp2, (int)G1CardTable::g1_young_card_val()); - __ b(done, eq); +} +static void generate_post_barrier_slow_path(MacroAssembler* masm, + const Register thread, + const Register tmp1, + const Register tmp2, + const Register tmp3, + Label& done, + Label& runtime) { __ membar(MacroAssembler::Membar_mask_bits(MacroAssembler::StoreLoad), tmp2); - assert(CardTable::dirty_card_val() == 0, "adjust this code"); + // card_addr is loaded by generate_post_barrier_fast_path + const Register card_addr = tmp1; __ ldrb(tmp2, Address(card_addr)); __ cbz(tmp2, done); @@ -234,29 +246,139 @@ void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, // dirty card and log. __ strb(__ zero_register(tmp2), Address(card_addr)); + generate_queue_test_and_insertion(masm, + G1ThreadLocalData::dirty_card_queue_index_offset(), + G1ThreadLocalData::dirty_card_queue_buffer_offset(), + runtime, + thread, card_addr, tmp2, tmp3); + __ b(done); +} - __ ldr(tmp2, queue_index); - __ ldr(tmp3, buffer); - __ subs(tmp2, tmp2, wordSize); - __ b(runtime, lt); // go to runtime if now negative - - __ str(tmp2, queue_index); +// G1 post-barrier. +// Blows all volatile registers R0-R3, LR). +void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register tmp1, + Register tmp2, + Register tmp3) { + Label done; + Label runtime; - __ str(card_addr, Address(tmp3, tmp2)); - __ b(done); + generate_post_barrier_fast_path(masm, store_addr, new_val, tmp1, tmp2, done, true /* new_val_may_be_null */); + // If card is young, jump to done + // card_addr and card are loaded by generate_post_barrier_fast_path + const Register card = tmp2; + const Register card_addr = tmp1; + __ b(done, eq); + generate_post_barrier_slow_path(masm, Rthread, card_addr, tmp2, tmp3, done, runtime); __ bind(runtime); + RegisterSet set = RegisterSet(store_addr) | RegisterSet(R0, R3) | RegisterSet(R12); + __ push(set); + if (card_addr != R0) { __ mov(R0, card_addr); } __ mov(R1, Rthread); __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry), R0, R1); + __ pop(set); + __ bind(done); } +#if defined(COMPILER2) + +static void generate_c2_barrier_runtime_call(MacroAssembler* masm, G1BarrierStubC2* stub, const Register arg, const address runtime_path, Register tmp1) { + SaveLiveRegisters save_registers(masm, stub); + if (c_rarg0 != arg) { + __ mov(c_rarg0, arg); + } + __ mov(c_rarg1, Rthread); + __ call_VM_leaf(runtime_path, R0, R1); +} + +void G1BarrierSetAssembler::g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register thread, + Register tmp1, + Register tmp2, + G1PreBarrierStubC2* stub) { + assert(thread == Rthread, "must be"); + assert_different_registers(obj, pre_val, tmp1, tmp2); + assert(pre_val != noreg && tmp1 != noreg && tmp2 != noreg, "expecting a register"); + + stub->initialize_registers(obj, pre_val, thread, tmp1, tmp2); + + generate_pre_barrier_fast_path(masm, thread, tmp1); + // If marking is active (*(mark queue active address) != 0), jump to stub (slow path) + __ cbnz(tmp1, *stub->entry()); + + __ bind(*stub->continuation()); +} + +void G1BarrierSetAssembler::generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const { + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + Register obj = stub->obj(); + Register pre_val = stub->pre_val(); + Register thread = stub->thread(); + Register tmp1 = stub->tmp1(); + Register tmp2 = stub->tmp2(); + + __ bind(*stub->entry()); + generate_pre_barrier_slow_path(masm, obj, pre_val, thread, tmp1, tmp2, *stub->continuation(), runtime); + + __ bind(runtime); + generate_c2_barrier_runtime_call(masm, stub, pre_val, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_pre_entry), tmp1); + __ b(*stub->continuation()); +} + +void G1BarrierSetAssembler::g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register thread, + Register tmp1, + Register tmp2, + Register tmp3, + G1PostBarrierStubC2* stub) { + assert(thread == Rthread, "must be"); + assert_different_registers(store_addr, new_val, thread, tmp1, tmp2, noreg); + + stub->initialize_registers(thread, tmp1, tmp2, tmp3); + + bool new_val_may_be_null = (stub->barrier_data() & G1C2BarrierPostNotNull) == 0; + generate_post_barrier_fast_path(masm, store_addr, new_val, tmp1, tmp2, *stub->continuation(), new_val_may_be_null); + // If card is not young, jump to stub (slow path) + __ b(*stub->entry(), ne); + + __ bind(*stub->continuation()); +} + +void G1BarrierSetAssembler::generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const { + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + Register thread = stub->thread(); + Register tmp1 = stub->tmp1(); // tmp1 holds the card address. + Register tmp2 = stub->tmp2(); + Register tmp3 = stub->tmp3(); + + __ bind(*stub->entry()); + generate_post_barrier_slow_path(masm, thread, tmp1, tmp2, tmp3, *stub->continuation(), runtime); + + __ bind(runtime); + generate_c2_barrier_runtime_call(masm, stub, tmp1, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry), tmp2); + __ b(*stub->continuation()); +} + +#endif // COMPILER2 + void G1BarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register dst, Address src, Register tmp1, Register tmp2, Register tmp3) { bool on_oop = type == T_OBJECT || type == T_ARRAY; @@ -268,7 +390,7 @@ void G1BarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorator if (on_oop && on_reference) { // Generate the G1 pre-barrier code to log the value of // the referent field in an SATB buffer. - g1_write_barrier_pre(masm, noreg, noreg, dst, tmp1, tmp2); + g1_write_barrier_pre(masm, noreg, dst, tmp1, tmp2); } } @@ -295,7 +417,7 @@ void G1BarrierSetAssembler::oop_store_at(MacroAssembler* masm, DecoratorSet deco } if (needs_pre_barrier) { - g1_write_barrier_pre(masm, store_addr, new_val, tmp1, tmp2, tmp3); + g1_write_barrier_pre(masm, store_addr, tmp3 /*pre_val*/, tmp1, tmp2); } if (is_null) { diff --git a/src/hotspot/cpu/arm/gc/g1/g1BarrierSetAssembler_arm.hpp b/src/hotspot/cpu/arm/gc/g1/g1BarrierSetAssembler_arm.hpp index 52932faa3e4..aefde19142e 100644 --- a/src/hotspot/cpu/arm/gc/g1/g1BarrierSetAssembler_arm.hpp +++ b/src/hotspot/cpu/arm/gc/g1/g1BarrierSetAssembler_arm.hpp @@ -33,6 +33,8 @@ class LIR_Assembler; class StubAssembler; class G1PreBarrierStub; class G1PostBarrierStub; +class G1PreBarrierStubC2; +class G1PostBarrierStubC2; class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { protected: @@ -43,7 +45,6 @@ class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { void g1_write_barrier_pre(MacroAssembler* masm, Register store_addr, - Register new_val, Register pre_val, Register tmp1, Register tmp2); @@ -70,6 +71,29 @@ class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { void generate_c1_pre_barrier_runtime_stub(StubAssembler* sasm); void generate_c1_post_barrier_runtime_stub(StubAssembler* sasm); #endif + +#ifdef COMPILER2 + void g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register thread, + Register tmp1, + Register tmp2, + G1PreBarrierStubC2* c2_stub); + void generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const; + void g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register thread, + Register tmp1, + Register tmp2, + Register tmp3, + G1PostBarrierStubC2* c2_stub); + void generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const; +#endif + }; #endif // CPU_ARM_GC_G1_G1BARRIERSETASSEMBLER_ARM_HPP diff --git a/src/hotspot/cpu/arm/gc/g1/g1_arm.ad b/src/hotspot/cpu/arm/gc/g1/g1_arm.ad new file mode 100644 index 00000000000..8a0a9e1aa53 --- /dev/null +++ b/src/hotspot/cpu/arm/gc/g1/g1_arm.ad @@ -0,0 +1,201 @@ +// +// Copyright (c) 2024, 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. +// + +source_hpp %{ + +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#include "gc/shared/gc_globals.hpp" + +%} + +source %{ + +#include "gc/g1/g1BarrierSetAssembler_arm.hpp" +#include "gc/g1/g1BarrierSetRuntime.hpp" + +static void write_barrier_pre(MacroAssembler* masm, + const MachNode* node, + Register obj, + Register pre_val, + Register tmp1, + Register tmp2, + RegSet preserve = RegSet(), + RegSet no_preserve = RegSet()) { + if (!G1PreBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PreBarrierStubC2* const stub = G1PreBarrierStubC2::create(node); + for (RegSetIterator reg = preserve.begin(); *reg != noreg; ++reg) { + stub->preserve(*reg); + } + for (RegSetIterator reg = no_preserve.begin(); *reg != noreg; ++reg) { + stub->dont_preserve(*reg); + } + g1_asm->g1_write_barrier_pre_c2(masm, obj, pre_val, Rthread, tmp1, tmp2, stub); +} + +static void write_barrier_post(MacroAssembler* masm, + const MachNode* node, + Register store_addr, + Register new_val, + Register tmp1, + Register tmp2, + Register tmp3) { + if (!G1PostBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PostBarrierStubC2* const stub = G1PostBarrierStubC2::create(node); + g1_asm->g1_write_barrier_post_c2(masm, store_addr, new_val, Rthread, tmp1, tmp2, tmp3, stub); +} + +%} + +instruct g1StoreP(indirect mem, iRegP src, iRegP tmp1, iRegP tmp2, iRegP tmp3, flagsReg icc) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreP mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL icc); + ins_cost(2 * (MEMORY_REF_COST + BRANCH_COST)); + format %{ "sd $src, $mem\t# ptr" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ str($src$$Register, Address($mem$$Register)); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + $tmp3$$Register /* tmp3 */); + %} + ins_pipe(istore_mem_reg); +%} + +instruct g1CompareAndSwapP(iRegI res, indirect mem, iRegP newval, iRegP tmp1, iRegP tmp2, iRegP tmp3, iRegP oldval, flagsReg ccr ) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapP mem (Binary oldval newval))); + effect(KILL ccr, TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(4 * (MEMORY_REF_COST + BRANCH_COST)); + format %{ "loop: \n\t" + "LDREX $tmp1, $mem\t! If $oldval==[$mem] Then store $newval into [$mem]\n\t" + "CMP $tmp1, $oldval\n\t" + "STREX.eq $tmp1, $newval, $mem\n\t" + "MOV.ne $tmp1, 0 \n\t" + "EORS.eq $tmp1,$tmp1, 1 \n\t" + "B.eq loop \n\t" + "MOV $res, $tmp1" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + Label loop; + __ bind(loop); + __ ldrex($tmp1$$Register,$mem$$Address); + __ cmp($tmp1$$Register, $oldval$$Register); + __ strex($tmp1$$Register, $newval$$Register, $mem$$Address, eq); + __ mov($tmp1$$Register, 0, ne); + __ eors($tmp1$$Register, $tmp1$$Register, 1, eq); + __ b(loop, eq); + __ mov($res$$Register, $tmp1$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + $tmp3$$Register /* tmp3 */); + %} + ins_pipe(long_memory_op); +%} + + +instruct g1GetAndSetP(indirect mem, iRegP newval, iRegP tmp1, iRegP tmp2, iRegP tmp3, iRegP preval, flagsReg ccr) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetP mem newval)); + effect(KILL ccr, TEMP preval, TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(4 * (MEMORY_REF_COST + BRANCH_COST)); + format %{ "loop: \n\t" + "LDREX $preval, $mem\n\t" + "STREX $tmp1, $newval, $mem\n\t" + "CMP $tmp1, 0 \n\t" + "B.ne loop \n\t" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $preval$$Register /* pre_val (as a temporary register) */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + Label loop; + __ bind(loop); + __ ldrex($preval$$Register,$mem$$Address); + __ strex($tmp1$$Register, $newval$$Register, $mem$$Address); + __ cmp($tmp1$$Register, 0); + __ b(loop, ne); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + $tmp3$$Register /* tmp3 */); + %} + ins_pipe(long_memory_op); +%} + +instruct g1LoadP(iRegP dst, indirect mem, iRegP tmp1, iRegP tmp2, flagsReg icc) +%{ + predicate(UseG1GC && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadP mem)); + effect(TEMP dst, TEMP tmp1, TEMP tmp2, KILL icc); + ins_cost(MEMORY_REF_COST + BRANCH_COST); + format %{ "ld $dst, $mem\t# ptr" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + __ ldr($dst$$Register, Address($mem$$Register)); + write_barrier_pre(masm, this, + noreg /* obj */, + $dst$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(iload_mem); +%} diff --git a/src/hotspot/cpu/arm/gc/shared/barrierSetAssembler_arm.cpp b/src/hotspot/cpu/arm/gc/shared/barrierSetAssembler_arm.cpp index ea19730673c..c13a259a1b9 100644 --- a/src/hotspot/cpu/arm/gc/shared/barrierSetAssembler_arm.cpp +++ b/src/hotspot/cpu/arm/gc/shared/barrierSetAssembler_arm.cpp @@ -31,6 +31,10 @@ #include "runtime/javaThread.hpp" #include "runtime/stubRoutines.hpp" +#ifdef COMPILER2 +#include "gc/shared/c2/barrierSetC2.hpp" +#endif // COMPILER2 + #define __ masm-> void BarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, @@ -206,7 +210,57 @@ void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm) { #ifdef COMPILER2 OptoReg::Name BarrierSetAssembler::refine_register(const Node* node, OptoReg::Name opto_reg) { - Unimplemented(); // This must be implemented to support late barrier expansion. + if (!OptoReg::is_reg(opto_reg)) { + return OptoReg::Bad; + } + + const VMReg vm_reg = OptoReg::as_VMReg(opto_reg); + if (!vm_reg->is_valid()){ + // skip APSR and FPSCR + return OptoReg::Bad; + } + + return opto_reg; } +void SaveLiveRegisters::initialize(BarrierStubC2* stub) { + // Record registers that needs to be saved/restored + RegMaskIterator rmi(stub->preserve_set()); + while (rmi.has_next()) { + const OptoReg::Name opto_reg = rmi.next(); + if (OptoReg::is_reg(opto_reg)) { + const VMReg vm_reg = OptoReg::as_VMReg(opto_reg); + if (vm_reg->is_Register()) { + gp_regs += RegSet::of(vm_reg->as_Register()); + } else if (vm_reg->is_FloatRegister()) { + fp_regs += FloatRegSet::of(vm_reg->as_FloatRegister()); + } else { + fatal("Unknown register type"); + } + } + } + // Remove C-ABI SOE registers that will be updated + gp_regs -= RegSet::range(R4, R11) + RegSet::of(R13, R15); + + // Remove C-ABI SOE fp registers + fp_regs -= FloatRegSet::range(S16, S31); +} + +SaveLiveRegisters::SaveLiveRegisters(MacroAssembler* masm, BarrierStubC2* stub) + : masm(masm), + gp_regs(), + fp_regs() { + // Figure out what registers to save/restore + initialize(stub); + + // Save registers + if (gp_regs.size() > 0) __ push(RegisterSet::from(gp_regs)); + if (fp_regs.size() > 0) __ fpush(FloatRegisterSet::from(fp_regs)); +} + +SaveLiveRegisters::~SaveLiveRegisters() { + // Restore registers + if (fp_regs.size() > 0) __ fpop(FloatRegisterSet::from(fp_regs)); + if (gp_regs.size() > 0) __ pop(RegisterSet::from(gp_regs)); +} #endif // COMPILER2 diff --git a/src/hotspot/cpu/arm/gc/shared/barrierSetAssembler_arm.hpp b/src/hotspot/cpu/arm/gc/shared/barrierSetAssembler_arm.hpp index 60021390ea2..054d172f463 100644 --- a/src/hotspot/cpu/arm/gc/shared/barrierSetAssembler_arm.hpp +++ b/src/hotspot/cpu/arm/gc/shared/barrierSetAssembler_arm.hpp @@ -31,7 +31,9 @@ #ifdef COMPILER2 #include "code/vmreg.hpp" #include "opto/optoreg.hpp" +#include "opto/regmask.hpp" +class BarrierStubC2; class Node; #endif // COMPILER2 @@ -69,4 +71,26 @@ class BarrierSetAssembler: public CHeapObj { #endif // COMPILER2 }; +#ifdef COMPILER2 +// This class saves and restores the registers that need to be preserved across +// the runtime call represented by a given C2 barrier stub. Use as follows: +// { +// SaveLiveRegisters save(masm, stub); +// .. +// __ bl(...); +// .. +// } +class SaveLiveRegisters { +private: + MacroAssembler* const masm; + RegSet gp_regs; + FloatRegSet fp_regs; + +public: + void initialize(BarrierStubC2* stub); + SaveLiveRegisters(MacroAssembler* masm, BarrierStubC2* stub); + ~SaveLiveRegisters(); +}; + +#endif // COMPILER2 #endif // CPU_ARM_GC_SHARED_BARRIERSETASSEMBLER_ARM_HPP diff --git a/src/hotspot/cpu/arm/register_arm.hpp b/src/hotspot/cpu/arm/register_arm.hpp index 9f486d2a625..d8961fd2935 100644 --- a/src/hotspot/cpu/arm/register_arm.hpp +++ b/src/hotspot/cpu/arm/register_arm.hpp @@ -303,6 +303,31 @@ class ConcreteRegisterImpl : public AbstractRegisterImpl { static const int max_fpr; }; +typedef AbstractRegSet RegSet; +typedef AbstractRegSet FloatRegSet; + +template <> +inline Register AbstractRegSet::first() { + if (_bitset == 0) { return noreg; } + return as_Register(count_trailing_zeros(_bitset)); +} + + +template <> +inline FloatRegister AbstractRegSet::first() { + uint32_t first = _bitset & -_bitset; + return first ? as_FloatRegister(exact_log2(first)) : fnoreg; +} + +template <> +inline FloatRegister AbstractRegSet::last() { + if (_bitset == 0) { return fnoreg; } + int last = max_size() - 1 - count_leading_zeros(_bitset); + return as_FloatRegister(last); +} + + + class VFPSystemRegisterImpl; typedef VFPSystemRegisterImpl* VFPSystemRegister; class VFPSystemRegisterImpl : public AbstractRegisterImpl { diff --git a/src/hotspot/cpu/arm/templateInterpreterGenerator_arm.cpp b/src/hotspot/cpu/arm/templateInterpreterGenerator_arm.cpp index 679f07a028e..ec9d237e50d 100644 --- a/src/hotspot/cpu/arm/templateInterpreterGenerator_arm.cpp +++ b/src/hotspot/cpu/arm/templateInterpreterGenerator_arm.cpp @@ -175,6 +175,7 @@ address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::M break; case Interpreter::java_lang_math_fmaD: case Interpreter::java_lang_math_fmaF: + case Interpreter::java_lang_math_tanh: // TODO: Implement intrinsic break; default: diff --git a/src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.cpp b/src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.cpp index 7d230d301c2..39693bdf925 100644 --- a/src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.cpp +++ b/src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.cpp @@ -41,10 +41,20 @@ #include "c1/c1_LIRAssembler.hpp" #include "c1/c1_MacroAssembler.hpp" #include "gc/g1/c1/g1BarrierSetC1.hpp" -#endif +#endif // COMPILER1 +#ifdef COMPILER2 +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#endif // COMPILER2 #define __ masm-> +static void generate_marking_inactive_test(MacroAssembler* masm) { + int active_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()); + assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); + __ lbz(R0, active_offset, R16_thread); // tmp1 := *(mark queue active address) + __ cmpwi(CCR0, R0, 0); +} + void G1BarrierSetAssembler::gen_write_ref_array_pre_barrier(MacroAssembler* masm, DecoratorSet decorators, Register from, Register to, Register count, Register preserve1, Register preserve2) { @@ -58,13 +68,7 @@ void G1BarrierSetAssembler::gen_write_ref_array_pre_barrier(MacroAssembler* masm Label filtered; // Is marking active? - if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { - __ lwz(R0, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()), R16_thread); - } else { - guarantee(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); - __ lbz(R0, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()), R16_thread); - } - __ cmpdi(CCR0, R0, 0); + generate_marking_inactive_test(masm); __ beq(CCR0, filtered); __ save_LR(R0); @@ -109,35 +113,48 @@ void G1BarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* mas __ restore_LR(R0); } +static void generate_queue_insertion(MacroAssembler* masm, ByteSize index_offset, ByteSize buffer_offset, Label& runtime, + const Register value, const Register temp) { + assert_different_registers(value, temp); + // Can we store a value in the given thread's buffer? + // (The index field is typed as size_t.) + __ ld(temp, in_bytes(index_offset), R16_thread); // temp := *(index address) + __ cmpdi(CCR0, temp, 0); // jump to runtime if index == 0 (full buffer) + __ beq(CCR0, runtime); + // The buffer is not full, store value into it. + __ ld(R0, in_bytes(buffer_offset), R16_thread); // R0 := buffer address + __ addi(temp, temp, -wordSize); // temp := next index + __ std(temp, in_bytes(index_offset), R16_thread); // *(index address) := next index + __ stdx(value, temp, R0); // *(buffer address + next index) := value +} + void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, DecoratorSet decorators, Register obj, RegisterOrConstant ind_or_offs, Register pre_val, Register tmp1, Register tmp2, MacroAssembler::PreservationLevel preservation_level) { + assert_different_registers(pre_val, tmp1, tmp2); + bool not_null = (decorators & IS_NOT_NULL) != 0, preloaded = obj == noreg; Register nv_save = noreg; - if (preloaded) { + // Determine necessary runtime invocation preservation measures + const bool needs_frame = preservation_level >= MacroAssembler::PRESERVATION_FRAME_LR; + const bool preserve_gp_registers = preservation_level >= MacroAssembler::PRESERVATION_FRAME_LR_GP_REGS; + const bool preserve_fp_registers = preservation_level >= MacroAssembler::PRESERVATION_FRAME_LR_GP_FP_REGS; + int nbytes_save = 0; + + if (pre_val->is_volatile() && preloaded && !preserve_gp_registers) { // We are not loading the previous value so make // sure that we don't trash the value in pre_val // with the code below. - assert_different_registers(pre_val, tmp1, tmp2); - if (pre_val->is_volatile()) { - nv_save = !tmp1->is_volatile() ? tmp1 : tmp2; - assert(!nv_save->is_volatile(), "need one nv temp register if pre_val lives in volatile register"); - } + nv_save = !tmp1->is_volatile() ? tmp1 : tmp2; + assert(!nv_save->is_volatile(), "need one nv temp register if pre_val lives in volatile register"); } Label runtime, filtered; - // Is marking active? - if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { - __ lwz(tmp1, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()), R16_thread); - } else { - guarantee(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); - __ lbz(tmp1, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()), R16_thread); - } - __ cmpdi(CCR0, tmp1, 0); + generate_marking_inactive_test(masm); __ beq(CCR0, filtered); // Do we need to load the previous value? @@ -175,28 +192,12 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Decorator // Can we store original value in the thread's buffer? // Is index == 0? // (The index field is typed as size_t.) - const Register Rbuffer = tmp1, Rindex = tmp2; - - __ ld(Rindex, in_bytes(G1ThreadLocalData::satb_mark_queue_index_offset()), R16_thread); - __ cmpdi(CCR0, Rindex, 0); - __ beq(CCR0, runtime); // If index == 0, goto runtime. - __ ld(Rbuffer, in_bytes(G1ThreadLocalData::satb_mark_queue_buffer_offset()), R16_thread); - - __ addi(Rindex, Rindex, -wordSize); // Decrement index. - __ std(Rindex, in_bytes(G1ThreadLocalData::satb_mark_queue_index_offset()), R16_thread); - - // Record the previous value. - __ stdx(pre_val, Rbuffer, Rindex); + generate_queue_insertion(masm, G1ThreadLocalData::satb_mark_queue_index_offset(), G1ThreadLocalData::satb_mark_queue_buffer_offset(), + runtime, pre_val, tmp1); __ b(filtered); __ bind(runtime); - // Determine necessary runtime invocation preservation measures - const bool needs_frame = preservation_level >= MacroAssembler::PRESERVATION_FRAME_LR; - const bool preserve_gp_registers = preservation_level >= MacroAssembler::PRESERVATION_FRAME_LR_GP_REGS; - const bool preserve_fp_registers = preservation_level >= MacroAssembler::PRESERVATION_FRAME_LR_GP_FP_REGS; - int nbytes_save = 0; - // May need to preserve LR. Also needed if current frame is not compatible with C calling convention. if (needs_frame) { if (preserve_gp_registers) { @@ -210,11 +211,11 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Decorator __ push_frame_reg_args(nbytes_save, tmp2); } - if (pre_val->is_volatile() && preloaded && !preserve_gp_registers) { + if (nv_save != noreg) { __ mr(nv_save, pre_val); // Save pre_val across C call if it was preloaded. } __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_pre_entry), pre_val, R16_thread); - if (pre_val->is_volatile() && preloaded && !preserve_gp_registers) { + if (nv_save != noreg) { __ mr(pre_val, nv_save); // restore } @@ -230,6 +231,26 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Decorator __ bind(filtered); } +static void generate_region_crossing_test(MacroAssembler* masm, const Register store_addr, const Register new_val) { + __ xorr(R0, store_addr, new_val); // tmp1 := store address ^ new value + __ srdi_(R0, R0, G1HeapRegion::LogOfHRGrainBytes); // tmp1 := ((store address ^ new value) >> LogOfHRGrainBytes) +} + +static Address generate_card_young_test(MacroAssembler* masm, const Register store_addr, const Register tmp1, const Register tmp2) { + CardTableBarrierSet* ct = barrier_set_cast(BarrierSet::barrier_set()); + __ load_const_optimized(tmp1, (address)(ct->card_table()->byte_map_base()), tmp2); + __ srdi(tmp2, store_addr, CardTable::card_shift()); // tmp1 := card address relative to card table base + __ lbzx(R0, tmp1, tmp2); // tmp1 := card address + __ cmpwi(CCR0, R0, (int)G1CardTable::g1_young_card_val()); + return Address(tmp1, tmp2); // return card address +} + +static void generate_card_dirty_test(MacroAssembler* masm, Address card_addr) { + __ membar(Assembler::StoreLoad); // Must reload after StoreLoad membar due to concurrent refinement + __ lbzx(R0, card_addr.base(), card_addr.index()); // tmp2 := card + __ cmpwi(CCR0, R0, (int)G1CardTable::dirty_card_val()); // tmp2 := card == dirty_card_val? +} + void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, DecoratorSet decorators, Register store_addr, Register new_val, Register tmp1, Register tmp2, Register tmp3, @@ -241,9 +262,7 @@ void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, Decorato CardTableBarrierSet* ct = barrier_set_cast(BarrierSet::barrier_set()); - // Does store cross heap regions? - __ xorr(tmp1, store_addr, new_val); - __ srdi_(tmp1, tmp1, G1HeapRegion::LogOfHRGrainBytes); + generate_region_crossing_test(masm, store_addr, new_val); __ beq(CCR0, filtered); // Crosses regions, storing null? @@ -257,43 +276,22 @@ void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, Decorato __ beq(CCR0, filtered); } - // Storing region crossing non-null, is card already dirty? - const Register Rcard_addr = tmp1; - Register Rbase = tmp2; - __ load_const_optimized(Rbase, (address)(ct->card_table()->byte_map_base()), /*temp*/ tmp3); - - __ srdi(Rcard_addr, store_addr, CardTable::card_shift()); - - // Get the address of the card. - __ lbzx(/*card value*/ tmp3, Rbase, Rcard_addr); - __ cmpwi(CCR0, tmp3, (int)G1CardTable::g1_young_card_val()); + Address card_addr = generate_card_young_test(masm, store_addr, tmp1, tmp2); __ beq(CCR0, filtered); - __ membar(Assembler::StoreLoad); - __ lbzx(/*card value*/ tmp3, Rbase, Rcard_addr); // Reload after membar. - __ cmpwi(CCR0, tmp3 /* card value */, (int)G1CardTable::dirty_card_val()); + generate_card_dirty_test(masm, card_addr); __ beq(CCR0, filtered); - // Storing a region crossing, non-null oop, card is clean. - // Dirty card and log. - __ li(tmp3, (int)G1CardTable::dirty_card_val()); - //release(); // G1: oops are allowed to get visible after dirty marking. - __ stbx(tmp3, Rbase, Rcard_addr); - - __ add(Rcard_addr, Rbase, Rcard_addr); // This is the address which needs to get enqueued. - Rbase = noreg; // end of lifetime + __ li(R0, (int)G1CardTable::dirty_card_val()); + __ stbx(R0, card_addr.base(), card_addr.index()); // *(card address) := dirty_card_val - const Register Rqueue_index = tmp2, - Rqueue_buf = tmp3; - __ ld(Rqueue_index, in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset()), R16_thread); - __ cmpdi(CCR0, Rqueue_index, 0); - __ beq(CCR0, runtime); // index == 0 then jump to runtime - __ ld(Rqueue_buf, in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset()), R16_thread); + Register Rcard_addr = tmp3; + __ add(Rcard_addr, card_addr.base(), card_addr.index()); // This is the address which needs to get enqueued. - __ addi(Rqueue_index, Rqueue_index, -wordSize); // decrement index - __ std(Rqueue_index, in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset()), R16_thread); - - __ stdx(Rcard_addr, Rqueue_buf, Rqueue_index); // store card + generate_queue_insertion(masm, + G1ThreadLocalData::dirty_card_queue_index_offset(), + G1ThreadLocalData::dirty_card_queue_buffer_offset(), + runtime, Rcard_addr, tmp1); __ b(filtered); __ bind(runtime); @@ -392,6 +390,142 @@ void G1BarrierSetAssembler::resolve_jobject(MacroAssembler* masm, Register value __ bind(done); } +#ifdef COMPILER2 + +static void generate_c2_barrier_runtime_call(MacroAssembler* masm, G1BarrierStubC2* stub, const Register arg, const address runtime_path) { + SaveLiveRegisters save_registers(masm, stub); + __ call_VM_leaf(runtime_path, arg, R16_thread); +} + +void G1BarrierSetAssembler::g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register tmp1, + Register tmp2, + G1PreBarrierStubC2* stub) { + assert_different_registers(obj, tmp1, tmp2, R0); + assert_different_registers(pre_val, tmp1, R0); + assert(!UseCompressedOops || tmp2 != noreg, "tmp2 needed with CompressedOops"); + + stub->initialize_registers(obj, pre_val, R16_thread, tmp1, tmp2); + + generate_marking_inactive_test(masm); + __ bc_far_optimized(Assembler::bcondCRbiIs0, __ bi0(CCR0, Assembler::equal), *stub->entry()); + + __ bind(*stub->continuation()); +} + +void G1BarrierSetAssembler::generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const { + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + Register obj = stub->obj(); + Register pre_val = stub->pre_val(); + Register tmp1 = stub->tmp1(); + + __ bind(*stub->entry()); + + if (obj != noreg) { + // Note: C2 currently doesn't use implicit null checks with barriers. + // Otherwise, obj could be null and the following instruction would raise a SIGSEGV. + if (UseCompressedOops) { + __ lwz(pre_val, 0, obj); + } else { + __ ld(pre_val, 0, obj); + } + } + __ cmpdi(CCR0, pre_val, 0); + __ bc_far_optimized(Assembler::bcondCRbiIs1, __ bi0(CCR0, Assembler::equal), *stub->continuation()); + + Register pre_val_decoded = pre_val; + if (UseCompressedOops) { + pre_val_decoded = __ decode_heap_oop_not_null(stub->tmp2(), pre_val); + } + + generate_queue_insertion(masm, + G1ThreadLocalData::satb_mark_queue_index_offset(), + G1ThreadLocalData::satb_mark_queue_buffer_offset(), + runtime, pre_val_decoded, tmp1); + __ b(*stub->continuation()); + + __ bind(runtime); + generate_c2_barrier_runtime_call(masm, stub, pre_val_decoded, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_pre_entry)); + __ b(*stub->continuation()); +} + +void G1BarrierSetAssembler::g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register tmp1, + Register tmp2, + G1PostBarrierStubC2* stub, + bool decode_new_val) { + assert_different_registers(store_addr, new_val, tmp1, R0); + assert_different_registers(store_addr, tmp1, tmp2, R0); + + stub->initialize_registers(R16_thread, tmp1, tmp2); + + bool null_check_required = (stub->barrier_data() & G1C2BarrierPostNotNull) == 0; + Register new_val_decoded = new_val; + + if (decode_new_val) { + assert(UseCompressedOops, "or should not be here"); + if (null_check_required && CompressedOops::base() != nullptr) { + // We prefer doing the null check after the region crossing check. + // Only compressed oop modes with base != null require a null check here. + __ cmpwi(CCR0, new_val, 0); + __ beq(CCR0, *stub->continuation()); + null_check_required = false; + } + new_val_decoded = __ decode_heap_oop_not_null(tmp2, new_val); + } + + generate_region_crossing_test(masm, store_addr, new_val_decoded); + __ beq(CCR0, *stub->continuation()); + + // crosses regions, storing null? + if (null_check_required) { + __ cmpdi(CCR0, new_val_decoded, 0); + __ beq(CCR0, *stub->continuation()); + } + + Address card_addr = generate_card_young_test(masm, store_addr, tmp1, tmp2); + assert(card_addr.base() == tmp1 && card_addr.index() == tmp2, "needed by post barrier stub"); + __ bc_far_optimized(Assembler::bcondCRbiIs0, __ bi0(CCR0, Assembler::equal), *stub->entry()); + + __ bind(*stub->continuation()); +} + +void G1BarrierSetAssembler::generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const { + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + Address card_addr(stub->tmp1(), stub->tmp2()); // See above. + + __ bind(*stub->entry()); + + generate_card_dirty_test(masm, card_addr); + __ bc_far_optimized(Assembler::bcondCRbiIs1, __ bi0(CCR0, Assembler::equal), *stub->continuation()); + + __ li(R0, (int)G1CardTable::dirty_card_val()); + __ stbx(R0, card_addr.base(), card_addr.index()); // *(card address) := dirty_card_val + + Register Rcard_addr = stub->tmp1(); + __ add(Rcard_addr, card_addr.base(), card_addr.index()); // This is the address which needs to get enqueued. + + generate_queue_insertion(masm, + G1ThreadLocalData::dirty_card_queue_index_offset(), + G1ThreadLocalData::dirty_card_queue_buffer_offset(), + runtime, Rcard_addr, stub->tmp2()); + __ b(*stub->continuation()); + + __ bind(runtime); + generate_c2_barrier_runtime_call(masm, stub, Rcard_addr, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry)); + __ b(*stub->continuation()); +} + +#endif // COMPILER2 + #ifdef COMPILER1 #undef __ @@ -470,13 +604,7 @@ void G1BarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAssembler* __ std(tmp2, -24, R1_SP); // Is marking still active? - if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { - __ lwz(tmp, satb_q_active_byte_offset, R16_thread); - } else { - assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); - __ lbz(tmp, satb_q_active_byte_offset, R16_thread); - } - __ cmpdi(CCR0, tmp, 0); + generate_marking_inactive_test(sasm); __ beq(CCR0, marking_not_active); __ bind(restart); diff --git a/src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.hpp b/src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.hpp index d9a252ff6ea..1c9fe8a5d10 100644 --- a/src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.hpp +++ b/src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.hpp @@ -30,10 +30,16 @@ #include "gc/shared/modRefBarrierSetAssembler.hpp" #include "utilities/macros.hpp" +#ifdef COMPILER2 +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#endif + class LIR_Assembler; class StubAssembler; class G1PreBarrierStub; class G1PostBarrierStub; +class G1PreBarrierStubC2; +class G1PostBarrierStubC2; class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { protected: @@ -59,6 +65,25 @@ class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { MacroAssembler::PreservationLevel preservation_level); public: +#ifdef COMPILER2 + void g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register tmp1, + Register tmp2, + G1PreBarrierStubC2* c2_stub); + void generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const; + void g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register tmp1, + Register tmp2, + G1PostBarrierStubC2* c2_stub, + bool decode_new_val); + void generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const; +#endif #ifdef COMPILER1 void gen_pre_barrier_stub(LIR_Assembler* ce, G1PreBarrierStub* stub); void gen_post_barrier_stub(LIR_Assembler* ce, G1PostBarrierStub* stub); diff --git a/src/hotspot/cpu/ppc/gc/g1/g1_ppc.ad b/src/hotspot/cpu/ppc/gc/g1/g1_ppc.ad new file mode 100644 index 00000000000..f4163242cad --- /dev/null +++ b/src/hotspot/cpu/ppc/gc/g1/g1_ppc.ad @@ -0,0 +1,684 @@ +// +// Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. +// Copyright (c) 2024 SAP SE. 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. +// + +source_hpp %{ + +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#include "gc/shared/gc_globals.hpp" + +%} + +source %{ + +#include "gc/g1/g1BarrierSetAssembler_ppc.hpp" +#include "gc/g1/g1BarrierSetRuntime.hpp" + +static void pre_write_barrier(MacroAssembler* masm, + const MachNode* node, + Register obj, + Register pre_val, + Register tmp1, + Register tmp2 = noreg, // only needed with CompressedOops when pre_val needs to be preserved + RegSet preserve = RegSet(), + RegSet no_preserve = RegSet()) { + if (!G1PreBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PreBarrierStubC2* const stub = G1PreBarrierStubC2::create(node); + for (RegSetIterator reg = preserve.begin(); *reg != noreg; ++reg) { + stub->preserve(*reg); + } + for (RegSetIterator reg = no_preserve.begin(); *reg != noreg; ++reg) { + stub->dont_preserve(*reg); + } + g1_asm->g1_write_barrier_pre_c2(masm, obj, pre_val, tmp1, (tmp2 != noreg) ? tmp2 : pre_val, stub); +} + +static void post_write_barrier(MacroAssembler* masm, + const MachNode* node, + Register store_addr, + Register new_val, + Register tmp1, + Register tmp2, + bool decode_new_val = false) { + if (!G1PostBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PostBarrierStubC2* const stub = G1PostBarrierStubC2::create(node); + g1_asm->g1_write_barrier_post_c2(masm, store_addr, new_val, tmp1, tmp2, stub, decode_new_val); +} + +%} + +instruct g1StoreP(indirect mem, iRegPsrc src, iRegPdst tmp1, iRegPdst tmp2, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreP mem src)); + effect(TEMP tmp1, TEMP tmp2, KILL cr0); + ins_cost(2 * MEMORY_REF_COST); + format %{ "std $mem, $src\t# ptr" %} + ins_encode %{ + pre_write_barrier(masm, this, + $mem$$Register, + $tmp1$$Register, + $tmp2$$Register, + noreg, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ std($src$$Register, 0, $mem$$Register); + post_write_barrier(masm, this, + $mem$$Register, + $src$$Register /* new_val */, + $tmp1$$Register, + $tmp2$$Register); + %} + ins_pipe(pipe_class_default); +%} + +instruct g1StoreN(indirect mem, iRegNsrc src, iRegPdst tmp1, iRegPdst tmp2, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem src)); + effect(TEMP tmp1, TEMP tmp2, KILL cr0); + ins_cost(2 * MEMORY_REF_COST); + format %{ "stw $mem, $src\t# ptr" %} + ins_encode %{ + pre_write_barrier(masm, this, + $mem$$Register, + $tmp1$$Register, + $tmp2$$Register, + noreg, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ stw($src$$Register, 0, $mem$$Register); + post_write_barrier(masm, this, + $mem$$Register, + $src$$Register /* new_val */, + $tmp1$$Register, + $tmp2$$Register, + true /* decode_new_val */); + %} + ins_pipe(pipe_class_default); +%} + +instruct g1EncodePAndStoreN(indirect mem, iRegPsrc src, iRegPdst tmp1, iRegPdst tmp2, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem (EncodeP src))); + effect(TEMP tmp1, TEMP tmp2, KILL cr0); + ins_cost(2 * MEMORY_REF_COST); + format %{ "encode_heap_oop $src\n\t" + "stw $mem, $src\t# ptr" %} + ins_encode %{ + pre_write_barrier(masm, this, + $mem$$Register, + $tmp1$$Register, + $tmp2$$Register, + noreg, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + Register encoded_oop = noreg; + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + encoded_oop = __ encode_heap_oop($tmp2$$Register, $src$$Register); + } else { + encoded_oop = __ encode_heap_oop_not_null($tmp2$$Register, $src$$Register); + } + __ stw(encoded_oop, 0, $mem$$Register); + post_write_barrier(masm, this, + $mem$$Register, + $src$$Register /* new_val */, + $tmp1$$Register, + $tmp2$$Register); + %} + ins_pipe(pipe_class_default); +%} + +instruct g1CompareAndExchangeP(iRegPdst res, indirect mem, iRegPsrc oldval, iRegPsrc newval, iRegPdst tmp1, iRegPdst tmp2, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndExchangeNode*)n)->order() != MemNode::acquire && ((CompareAndExchangeNode*)n)->order() != MemNode::seqcst)); + match(Set res (CompareAndExchangeP mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp1, TEMP tmp2, KILL cr0); + format %{ "cmpxchgd $newval, $mem" %} + ins_encode %{ + Label no_update; + __ cmpxchgd(CCR0, $res$$Register, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register, + $tmp1$$Register, + $tmp2$$Register, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp1$$Register, + $tmp2$$Register); + __ bind(no_update); + %} + ins_pipe(pipe_class_default); +%} + +instruct g1CompareAndExchangeP_acq(iRegPdst res, indirect mem, iRegPsrc oldval, iRegPsrc newval, iRegPdst tmp1, iRegPdst tmp2, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndExchangeNode*)n)->order() == MemNode::acquire || ((CompareAndExchangeNode*)n)->order() == MemNode::seqcst)); + match(Set res (CompareAndExchangeP mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp1, TEMP tmp2, KILL cr0); + format %{ "cmpxchgd acq $newval, $mem" %} + ins_encode %{ + Label no_update; + __ cmpxchgd(CCR0, $res$$Register, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register, + $tmp1$$Register, + $tmp2$$Register, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp1$$Register, + $tmp2$$Register); + __ bind(no_update); + if (support_IRIW_for_not_multiple_copy_atomic_cpu) { + __ isync(); + } else { + // isync would be sufficient in case of CompareAndExchangeAcquire, but we currently don't optimize for that. + __ sync(); + } + %} + ins_pipe(pipe_class_default); +%} + +instruct g1CompareAndExchangeN(iRegNdst res, indirect mem, iRegNsrc oldval, iRegNsrc newval, iRegPdst tmp1, iRegPdst tmp2, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndExchangeNode*)n)->order() != MemNode::acquire && ((CompareAndExchangeNode*)n)->order() != MemNode::seqcst)); + match(Set res (CompareAndExchangeN mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp1, TEMP tmp2, KILL cr0); + format %{ "cmpxchgw $newval, $mem" %} + ins_encode %{ + Label no_update; + __ cmpxchgw(CCR0, $res$$Register, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register, + $tmp1$$Register, + $tmp2$$Register, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp1$$Register, + $tmp2$$Register, + true /* decode_new_val */); + __ bind(no_update); + %} + ins_pipe(pipe_class_default); +%} + +instruct g1CompareAndExchangeN_acq(iRegNdst res, indirect mem, iRegNsrc oldval, iRegNsrc newval, iRegPdst tmp1, iRegPdst tmp2, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndExchangeNode*)n)->order() == MemNode::acquire || ((CompareAndExchangeNode*)n)->order() == MemNode::seqcst)); + match(Set res (CompareAndExchangeN mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp1, TEMP tmp2, KILL cr0); + format %{ "cmpxchgw acq $newval, $mem" %} + ins_encode %{ + Label no_update; + __ cmpxchgw(CCR0, $res$$Register, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register, + $tmp1$$Register, + $tmp2$$Register, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp1$$Register, + $tmp2$$Register, + true /* decode_new_val */); + __ bind(no_update); + if (support_IRIW_for_not_multiple_copy_atomic_cpu) { + __ isync(); + } else { + // isync would be sufficient in case of CompareAndExchangeAcquire, but we currently don't optimize for that. + __ sync(); + } + %} + ins_pipe(pipe_class_default); +%} + +instruct g1CompareAndSwapP(iRegIdst res, indirect mem, iRegPsrc oldval, iRegPsrc newval, iRegPdst tmp, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndSwapNode*)n)->order() != MemNode::acquire && ((CompareAndSwapNode*)n)->order() != MemNode::seqcst)); + match(Set res (CompareAndSwapP mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp, KILL cr0); + format %{ "CMPXCHGD $res, $mem, $oldval, $newval; as bool; ptr" %} + ins_encode %{ + Label no_update; + __ li($res$$Register, 0); + __ cmpxchgd(CCR0, R0, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register /* pre_val */, + $tmp$$Register, + $res$$Register /* temp */, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp$$Register, + $res$$Register /* temp */); + __ li($res$$Register, 1); + __ bind(no_update); + %} + ins_pipe(pipe_class_default); +%} + +instruct g1CompareAndSwapP_acq(iRegIdst res, indirect mem, iRegPsrc oldval, iRegPsrc newval, iRegPdst tmp, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndSwapNode*)n)->order() == MemNode::acquire || ((CompareAndSwapNode*)n)->order() == MemNode::seqcst)); + match(Set res (CompareAndSwapP mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp, KILL cr0); + format %{ "CMPXCHGD acq $res, $mem, $oldval, $newval; as bool; ptr" %} + ins_encode %{ + Label no_update; + __ li($res$$Register, 0); + __ cmpxchgd(CCR0, R0, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register /* pre_val */, + $tmp$$Register, + $res$$Register /* temp */, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp$$Register, + $res$$Register /* temp */); + __ li($res$$Register, 1); + __ bind(no_update); + if (support_IRIW_for_not_multiple_copy_atomic_cpu) { + __ isync(); + } else { + // isync would be sufficient in case of CompareAndExchangeAcquire, but we currently don't optimize for that. + __ sync(); + } + %} + ins_pipe(pipe_class_default); +%} + +instruct g1CompareAndSwapN(iRegIdst res, indirect mem, iRegNsrc oldval, iRegNsrc newval, iRegPdst tmp, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndSwapNode*)n)->order() != MemNode::acquire && ((CompareAndSwapNode*)n)->order() != MemNode::seqcst)); + match(Set res (CompareAndSwapN mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp, KILL cr0); + format %{ "CMPXCHGW $res, $mem, $oldval, $newval; as bool; ptr" %} + ins_encode %{ + Label no_update; + __ li($res$$Register, 0); + __ cmpxchgw(CCR0, R0, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register /* pre_val */, + $tmp$$Register, + $res$$Register /* temp */, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp$$Register, + $res$$Register /* temp */, + true /* decode_new_val */); + __ li($res$$Register, 1); + __ bind(no_update); + %} + ins_pipe(pipe_class_default); +%} + +instruct g1CompareAndSwapN_acq(iRegIdst res, indirect mem, iRegNsrc oldval, iRegNsrc newval, iRegPdst tmp, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndSwapNode*)n)->order() == MemNode::acquire || ((CompareAndSwapNode*)n)->order() == MemNode::seqcst)); + match(Set res (CompareAndSwapN mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp, KILL cr0); + format %{ "CMPXCHGW acq $res, $mem, $oldval, $newval; as bool; ptr" %} + ins_encode %{ + Label no_update; + __ li($res$$Register, 0); + __ cmpxchgw(CCR0, R0, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register /* pre_val */, + $tmp$$Register, + $res$$Register /* temp */, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp$$Register, + $res$$Register /* temp */, + true /* decode_new_val */); + __ li($res$$Register, 1); + __ bind(no_update); + if (support_IRIW_for_not_multiple_copy_atomic_cpu) { + __ isync(); + } else { + // isync would be sufficient in case of CompareAndExchangeAcquire, but we currently don't optimize for that. + __ sync(); + } + %} + ins_pipe(pipe_class_default); +%} + +instruct weakG1CompareAndSwapP(iRegIdst res, indirect mem, iRegPsrc oldval, iRegPsrc newval, iRegPdst tmp, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndSwapNode*)n)->order() != MemNode::acquire && ((CompareAndSwapNode*)n)->order() != MemNode::seqcst)); + match(Set res (WeakCompareAndSwapP mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp, KILL cr0); + format %{ "weak CMPXCHGD $res, $mem, $oldval, $newval; as bool; ptr" %} + ins_encode %{ + Label no_update; + __ li($res$$Register, 0); + __ cmpxchgd(CCR0, R0, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register /* pre_val */, + $tmp$$Register, + $res$$Register /* temp */, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp$$Register, + $res$$Register /* temp */); + __ li($res$$Register, 1); + __ bind(no_update); + %} + ins_pipe(pipe_class_default); +%} + +instruct weakG1CompareAndSwapP_acq(iRegIdst res, indirect mem, iRegPsrc oldval, iRegPsrc newval, iRegPdst tmp, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndSwapNode*)n)->order() == MemNode::acquire || ((CompareAndSwapNode*)n)->order() == MemNode::seqcst)); + match(Set res (WeakCompareAndSwapP mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp, KILL cr0); + format %{ "weak CMPXCHGD acq $res, $mem, $oldval, $newval; as bool; ptr" %} + ins_encode %{ + Label no_update; + __ li($res$$Register, 0); + __ cmpxchgd(CCR0, R0, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register /* pre_val */, + $tmp$$Register, + $res$$Register /* temp */, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp$$Register, + $res$$Register /* temp */); + __ li($res$$Register, 1); + if (support_IRIW_for_not_multiple_copy_atomic_cpu) { + __ isync(); + } else { + // isync would be sufficient in case of CompareAndExchangeAcquire, but we currently don't optimize for that. + __ sync(); + } + __ bind(no_update); // weak version requires no memory barrier on failure + %} + ins_pipe(pipe_class_default); +%} + +instruct weakG1CompareAndSwapN(iRegIdst res, indirect mem, iRegNsrc oldval, iRegNsrc newval, iRegPdst tmp, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndSwapNode*)n)->order() != MemNode::acquire && ((CompareAndSwapNode*)n)->order() != MemNode::seqcst)); + match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp, KILL cr0); + format %{ "weak CMPXCHGW $res, $mem, $oldval, $newval; as bool; ptr" %} + ins_encode %{ + Label no_update; + __ li($res$$Register, 0); + __ cmpxchgw(CCR0, R0, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register /* pre_val */, + $tmp$$Register, + $res$$Register /* temp */, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp$$Register, + $res$$Register /* temp */, + true /* decode_new_val */); + __ li($res$$Register, 1); + __ bind(no_update); + %} + ins_pipe(pipe_class_default); +%} + +instruct weakG1CompareAndSwapN_acq(iRegIdst res, indirect mem, iRegNsrc oldval, iRegNsrc newval, iRegPdst tmp, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0 && + (((CompareAndSwapNode*)n)->order() == MemNode::acquire || ((CompareAndSwapNode*)n)->order() == MemNode::seqcst)); + match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); + effect(TEMP_DEF res, TEMP tmp, KILL cr0); + format %{ "weak CMPXCHGW acq $res, $mem, $oldval, $newval; as bool; ptr" %} + ins_encode %{ + Label no_update; + __ li($res$$Register, 0); + __ cmpxchgw(CCR0, R0, $oldval$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::MemBarNone, MacroAssembler::cmpxchgx_hint_atomic_update(), + noreg, &no_update, true, true); + // Pass oldval to SATB which is the only value which can get overwritten. + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg, + $oldval$$Register /* pre_val */, + $tmp$$Register, + $res$$Register /* temp */, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp$$Register, + $res$$Register /* temp */, + true /* decode_new_val */); + __ li($res$$Register, 1); + if (support_IRIW_for_not_multiple_copy_atomic_cpu) { + __ isync(); + } else { + // isync would be sufficient in case of CompareAndExchangeAcquire, but we currently don't optimize for that. + __ sync(); + } + __ bind(no_update); // weak version requires no memory barrier on failure + %} + ins_pipe(pipe_class_default); +%} + +instruct g1GetAndSetP(iRegPdst res, indirect mem, iRegPsrc newval, iRegPdst tmp1, iRegPdst tmp2, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (GetAndSetP mem newval)); + effect(TEMP_DEF res, TEMP tmp1, TEMP tmp2, KILL cr0); + format %{ "GetAndSetP $newval, $mem" %} + ins_encode %{ + assert_different_registers($mem$$Register, $newval$$Register); + __ getandsetd($res$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::cmpxchgx_hint_atomic_update()); + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg /* obj */, + $res$$Register /* res */, + $tmp1$$Register, + $tmp2$$Register, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp1$$Register, + $tmp2$$Register); + if (support_IRIW_for_not_multiple_copy_atomic_cpu) { + __ isync(); + } else { + __ sync(); + } + %} + ins_pipe(pipe_class_default); +%} + +instruct g1GetAndSetN(iRegNdst res, indirect mem, iRegNsrc newval, iRegPdst tmp1, iRegPdst tmp2, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (GetAndSetN mem newval)); + effect(TEMP_DEF res, TEMP tmp1, TEMP tmp2, KILL cr0); + format %{ "GetAndSetN $newval, $mem" %} + ins_encode %{ + assert_different_registers($mem$$Register, $newval$$Register); + __ getandsetw($res$$Register, $newval$$Register, $mem$$Register, + MacroAssembler::cmpxchgx_hint_atomic_update()); + // Can be done after cmpxchg because there's no safepoint here. + pre_write_barrier(masm, this, + noreg /* obj */, + $res$$Register /* res */, + $tmp1$$Register, + $tmp2$$Register, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */); + post_write_barrier(masm, this, + $mem$$Register, + $newval$$Register, + $tmp1$$Register, + $tmp2$$Register, + true /* decode_new_val */); + if (support_IRIW_for_not_multiple_copy_atomic_cpu) { + __ isync(); + } else { + __ sync(); + } + %} + ins_pipe(pipe_class_default); +%} + +instruct g1LoadP(iRegPdst dst, memoryAlg4 mem, iRegPdst tmp, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_Load()->is_unordered() && n->as_Load()->barrier_data() != 0); + // This instruction does not need an acquiring counterpart because it is only + // used for reference loading (Reference::get()). + match(Set dst (LoadP mem)); + effect(TEMP_DEF dst, TEMP tmp, KILL cr0); + ins_cost(2 * MEMORY_REF_COST); + format %{ "ld $dst, $mem\t# ptr" %} + ins_encode %{ + __ ld($dst$$Register, $mem$$disp, $mem$$base$$Register); + pre_write_barrier(masm, this, + noreg /* obj */, + $dst$$Register /* pre_val */, + $tmp$$Register); + %} + ins_pipe(pipe_class_default); +%} + +instruct g1LoadN(iRegNdst dst, memoryAlg4 mem, iRegPdst tmp1, iRegPdst tmp2, flagsRegCR0 cr0) +%{ + predicate(UseG1GC && n->as_Load()->is_unordered() && n->as_Load()->barrier_data() != 0); + // This instruction does not need an acquiring counterpart because it is only + // used for reference loading (Reference::get()). + match(Set dst (LoadN mem)); + effect(TEMP_DEF dst, TEMP tmp1, TEMP tmp2, KILL cr0); + ins_cost(2 * MEMORY_REF_COST); + format %{ "lwz $dst, $mem\t# ptr" %} + ins_encode %{ + __ lwz($dst$$Register, $mem$$disp, $mem$$base$$Register); + pre_write_barrier(masm, this, + noreg /* obj */, + $dst$$Register, + $tmp1$$Register, + $tmp2$$Register); + %} + ins_pipe(pipe_class_default); +%} diff --git a/src/hotspot/cpu/ppc/gc/shenandoah/shenandoahBarrierSetAssembler_ppc.cpp b/src/hotspot/cpu/ppc/gc/shenandoah/shenandoahBarrierSetAssembler_ppc.cpp index 3cb5c5a628f..53150807212 100644 --- a/src/hotspot/cpu/ppc/gc/shenandoah/shenandoahBarrierSetAssembler_ppc.cpp +++ b/src/hotspot/cpu/ppc/gc/shenandoah/shenandoahBarrierSetAssembler_ppc.cpp @@ -144,9 +144,9 @@ void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler *masm, Dec // Invoke runtime. address jrt_address = nullptr; if (UseCompressedOops) { - jrt_address = CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_narrow_oop_entry); + jrt_address = CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_narrow_oop); } else { - jrt_address = CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_oop_entry); + jrt_address = CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_oop); } assert(jrt_address != nullptr, "jrt routine cannot be found"); @@ -302,7 +302,7 @@ void ShenandoahBarrierSetAssembler::satb_write_barrier_impl(MacroAssembler *masm } // Invoke runtime. - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, R16_thread); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), pre_val, R16_thread); // Restore to-be-preserved registers. if (!preserve_gp_registers && preloaded_mode && pre_val->is_volatile()) { @@ -906,7 +906,7 @@ void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAss __ push_frame_reg_args(nbytes_save, R11_tmp1); // Invoke runtime. - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), R0_pre_val, R16_thread); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), R0_pre_val, R16_thread); // Restore to-be-preserved registers. __ pop_frame(); diff --git a/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp b/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp index a8635af9582..8d8e39b8bbc 100644 --- a/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp +++ b/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp @@ -2715,13 +2715,34 @@ void MacroAssembler::compiler_fast_unlock_object(ConditionRegister flag, Registe b(success); bind(notRecursive); + + // Set owner to null. + // Release to satisfy the JMM + release(); + li(temp, 0); + std(temp, in_bytes(ObjectMonitor::owner_offset()), current_header); + // We need a full fence after clearing owner to avoid stranding. + // StoreLoad achieves this. + membar(StoreLoad); + + // Check if the entry lists are empty. ld(temp, in_bytes(ObjectMonitor::EntryList_offset()), current_header); ld(displaced_header, in_bytes(ObjectMonitor::cxq_offset()), current_header); orr(temp, temp, displaced_header); // Will be 0 if both are 0. cmpdi(flag, temp, 0); - bne(flag, failure); - release(); - std(temp, in_bytes(ObjectMonitor::owner_offset()), current_header); + beq(flag, success); // If so we are done. + + // Check if there is a successor. + ld(temp, in_bytes(ObjectMonitor::succ_offset()), current_header); + cmpdi(flag, temp, 0); + bne(flag, success); // If so we are done. + + // Save the monitor pointer in the current thread, so we can try + // to reacquire the lock in SharedRuntime::monitor_exit_helper(). + std(current_header, in_bytes(JavaThread::unlocked_inflated_monitor_offset()), R16_thread); + + crxor(flag, Assembler::equal, flag, Assembler::equal); // Set flag = NE => slow path + b(failure); // flag == EQ indicates success, decrement held monitor count // flag == NE indicates failure @@ -3028,27 +3049,39 @@ void MacroAssembler::compiler_fast_unlock_lightweight_object(ConditionRegister f bind(not_recursive); - Label release_; + Label set_eq_unlocked; const Register t2 = tmp2; + // Set owner to null. + // Release to satisfy the JMM + release(); + li(t, 0); + std(t, in_bytes(ObjectMonitor::owner_offset()), monitor); + // We need a full fence after clearing owner to avoid stranding. + // StoreLoad achieves this. + membar(StoreLoad); + // Check if the entry lists are empty. ld(t, in_bytes(ObjectMonitor::EntryList_offset()), monitor); ld(t2, in_bytes(ObjectMonitor::cxq_offset()), monitor); orr(t, t, t2); cmpdi(CCR0, t, 0); - beq(CCR0, release_); + beq(CCR0, unlocked); // If so we are done. - // The owner may be anonymous and we removed the last obj entry in - // the lock-stack. This loses the information about the owner. - // Write the thread to the owner field so the runtime knows the owner. - std(R16_thread, in_bytes(ObjectMonitor::owner_offset()), monitor); + // Check if there is a successor. + ld(t, in_bytes(ObjectMonitor::succ_offset()), monitor); + cmpdi(CCR0, t, 0); + bne(CCR0, set_eq_unlocked); // If so we are done. + + // Save the monitor pointer in the current thread, so we can try + // to reacquire the lock in SharedRuntime::monitor_exit_helper(). + std(monitor, in_bytes(JavaThread::unlocked_inflated_monitor_offset()), R16_thread); + + crxor(CCR0, Assembler::equal, CCR0, Assembler::equal); // Set flag = NE => slow path b(slow_path); - bind(release_); - // Set owner to null. - release(); - // t contains 0 - std(t, in_bytes(ObjectMonitor::owner_offset()), monitor); + bind(set_eq_unlocked); + crorc(CCR0, Assembler::equal, CCR0, Assembler::equal); // Set flag = EQ => fast path } bind(unlocked); diff --git a/src/hotspot/cpu/ppc/ppc.ad b/src/hotspot/cpu/ppc/ppc.ad index 612b7bf898c..d15f9929671 100644 --- a/src/hotspot/cpu/ppc/ppc.ad +++ b/src/hotspot/cpu/ppc/ppc.ad @@ -1000,6 +1000,10 @@ int MachNode::compute_padding(int current_offset) const { // Should the matcher clone input 'm' of node 'n'? bool Matcher::pd_clone_node(Node* n, Node* m, Matcher::MStack& mstack) { + if (is_encode_and_store_pattern(n, m)) { + mstack.push(m, Visit); + return true; + } return false; } @@ -5407,7 +5411,7 @@ instruct loadRange(iRegIdst dst, memory mem) %{ // Load Compressed Pointer instruct loadN(iRegNdst dst, memory mem) %{ match(Set dst (LoadN mem)); - predicate(n->as_Load()->is_unordered() || followed_by_acquire(n)); + predicate((n->as_Load()->is_unordered() || followed_by_acquire(n)) && n->as_Load()->barrier_data() == 0); ins_cost(MEMORY_REF_COST); format %{ "LWZ $dst, $mem \t// load compressed ptr" %} @@ -5419,6 +5423,7 @@ instruct loadN(iRegNdst dst, memory mem) %{ // Load Compressed Pointer acquire. instruct loadN_ac(iRegNdst dst, memory mem) %{ match(Set dst (LoadN mem)); + predicate(n->as_Load()->barrier_data() == 0); ins_cost(3*MEMORY_REF_COST); format %{ "LWZ $dst, $mem \t// load acquire compressed ptr\n\t" @@ -5432,7 +5437,7 @@ instruct loadN_ac(iRegNdst dst, memory mem) %{ // Load Compressed Pointer and decode it if narrow_oop_shift == 0. instruct loadN2P_unscaled(iRegPdst dst, memory mem) %{ match(Set dst (DecodeN (LoadN mem))); - predicate(_kids[0]->_leaf->as_Load()->is_unordered() && CompressedOops::shift() == 0); + predicate(_kids[0]->_leaf->as_Load()->is_unordered() && CompressedOops::shift() == 0 && _kids[0]->_leaf->as_Load()->barrier_data() == 0); ins_cost(MEMORY_REF_COST); format %{ "LWZ $dst, $mem \t// DecodeN (unscaled)" %} @@ -6423,6 +6428,7 @@ instruct reinterpretX(vecX dst) %{ // Store Compressed Oop instruct storeN(memory dst, iRegN_P2N src) %{ match(Set dst (StoreN dst src)); + predicate(n->as_Store()->barrier_data() == 0); ins_cost(MEMORY_REF_COST); format %{ "STW $src, $dst \t// compressed oop" %} @@ -6598,7 +6604,7 @@ instruct encodeP_not_null_Ex(iRegNdst dst, iRegPsrc src) %{ instruct encodeP_not_null_base_null(iRegNdst dst, iRegPsrc src) %{ match(Set dst (EncodeP src)); predicate(CompressedOops::shift() != 0 && - CompressedOops::base() ==0); + CompressedOops::base() == nullptr); format %{ "SRDI $dst, $src, #3 \t// encodeP, $src != nullptr" %} size(4); @@ -6695,7 +6701,7 @@ instruct decodeN_Ex(iRegPdst dst, iRegNsrc src, flagsReg crx) %{ predicate((n->bottom_type()->is_oopptr()->ptr() != TypePtr::NotNull && n->bottom_type()->is_oopptr()->ptr() != TypePtr::Constant) && CompressedOops::shift() != 0 && - CompressedOops::base() != 0); + CompressedOops::base() != nullptr); ins_cost(4 * DEFAULT_COST); // Should be more expensive than decodeN_Disjoint_isel_Ex. effect(TEMP crx); @@ -6707,7 +6713,7 @@ instruct decodeN_Ex(iRegPdst dst, iRegNsrc src, flagsReg crx) %{ instruct decodeN_nullBase(iRegPdst dst, iRegNsrc src) %{ match(Set dst (DecodeN src)); predicate(CompressedOops::shift() != 0 && - CompressedOops::base() == 0); + CompressedOops::base() == nullptr); format %{ "SLDI $dst, $src, #3 \t// DecodeN (zerobased)" %} size(4); @@ -6825,7 +6831,7 @@ instruct decodeN_notNull_addBase_Ex(iRegPdst dst, iRegNsrc src) %{ predicate((n->bottom_type()->is_oopptr()->ptr() == TypePtr::NotNull || n->bottom_type()->is_oopptr()->ptr() == TypePtr::Constant) && CompressedOops::shift() != 0 && - CompressedOops::base() != 0); + CompressedOops::base() != nullptr); ins_cost(2 * DEFAULT_COST); format %{ "DecodeN $dst, $src \t// $src != nullptr, postalloc expanded" %} @@ -7477,6 +7483,7 @@ instruct compareAndSwapI_regP_regI_regI(iRegIdst res, iRegPdst mem_ptr, iRegIsrc instruct compareAndSwapN_regP_regN_regN(iRegIdst res, iRegPdst mem_ptr, iRegNsrc src1, iRegNsrc src2, flagsRegCR0 cr0) %{ match(Set res (CompareAndSwapN mem_ptr (Binary src1 src2))); + predicate(n->as_LoadStore()->barrier_data() == 0); effect(TEMP_DEF res, TEMP cr0); // TEMP_DEF to avoid jump format %{ "CMPXCHGW $res, $mem_ptr, $src1, $src2; as bool" %} ins_encode %{ @@ -7676,7 +7683,7 @@ instruct weakCompareAndSwapI_acq_regP_regI_regI(iRegIdst res, iRegPdst mem_ptr, instruct weakCompareAndSwapN_regP_regN_regN(iRegIdst res, iRegPdst mem_ptr, iRegNsrc src1, iRegNsrc src2, flagsRegCR0 cr0) %{ match(Set res (WeakCompareAndSwapN mem_ptr (Binary src1 src2))); - predicate(((CompareAndSwapNode*)n)->order() != MemNode::acquire && ((CompareAndSwapNode*)n)->order() != MemNode::seqcst); + predicate(((CompareAndSwapNode*)n)->order() != MemNode::acquire && ((CompareAndSwapNode*)n)->order() != MemNode::seqcst && n->as_LoadStore()->barrier_data() == 0); effect(TEMP_DEF res, TEMP cr0); // TEMP_DEF to avoid jump format %{ "weak CMPXCHGW $res, $mem_ptr, $src1, $src2; as bool" %} ins_encode %{ @@ -7690,7 +7697,7 @@ instruct weakCompareAndSwapN_regP_regN_regN(iRegIdst res, iRegPdst mem_ptr, iReg instruct weakCompareAndSwapN_acq_regP_regN_regN(iRegIdst res, iRegPdst mem_ptr, iRegNsrc src1, iRegNsrc src2, flagsRegCR0 cr0) %{ match(Set res (WeakCompareAndSwapN mem_ptr (Binary src1 src2))); - predicate(((CompareAndSwapNode*)n)->order() == MemNode::acquire || ((CompareAndSwapNode*)n)->order() == MemNode::seqcst); + predicate((((CompareAndSwapNode*)n)->order() == MemNode::acquire || ((CompareAndSwapNode*)n)->order() == MemNode::seqcst) && n->as_LoadStore()->barrier_data() == 0); effect(TEMP_DEF res, TEMP cr0); // TEMP_DEF to avoid jump format %{ "weak CMPXCHGW acq $res, $mem_ptr, $src1, $src2; as bool" %} ins_encode %{ @@ -7939,7 +7946,7 @@ instruct compareAndExchangeI_acq_regP_regI_regI(iRegIdst res, iRegPdst mem_ptr, instruct compareAndExchangeN_regP_regN_regN(iRegNdst res, iRegPdst mem_ptr, iRegNsrc src1, iRegNsrc src2, flagsRegCR0 cr0) %{ match(Set res (CompareAndExchangeN mem_ptr (Binary src1 src2))); - predicate(((CompareAndSwapNode*)n)->order() != MemNode::acquire && ((CompareAndSwapNode*)n)->order() != MemNode::seqcst); + predicate(((CompareAndSwapNode*)n)->order() != MemNode::acquire && ((CompareAndSwapNode*)n)->order() != MemNode::seqcst && n->as_LoadStore()->barrier_data() == 0); effect(TEMP_DEF res, TEMP cr0); format %{ "CMPXCHGW $res, $mem_ptr, $src1, $src2; as narrow oop" %} ins_encode %{ @@ -7953,7 +7960,7 @@ instruct compareAndExchangeN_regP_regN_regN(iRegNdst res, iRegPdst mem_ptr, iReg instruct compareAndExchangeN_acq_regP_regN_regN(iRegNdst res, iRegPdst mem_ptr, iRegNsrc src1, iRegNsrc src2, flagsRegCR0 cr0) %{ match(Set res (CompareAndExchangeN mem_ptr (Binary src1 src2))); - predicate(((CompareAndSwapNode*)n)->order() == MemNode::acquire || ((CompareAndSwapNode*)n)->order() == MemNode::seqcst); + predicate((((CompareAndSwapNode*)n)->order() == MemNode::acquire || ((CompareAndSwapNode*)n)->order() == MemNode::seqcst) && n->as_LoadStore()->barrier_data() == 0); effect(TEMP_DEF res, TEMP cr0); format %{ "CMPXCHGW acq $res, $mem_ptr, $src1, $src2; as narrow oop" %} ins_encode %{ @@ -8262,6 +8269,7 @@ instruct getAndSetP(iRegPdst res, iRegPdst mem_ptr, iRegPsrc src, flagsRegCR0 cr instruct getAndSetN(iRegNdst res, iRegPdst mem_ptr, iRegNsrc src, flagsRegCR0 cr0) %{ match(Set res (GetAndSetN mem_ptr src)); + predicate(n->as_LoadStore()->barrier_data() == 0); effect(TEMP_DEF res, TEMP cr0); format %{ "GetAndSetN $res, $mem_ptr, $src" %} ins_encode %{ diff --git a/src/hotspot/cpu/ppc/register_ppc.hpp b/src/hotspot/cpu/ppc/register_ppc.hpp index 302d49884fa..b7ba4f053b5 100644 --- a/src/hotspot/cpu/ppc/register_ppc.hpp +++ b/src/hotspot/cpu/ppc/register_ppc.hpp @@ -27,6 +27,7 @@ #define CPU_PPC_REGISTER_PPC_HPP #include "asm/register.hpp" +#include "utilities/count_trailing_zeros.hpp" // forward declaration class VMRegImpl; @@ -555,4 +556,12 @@ constexpr Register R29_TOC = R29; constexpr Register R11_scratch1 = R11; constexpr Register R12_scratch2 = R12; +template <> +inline Register AbstractRegSet::first() { + if (_bitset == 0) { return noreg; } + return as_Register(count_trailing_zeros(_bitset)); +} + +typedef AbstractRegSet RegSet; + #endif // CPU_PPC_REGISTER_PPC_HPP diff --git a/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp b/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp index e2c9b9dd609..75f87e35adf 100644 --- a/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp +++ b/src/hotspot/cpu/riscv/c2_MacroAssembler_riscv.cpp @@ -165,6 +165,7 @@ void C2_MacroAssembler::fast_unlock(Register objectReg, Register boxReg, Register oop = objectReg; Register box = boxReg; Register disp_hdr = tmp1Reg; + Register owner_addr = tmp1Reg; Register tmp = tmp2Reg; Label object_has_monitor; // Finish fast lock successfully. MUST branch to with flag == 0 @@ -222,15 +223,33 @@ void C2_MacroAssembler::fast_unlock(Register objectReg, Register boxReg, j(unlocked); bind(notRecursive); - ld(t0, Address(tmp, ObjectMonitor::EntryList_offset())); - ld(disp_hdr, Address(tmp, ObjectMonitor::cxq_offset())); - orr(t0, t0, disp_hdr); // Will be 0 if both are 0. - bnez(t0, slow_path); + // Compute owner address. + la(owner_addr, Address(tmp, ObjectMonitor::owner_offset())); - // need a release store here - la(tmp, Address(tmp, ObjectMonitor::owner_offset())); + // Set owner to null. + // Release to satisfy the JMM membar(MacroAssembler::LoadStore | MacroAssembler::StoreStore); - sd(zr, Address(tmp)); // set unowned + sd(zr, Address(owner_addr)); + // We need a full fence after clearing owner to avoid stranding. + // StoreLoad achieves this. + membar(StoreLoad); + + // Check if the entry lists are empty. + ld(t0, Address(tmp, ObjectMonitor::EntryList_offset())); + ld(tmp1Reg, Address(tmp, ObjectMonitor::cxq_offset())); + orr(t0, t0, tmp1Reg); + beqz(t0, unlocked); // If so we are done. + + // Check if there is a successor. + ld(t0, Address(tmp, ObjectMonitor::succ_offset())); + bnez(t0, unlocked); // If so we are done. + + // Save the monitor pointer in the current thread, so we can try to + // reacquire the lock in SharedRuntime::monitor_exit_helper(). + sd(tmp, Address(xthread, JavaThread::unlocked_inflated_monitor_offset())); + + mv(flag, 1); + j(slow_path); bind(unlocked); mv(flag, zr); @@ -534,28 +553,35 @@ void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register box, bind(not_recursive); - Label release; const Register tmp2_owner_addr = tmp2; // Compute owner address. la(tmp2_owner_addr, Address(tmp1_monitor, ObjectMonitor::owner_offset())); + // Set owner to null. + // Release to satisfy the JMM + membar(MacroAssembler::LoadStore | MacroAssembler::StoreStore); + sd(zr, Address(tmp2_owner_addr)); + // We need a full fence after clearing owner to avoid stranding. + // StoreLoad achieves this. + membar(StoreLoad); + // Check if the entry lists are empty. ld(t0, Address(tmp1_monitor, ObjectMonitor::EntryList_offset())); ld(tmp3_t, Address(tmp1_monitor, ObjectMonitor::cxq_offset())); orr(t0, t0, tmp3_t); - beqz(t0, release); + beqz(t0, unlocked); // If so we are done. - // The owner may be anonymous and we removed the last obj entry in - // the lock-stack. This loses the information about the owner. - // Write the thread to the owner field so the runtime knows the owner. - sd(xthread, Address(tmp2_owner_addr)); - j(slow_path); + // Check if there is a successor. + ld(tmp3_t, Address(tmp1_monitor, ObjectMonitor::succ_offset())); + bnez(tmp3_t, unlocked); // If so we are done. - bind(release); - // Set owner to null. - membar(MacroAssembler::LoadStore | MacroAssembler::StoreStore); - sd(zr, Address(tmp2_owner_addr)); + // Save the monitor pointer in the current thread, so we can try + // to reacquire the lock in SharedRuntime::monitor_exit_helper(). + sd(tmp1_monitor, Address(xthread, JavaThread::unlocked_inflated_monitor_offset())); + + mv(flag, 1); + j(slow_path); } bind(unlocked); diff --git a/src/hotspot/cpu/riscv/gc/g1/g1BarrierSetAssembler_riscv.cpp b/src/hotspot/cpu/riscv/gc/g1/g1BarrierSetAssembler_riscv.cpp index 062f8029062..7036c44d99d 100644 --- a/src/hotspot/cpu/riscv/gc/g1/g1BarrierSetAssembler_riscv.cpp +++ b/src/hotspot/cpu/riscv/gc/g1/g1BarrierSetAssembler_riscv.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2020, 2023, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, 2024, Huawei Technologies Co., Ltd. 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 @@ -39,7 +39,10 @@ #include "c1/c1_LIRAssembler.hpp" #include "c1/c1_MacroAssembler.hpp" #include "gc/g1/c1/g1BarrierSetC1.hpp" -#endif +#endif // COMPILER1 +#ifdef COMPILER2 +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#endif // COMPILER2 #define __ masm-> @@ -96,6 +99,55 @@ void G1BarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* mas __ pop_reg(saved_regs, sp); } +static void generate_queue_test_and_insertion(MacroAssembler* masm, ByteSize index_offset, ByteSize buffer_offset, Label& runtime, + const Register thread, const Register value, const Register tmp1, const Register tmp2) { + // Can we store a value in the given thread's buffer? + // (The index field is typed as size_t.) + __ ld(tmp1, Address(thread, in_bytes(index_offset))); // tmp1 := *(index address) + __ beqz(tmp1, runtime); // jump to runtime if index == 0 (full buffer) + // The buffer is not full, store value into it. + __ sub(tmp1, tmp1, wordSize); // tmp1 := next index + __ sd(tmp1, Address(thread, in_bytes(index_offset))); // *(index address) := next index + __ ld(tmp2, Address(thread, in_bytes(buffer_offset))); // tmp2 := buffer address + __ add(tmp2, tmp2, tmp1); + __ sd(value, Address(tmp2)); // *(buffer address + next index) := value +} + +static void generate_pre_barrier_fast_path(MacroAssembler* masm, + const Register thread, + const Register tmp1) { + Address in_progress(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset())); + // Is marking active? + if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { + __ lwu(tmp1, in_progress); + } else { + assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); + __ lbu(tmp1, in_progress); + } +} + +static void generate_pre_barrier_slow_path(MacroAssembler* masm, + const Register obj, + const Register pre_val, + const Register thread, + const Register tmp1, + const Register tmp2, + Label& done, + Label& runtime) { + // Do we need to load the previous value? + if (obj != noreg) { + __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW); + } + // Is the previous value null? + __ beqz(pre_val, done, true); + generate_queue_test_and_insertion(masm, + G1ThreadLocalData::satb_mark_queue_index_offset(), + G1ThreadLocalData::satb_mark_queue_buffer_offset(), + runtime, + thread, pre_val, tmp1, tmp2); + __ j(done); +} + void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Register obj, Register pre_val, @@ -116,43 +168,10 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, assert_different_registers(obj, pre_val, tmp1, tmp2); assert(pre_val != noreg && tmp1 != noreg && tmp2 != noreg, "expecting a register"); - Address in_progress(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset())); - Address index(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_index_offset())); - Address buffer(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_buffer_offset())); - - // Is marking active? - if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { // 4-byte width - __ lwu(tmp1, in_progress); - } else { - assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); - __ lbu(tmp1, in_progress); - } + generate_pre_barrier_fast_path(masm, thread, tmp1); + // If marking is not active (*(mark queue active address) == 0), jump to done __ beqz(tmp1, done); - - // Do we need to load the previous value? - if (obj != noreg) { - __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW); - } - - // Is the previous value null? - __ beqz(pre_val, done); - - // Can we store original value in the thread's buffer? - // Is index == 0? - // (The index field is typed as size_t.) - - __ ld(tmp1, index); // tmp := *index_adr - __ beqz(tmp1, runtime); // tmp == 0? - // If yes, goto runtime - - __ sub(tmp1, tmp1, wordSize); // tmp := tmp - wordSize - __ sd(tmp1, index); // *index_adr := tmp - __ ld(tmp2, buffer); - __ add(tmp1, tmp1, tmp2); // tmp := tmp + *buffer_adr - - // Record the previous value - __ sd(pre_val, Address(tmp1, 0)); - __ j(done); + generate_pre_barrier_slow_path(masm, obj, pre_val, thread, tmp1, tmp2, done, runtime); __ bind(runtime); @@ -171,6 +190,49 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, } +static void generate_post_barrier_fast_path(MacroAssembler* masm, + const Register store_addr, + const Register new_val, + const Register tmp1, + const Register tmp2, + Label& done, + bool new_val_may_be_null) { + // Does store cross heap regions? + __ xorr(tmp1, store_addr, new_val); // tmp1 := store address ^ new value + __ srli(tmp1, tmp1, G1HeapRegion::LogOfHRGrainBytes); // tmp1 := ((store address ^ new value) >> LogOfHRGrainBytes) + __ beqz(tmp1, done); + // Crosses regions, storing null? + if (new_val_may_be_null) { + __ beqz(new_val, done); + } + // Storing region crossing non-null, is card young? + __ srli(tmp1, store_addr, CardTable::card_shift()); // tmp1 := card address relative to card table base + __ load_byte_map_base(tmp2); // tmp2 := card table base address + __ add(tmp1, tmp1, tmp2); // tmp1 := card address + __ lbu(tmp2, Address(tmp1)); // tmp2 := card +} + +static void generate_post_barrier_slow_path(MacroAssembler* masm, + const Register thread, + const Register tmp1, + const Register tmp2, + Label& done, + Label& runtime) { + __ membar(MacroAssembler::StoreLoad); // StoreLoad membar + __ lbu(tmp2, Address(tmp1)); // tmp2 := card + __ beqz(tmp2, done, true); + // Storing a region crossing, non-null oop, card is clean. + // Dirty card and log. + STATIC_ASSERT(CardTable::dirty_card_val() == 0); + __ sb(zr, Address(tmp1)); // *(card address) := dirty_card_val + generate_queue_test_and_insertion(masm, + G1ThreadLocalData::dirty_card_queue_index_offset(), + G1ThreadLocalData::dirty_card_queue_buffer_offset(), + runtime, + thread, tmp1, tmp2, t0); + __ j(done); +} + void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, Register store_addr, Register new_val, @@ -179,73 +241,119 @@ void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, Register tmp2) { assert(thread == xthread, "must be"); assert_different_registers(store_addr, new_val, thread, tmp1, tmp2, t0); - assert(store_addr != noreg && new_val != noreg && tmp1 != noreg && - tmp2 != noreg, "expecting a register"); - - Address queue_index(thread, in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset())); - Address buffer(thread, in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset())); - - BarrierSet* bs = BarrierSet::barrier_set(); - CardTableBarrierSet* ctbs = barrier_set_cast(bs); + assert(store_addr != noreg && new_val != noreg && tmp1 != noreg && tmp2 != noreg, + "expecting a register"); Label done; Label runtime; - // Does store cross heap regions? + generate_post_barrier_fast_path(masm, store_addr, new_val, tmp1, tmp2, done, true /* new_val_may_be_null */); + // If card is young, jump to done (tmp2 holds the card value) + __ mv(t0, (int)G1CardTable::g1_young_card_val()); + __ beq(tmp2, t0, done); // card == young_card_val? + generate_post_barrier_slow_path(masm, thread, tmp1, tmp2, done, runtime); - __ xorr(tmp1, store_addr, new_val); - __ srli(tmp1, tmp1, G1HeapRegion::LogOfHRGrainBytes); - __ beqz(tmp1, done); + __ bind(runtime); + // save the live input values + RegSet saved = RegSet::of(store_addr); + __ push_reg(saved, sp); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry), tmp1, thread); + __ pop_reg(saved, sp); - // crosses regions, storing null? + __ bind(done); +} - __ beqz(new_val, done); +#if defined(COMPILER2) - // storing region crossing non-null, is card already dirty? +static void generate_c2_barrier_runtime_call(MacroAssembler* masm, G1BarrierStubC2* stub, const Register arg, const address runtime_path) { + SaveLiveRegisters save_registers(masm, stub); + if (c_rarg0 != arg) { + __ mv(c_rarg0, arg); + } + __ mv(c_rarg1, xthread); + __ mv(t0, runtime_path); + __ jalr(t0); +} - const Register card_addr = tmp1; +void G1BarrierSetAssembler::g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register thread, + Register tmp1, + Register tmp2, + G1PreBarrierStubC2* stub) { + assert(thread == xthread, "must be"); + assert_different_registers(obj, pre_val, tmp1, tmp2); + assert(pre_val != noreg && tmp1 != noreg && tmp2 != noreg, "expecting a register"); - __ srli(card_addr, store_addr, CardTable::card_shift()); + stub->initialize_registers(obj, pre_val, thread, tmp1, tmp2); - // get the address of the card - __ load_byte_map_base(tmp2); - __ add(card_addr, card_addr, tmp2); - __ lbu(tmp2, Address(card_addr)); - __ mv(t0, (int)G1CardTable::g1_young_card_val()); - __ beq(tmp2, t0, done); + generate_pre_barrier_fast_path(masm, thread, tmp1); + // If marking is active (*(mark queue active address) != 0), jump to stub (slow path) + __ bnez(tmp1, *stub->entry(), true); - assert((int)CardTable::dirty_card_val() == 0, "must be 0"); + __ bind(*stub->continuation()); +} - __ membar(MacroAssembler::StoreLoad); +void G1BarrierSetAssembler::generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const { + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + Register obj = stub->obj(); + Register pre_val = stub->pre_val(); + Register thread = stub->thread(); + Register tmp1 = stub->tmp1(); + Register tmp2 = stub->tmp2(); - __ lbu(tmp2, Address(card_addr)); - __ beqz(tmp2, done); + __ bind(*stub->entry()); + generate_pre_barrier_slow_path(masm, obj, pre_val, thread, tmp1, tmp2, *stub->continuation(), runtime); - // storing a region crossing, non-null oop, card is clean. - // dirty card and log. + __ bind(runtime); + generate_c2_barrier_runtime_call(masm, stub, pre_val, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_pre_entry)); + __ j(*stub->continuation()); +} - __ sb(zr, Address(card_addr)); +void G1BarrierSetAssembler::g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register thread, + Register tmp1, + Register tmp2, + G1PostBarrierStubC2* stub) { + assert(thread == xthread, "must be"); + assert_different_registers(store_addr, new_val, thread, tmp1, tmp2, t0); + assert(store_addr != noreg && new_val != noreg && tmp1 != noreg && tmp2 != noreg, + "expecting a register"); - __ ld(t0, queue_index); - __ beqz(t0, runtime); - __ sub(t0, t0, wordSize); - __ sd(t0, queue_index); + stub->initialize_registers(thread, tmp1, tmp2); - __ ld(tmp2, buffer); - __ add(t0, tmp2, t0); - __ sd(card_addr, Address(t0, 0)); - __ j(done); + bool new_val_may_be_null = (stub->barrier_data() & G1C2BarrierPostNotNull) == 0; + generate_post_barrier_fast_path(masm, store_addr, new_val, tmp1, tmp2, *stub->continuation(), new_val_may_be_null); + // If card is not young, jump to stub (slow path) (tmp2 holds the card value) + __ mv(t0, (int)G1CardTable::g1_young_card_val()); + __ bne(tmp2, t0, *stub->entry(), true); - __ bind(runtime); - // save the live input values - RegSet saved = RegSet::of(store_addr); - __ push_reg(saved, sp); - __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry), card_addr, thread); - __ pop_reg(saved, sp); + __ bind(*stub->continuation()); +} - __ bind(done); +void G1BarrierSetAssembler::generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const { + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + Register thread = stub->thread(); + Register tmp1 = stub->tmp1(); // tmp1 holds the card address. + Register tmp2 = stub->tmp2(); + + __ bind(*stub->entry()); + generate_post_barrier_slow_path(masm, thread, tmp1, tmp2, *stub->continuation(), runtime); + + __ bind(runtime); + generate_c2_barrier_runtime_call(masm, stub, tmp1, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry)); + __ j(*stub->continuation()); } +#endif // COMPILER2 + void G1BarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register dst, Address src, Register tmp1, Register tmp2) { bool on_oop = is_reference_type(type); diff --git a/src/hotspot/cpu/riscv/gc/g1/g1BarrierSetAssembler_riscv.hpp b/src/hotspot/cpu/riscv/gc/g1/g1BarrierSetAssembler_riscv.hpp index 96568994079..c7bee2ef6f3 100644 --- a/src/hotspot/cpu/riscv/gc/g1/g1BarrierSetAssembler_riscv.hpp +++ b/src/hotspot/cpu/riscv/gc/g1/g1BarrierSetAssembler_riscv.hpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2020, 2021, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, 2024, Huawei Technologies Co., Ltd. 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 @@ -36,6 +36,8 @@ class LIR_Assembler; class StubAssembler; class G1PreBarrierStub; class G1PostBarrierStub; +class G1PreBarrierStubC2; +class G1PostBarrierStubC2; class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { protected: @@ -72,6 +74,27 @@ class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { void generate_c1_post_barrier_runtime_stub(StubAssembler* sasm); #endif +#ifdef COMPILER2 + void g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register thread, + Register tmp1, + Register tmp2, + G1PreBarrierStubC2* c2_stub); + void generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const; + void g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register thread, + Register tmp1, + Register tmp2, + G1PostBarrierStubC2* c2_stub); + void generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const; +#endif + void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register dst, Address src, Register tmp1, Register tmp2); }; diff --git a/src/hotspot/cpu/riscv/gc/g1/g1_riscv.ad b/src/hotspot/cpu/riscv/gc/g1/g1_riscv.ad new file mode 100644 index 00000000000..1dc5834dbdc --- /dev/null +++ b/src/hotspot/cpu/riscv/gc/g1/g1_riscv.ad @@ -0,0 +1,564 @@ +// +// Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. +// Copyright (c) 2024, Huawei Technologies Co., Ltd. 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. +// + +source_hpp %{ + +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#include "gc/shared/gc_globals.hpp" + +%} + +source %{ + +#include "gc/g1/g1BarrierSetAssembler_riscv.hpp" +#include "gc/g1/g1BarrierSetRuntime.hpp" + +static void write_barrier_pre(MacroAssembler* masm, + const MachNode* node, + Register obj, + Register pre_val, + Register tmp1, + Register tmp2, + RegSet preserve = RegSet(), + RegSet no_preserve = RegSet()) { + if (!G1PreBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PreBarrierStubC2* const stub = G1PreBarrierStubC2::create(node); + for (RegSetIterator reg = preserve.begin(); *reg != noreg; ++reg) { + stub->preserve(*reg); + } + for (RegSetIterator reg = no_preserve.begin(); *reg != noreg; ++reg) { + stub->dont_preserve(*reg); + } + g1_asm->g1_write_barrier_pre_c2(masm, obj, pre_val, xthread, tmp1, tmp2, stub); +} + +static void write_barrier_post(MacroAssembler* masm, + const MachNode* node, + Register store_addr, + Register new_val, + Register tmp1, + Register tmp2) { + if (!G1PostBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PostBarrierStubC2* const stub = G1PostBarrierStubC2::create(node); + g1_asm->g1_write_barrier_post_c2(masm, store_addr, new_val, xthread, tmp1, tmp2, stub); +} + +%} + +instruct g1StoreP(indirect mem, iRegP src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreP mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(STORE_COST); + format %{ "sd $src, $mem\t# ptr" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ sd($src$$Register, Address($mem$$Register)); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(istore_reg_mem); +%} + +instruct g1StoreN(indirect mem, iRegN src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(STORE_COST); + format %{ "sw $src, $mem\t# compressed ptr" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + __ sw($src$$Register, Address($mem$$Register)); + if ((barrier_data() & G1C2BarrierPost) != 0) { + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ decode_heap_oop($tmp1$$Register, $src$$Register); + } else { + __ decode_heap_oop_not_null($tmp1$$Register, $src$$Register); + } + } + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(istore_reg_mem); +%} + +instruct g1EncodePAndStoreN(indirect mem, iRegP src, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem (EncodeP src))); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(STORE_COST); + format %{ "encode_heap_oop $tmp1, $src\n\t" + "sw $tmp1, $mem\t# compressed ptr" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ encode_heap_oop($tmp1$$Register, $src$$Register); + } else { + __ encode_heap_oop_not_null($tmp1$$Register, $src$$Register); + } + __ sw($tmp1$$Register, Address($mem$$Register)); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(istore_reg_mem); +%} + +instruct g1CompareAndExchangeP(iRegPNoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "cmpxchg $res = $mem, $oldval, $newval\t# ptr" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + // Pass $oldval to the pre-barrier (instead of loading from $mem), because + // $oldval is the only value that can be overwritten. + // The same holds for g1CompareAndSwapP and its Acq variant. + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::int64, + /*acquire*/ Assembler::relaxed, /*release*/ Assembler::rl, $res$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +instruct g1CompareAndExchangePAcq(iRegPNoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2) +%{ + predicate(UseG1GC && needs_acquiring_load_reserved(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2); + ins_cost(VOLATILE_REF_COST); + format %{ "cmpxchg_acq $res = $mem, $oldval, $newval\t# ptr" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + // Pass $oldval to the pre-barrier (instead of loading from $mem), because + // $oldval is the only value that can be overwritten. + // The same holds for g1CompareAndSwapP and its Acq variant. + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::int64, + /*acquire*/ Assembler::aq, /*release*/ Assembler::rl, $res$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +instruct g1CompareAndExchangeN(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "cmpxchg $res = $mem, $oldval, $newval\t# narrow oop" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::uint32, + /*acquire*/ Assembler::relaxed, /*release*/ Assembler::rl, $res$$Register); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +instruct g1CompareAndExchangeNAcq(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3) +%{ + predicate(UseG1GC && needs_acquiring_load_reserved(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(VOLATILE_REF_COST); + format %{ "cmpxchg_acq $res = $mem, $oldval, $newval\t# narrow oop" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::uint32, + /*acquire*/ Assembler::aq, /*release*/ Assembler::rl, $res$$Register); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +instruct g1CompareAndSwapP(iRegINoSp res, indirect mem, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegP oldval) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapP mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "cmpxchg $mem, $oldval, $newval\t# (ptr)\n\t" + "mv $res, $res == $oldval" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::int64, + /*acquire*/ Assembler::relaxed, /*release*/ Assembler::rl, $res$$Register, + /*result as bool*/ true); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +instruct g1CompareAndSwapPAcq(iRegINoSp res, indirect mem, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegP oldval) +%{ + predicate(UseG1GC && needs_acquiring_load_reserved(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapP mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2); + ins_cost(VOLATILE_REF_COST); + format %{ "cmpxchg_acq $mem, $oldval, $newval\t# (ptr)\n\t" + "mv $res, $res == $oldval" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::int64, + /*acquire*/ Assembler::aq, /*release*/ Assembler::rl, $res$$Register, + /*result as bool*/ true); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +instruct g1CompareAndSwapN(iRegINoSp res, indirect mem, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, iRegN oldval) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapN mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "cmpxchg $mem, $oldval, $newval\t# (narrow oop)\n\t" + "mv $res, $res == $oldval" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::uint32, + /*acquire*/ Assembler::relaxed, /*release*/ Assembler::rl, $res$$Register, + /*result as bool*/ true); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +instruct g1CompareAndSwapNAcq(iRegINoSp res, indirect mem, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, iRegN oldval) +%{ + predicate(UseG1GC && needs_acquiring_load_reserved(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapN mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(VOLATILE_REF_COST); + format %{ "cmpxchg_acq $mem, $oldval, $newval\t# (narrow oop)\n\t" + "mv $res, $res == $oldval" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($oldval$$Register, $mem$$Register); + assert_different_registers($newval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ cmpxchg($mem$$Register, $oldval$$Register, $newval$$Register, Assembler::uint32, + /*acquire*/ Assembler::aq, /*release*/ Assembler::rl, $res$$Register, + /*result as bool*/ true); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_slow); +%} + +instruct g1GetAndSetP(indirect mem, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp preval) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetP mem newval)); + effect(TEMP preval, TEMP tmp1, TEMP tmp2); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "atomic_xchg $preval, $newval, [$mem]" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $preval$$Register /* pre_val (as a temporary register) */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + __ atomic_xchg($preval$$Register, $newval$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_serial); +%} + +instruct g1GetAndSetPAcq(indirect mem, iRegP newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp preval) +%{ + predicate(UseG1GC && needs_acquiring_load_reserved(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetP mem newval)); + effect(TEMP preval, TEMP tmp1, TEMP tmp2); + ins_cost(VOLATILE_REF_COST); + format %{ "atomic_xchg_acq $preval, $newval, [$mem]" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $preval$$Register /* pre_val (as a temporary register) */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + __ atomic_xchgal($preval$$Register, $newval$$Register, $mem$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(pipe_serial); +%} + +instruct g1GetAndSetN(indirect mem, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, iRegNNoSp preval) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetN mem newval)); + effect(TEMP preval, TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(2 * VOLATILE_REF_COST); + format %{ "atomic_xchgwu $preval, $newval, [$mem]" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + __ atomic_xchgwu($preval$$Register, $newval$$Register, $mem$$Register); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_serial); +%} + +instruct g1GetAndSetNAcq(indirect mem, iRegN newval, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3, iRegNNoSp preval) +%{ + predicate(UseG1GC && needs_acquiring_load_reserved(n) && n->as_LoadStore()->barrier_data() != 0); + match(Set preval (GetAndSetN mem newval)); + effect(TEMP preval, TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(VOLATILE_REF_COST); + format %{ "atomic_xchgwu_acq $preval, $newval, [$mem]" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */, + RegSet::of($mem$$Register, $preval$$Register, $newval$$Register) /* preserve */); + __ atomic_xchgalwu($preval$$Register, $newval$$Register, $mem$$Register); + __ decode_heap_oop($tmp1$$Register, $newval$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_serial); +%} + +instruct g1LoadP(iRegPNoSp dst, indirect mem, iRegPNoSp tmp1, iRegPNoSp tmp2) +%{ + predicate(UseG1GC && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadP mem)); + effect(TEMP dst, TEMP tmp1, TEMP tmp2); + ins_cost(LOAD_COST + BRANCH_COST); + format %{ "ld $dst, $mem\t# ptr" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + __ ld($dst$$Register, Address($mem$$Register)); + write_barrier_pre(masm, this, + noreg /* obj */, + $dst$$Register /* pre_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(iload_reg_mem); +%} + +instruct g1LoadN(iRegNNoSp dst, indirect mem, iRegPNoSp tmp1, iRegPNoSp tmp2, iRegPNoSp tmp3) +%{ + predicate(UseG1GC && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadN mem)); + effect(TEMP dst, TEMP tmp1, TEMP tmp2, TEMP tmp3); + ins_cost(LOAD_COST + BRANCH_COST); + format %{ "lwu $dst, $mem\t# compressed ptr" %} + ins_encode %{ + guarantee($mem$$disp == 0, "impossible encoding"); + __ lwu($dst$$Register, Address($mem$$Register)); + if ((barrier_data() & G1C2BarrierPre) != 0) { + __ decode_heap_oop($tmp1$$Register, $dst$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + } + %} + ins_pipe(iload_reg_mem); +%} diff --git a/src/hotspot/cpu/riscv/gc/shenandoah/shenandoahBarrierSetAssembler_riscv.cpp b/src/hotspot/cpu/riscv/gc/shenandoah/shenandoahBarrierSetAssembler_riscv.cpp index 9a79a923277..cc73d14a756 100644 --- a/src/hotspot/cpu/riscv/gc/shenandoah/shenandoahBarrierSetAssembler_riscv.cpp +++ b/src/hotspot/cpu/riscv/gc/shenandoah/shenandoahBarrierSetAssembler_riscv.cpp @@ -70,10 +70,10 @@ void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, Dec __ push_reg(saved_regs, sp); if (UseCompressedOops) { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_narrow_oop_entry), + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_narrow_oop), src, dst, count); } else { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_oop_entry), src, dst, count); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_oop), src, dst, count); } __ pop_reg(saved_regs, sp); __ bind(done); @@ -165,9 +165,9 @@ void ShenandoahBarrierSetAssembler::satb_write_barrier_pre(MacroAssembler* masm, // expand_call should be passed true. if (expand_call) { assert(pre_val != c_rarg1, "smashed arg"); - __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread); + __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), pre_val, thread); } else { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), pre_val, thread); } __ pop_reg(saved, sp); @@ -645,7 +645,7 @@ void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAss __ bind(runtime); __ push_call_clobbered_registers(); __ load_parameter(0, pre_val); - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), pre_val, thread); __ pop_call_clobbered_registers(); __ bind(done); diff --git a/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp b/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp index 32a446959a2..b99ba542423 100644 --- a/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp +++ b/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp @@ -1564,7 +1564,10 @@ void MacroAssembler::kernel_crc32(Register crc, Register buf, Register len, Register table0, Register table1, Register table2, Register table3, Register tmp1, Register tmp2, Register tmp3, Register tmp4, Register tmp5, Register tmp6) { assert_different_registers(crc, buf, len, table0, table1, table2, table3, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6); - Label L_by16_loop, L_vector_entry, L_unroll_loop, L_unroll_loop_entry, L_by4, L_by4_loop, L_by1, L_by1_loop, L_exit; + Label L_vector_entry, + L_unroll_loop, + L_by4_loop_entry, L_by4_loop, + L_by1_loop, L_exit; const int64_t single_table_size = 256; const int64_t unroll = 16; @@ -1585,21 +1588,17 @@ void MacroAssembler::kernel_crc32(Register crc, Register buf, Register len, bge(len, tmp1, L_vector_entry); } #endif // COMPILER2 - subw(len, len, unroll_words); - bge(len, zr, L_unroll_loop_entry); - addiw(len, len, unroll_words-4); - bge(len, zr, L_by4_loop); - addiw(len, len, 4); - bgt(len, zr, L_by1_loop); - j(L_exit); + mv(tmp1, unroll_words); + blt(len, tmp1, L_by4_loop_entry); + + const Register loop_buf_end = tmp3; align(CodeEntryAlignment); - bind(L_unroll_loop_entry); - const Register buf_end = tmp3; - add(buf_end, buf, len); // buf_end will be used as endpoint for loop below + // Entry for L_unroll_loop + add(loop_buf_end, buf, len); // loop_buf_end will be used as endpoint for loop below andi(len, len, unroll_words-1); // len = (len % unroll_words) - sub(len, len, unroll_words); // Length after all iterations + sub(loop_buf_end, loop_buf_end, len); bind(L_unroll_loop); for (int i = 0; i < unroll; i++) { ld(tmp1, Address(buf, i*wordSize)); @@ -1608,57 +1607,50 @@ void MacroAssembler::kernel_crc32(Register crc, Register buf, Register len, } addi(buf, buf, unroll_words); - ble(buf, buf_end, L_unroll_loop); - addiw(len, len, unroll_words-4); - bge(len, zr, L_by4_loop); - addiw(len, len, 4); - bgt(len, zr, L_by1_loop); - j(L_exit); - + blt(buf, loop_buf_end, L_unroll_loop); + + bind(L_by4_loop_entry); + mv(tmp1, 4); + blt(len, tmp1, L_by1_loop); + add(loop_buf_end, buf, len); // loop_buf_end will be used as endpoint for loop below + andi(len, len, 3); + sub(loop_buf_end, loop_buf_end, len); bind(L_by4_loop); lwu(tmp1, Address(buf)); update_word_crc32(crc, tmp1, tmp2, tmp4, tmp6, table0, table1, table2, table3, false); - subw(len, len, 4); addi(buf, buf, 4); - bge(len, zr, L_by4_loop); - addiw(len, len, 4); - ble(len, zr, L_exit); + blt(buf, loop_buf_end, L_by4_loop); bind(L_by1_loop); + beqz(len, L_exit); + subw(len, len, 1); lwu(tmp1, Address(buf)); andi(tmp2, tmp1, right_8_bits); update_byte_crc32(crc, tmp2, table0); - ble(len, zr, L_exit); + beqz(len, L_exit); subw(len, len, 1); srli(tmp2, tmp1, 8); andi(tmp2, tmp2, right_8_bits); update_byte_crc32(crc, tmp2, table0); - ble(len, zr, L_exit); + beqz(len, L_exit); subw(len, len, 1); srli(tmp2, tmp1, 16); andi(tmp2, tmp2, right_8_bits); update_byte_crc32(crc, tmp2, table0); - ble(len, zr, L_exit); - - srli(tmp2, tmp1, 24); - andi(tmp2, tmp2, right_8_bits); - update_byte_crc32(crc, tmp2, table0); #ifdef COMPILER2 // put vector code here, otherwise "offset is too large" error occurs. if (UseRVV) { - j(L_exit); // only need to jump exit when UseRVV == true, it's a jump from end of block `L_by1_loop`. + // only need to jump exit when UseRVV == true, it's a jump from end of block `L_by1_loop`. + j(L_exit); bind(L_vector_entry); vector_update_crc32(crc, buf, len, tmp1, tmp2, tmp3, tmp4, tmp6, table0, table3); - addiw(len, len, -4); - bge(len, zr, L_by4_loop); - addiw(len, len, 4); - bgt(len, zr, L_by1_loop); + bgtz(len, L_by4_loop_entry); } #endif // COMPILER2 diff --git a/src/hotspot/cpu/riscv/riscv.ad b/src/hotspot/cpu/riscv/riscv.ad index 05f55fd0da7..563dfd4cde9 100644 --- a/src/hotspot/cpu/riscv/riscv.ad +++ b/src/hotspot/cpu/riscv/riscv.ad @@ -2224,7 +2224,8 @@ bool Matcher::pd_clone_node(Node* n, Node* m, Matcher::MStack& mstack) { assert_cond(m != nullptr); if (is_vshift_con_pattern(n, m) || // ShiftV src (ShiftCntV con) is_vector_bitwise_not_pattern(n, m) || - is_vector_scalar_bitwise_pattern(n, m)) { + is_vector_scalar_bitwise_pattern(n, m) || + is_encode_and_store_pattern(n, m)) { mstack.push(m, Visit); return true; } @@ -4785,6 +4786,7 @@ instruct loadP(iRegPNoSp dst, memory mem) // Load Compressed Pointer instruct loadN(iRegNNoSp dst, memory mem) %{ + predicate(n->as_Load()->barrier_data() == 0); match(Set dst (LoadN mem)); ins_cost(LOAD_COST); @@ -5220,6 +5222,7 @@ instruct storeimmP0(immP0 zero, memory mem) // Store Compressed Pointer instruct storeN(iRegN src, memory mem) %{ + predicate(n->as_Store()->barrier_data() == 0); match(Set mem (StoreN mem src)); ins_cost(STORE_COST); @@ -5234,6 +5237,7 @@ instruct storeN(iRegN src, memory mem) instruct storeImmN0(immN0 zero, memory mem) %{ + predicate(n->as_Store()->barrier_data() == 0); match(Set mem (StoreN mem zero)); ins_cost(STORE_COST); @@ -5424,6 +5428,7 @@ instruct compareAndSwapP(iRegINoSp res, indirect mem, iRegP oldval, iRegP newval instruct compareAndSwapN(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); match(Set res (CompareAndSwapN mem (Binary oldval newval))); ins_cost(LOAD_COST + STORE_COST + ALU_COST * 8 + BRANCH_COST * 4); @@ -5545,7 +5550,7 @@ instruct compareAndSwapPAcq(iRegINoSp res, indirect mem, iRegP oldval, iRegP new instruct compareAndSwapNAcq(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval) %{ - predicate(needs_acquiring_load_reserved(n)); + predicate(needs_acquiring_load_reserved(n) && n->as_LoadStore()->barrier_data() == 0); match(Set res (CompareAndSwapN mem (Binary oldval newval))); @@ -5653,6 +5658,7 @@ instruct compareAndExchangeL(iRegLNoSp res, indirect mem, iRegL oldval, iRegL ne instruct compareAndExchangeN(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); match(Set res (CompareAndExchangeN mem (Binary oldval newval))); ins_cost(LOAD_COST + STORE_COST + BRANCH_COST * 3 + ALU_COST * 3); @@ -5786,7 +5792,7 @@ instruct compareAndExchangeLAcq(iRegLNoSp res, indirect mem, iRegL oldval, iRegL instruct compareAndExchangeNAcq(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval) %{ - predicate(needs_acquiring_load_reserved(n)); + predicate(needs_acquiring_load_reserved(n) && n->as_LoadStore()->barrier_data() == 0); match(Set res (CompareAndExchangeN mem (Binary oldval newval))); @@ -5914,6 +5920,7 @@ instruct weakCompareAndSwapL(iRegINoSp res, indirect mem, iRegL oldval, iRegL ne instruct weakCompareAndSwapN(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); ins_cost(LOAD_COST + STORE_COST + BRANCH_COST * 2 + ALU_COST * 4); @@ -6045,7 +6052,7 @@ instruct weakCompareAndSwapLAcq(iRegINoSp res, indirect mem, iRegL oldval, iRegL instruct weakCompareAndSwapNAcq(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval) %{ - predicate(needs_acquiring_load_reserved(n)); + predicate(needs_acquiring_load_reserved(n) && n->as_LoadStore()->barrier_data() == 0); match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); @@ -6117,6 +6124,8 @@ instruct get_and_setL(indirect mem, iRegL newv, iRegLNoSp prev) instruct get_and_setN(indirect mem, iRegN newv, iRegINoSp prev) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); + match(Set prev (GetAndSetN mem newv)); ins_cost(ALU_COST); @@ -6182,7 +6191,7 @@ instruct get_and_setLAcq(indirect mem, iRegL newv, iRegLNoSp prev) instruct get_and_setNAcq(indirect mem, iRegN newv, iRegINoSp prev) %{ - predicate(needs_acquiring_load_reserved(n)); + predicate(needs_acquiring_load_reserved(n) && n->as_LoadStore()->barrier_data() == 0); match(Set prev (GetAndSetN mem newv)); diff --git a/src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp b/src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp index 879fd922722..27da26d404c 100644 --- a/src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp +++ b/src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp @@ -2110,7 +2110,7 @@ void SharedRuntime::generate_deopt_blob() { int reexecute_offset = __ pc() - start; #if INCLUDE_JVMCI && !defined(COMPILER1) - if (EnableJVMCI && UseJVMCICompiler) { + if (UseJVMCICompiler) { // JVMCI does not use this kind of deoptimization __ should_not_reach_here(); } diff --git a/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp b/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp index d4ec76da943..5970111088f 100644 --- a/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp +++ b/src/hotspot/cpu/riscv/stubGenerator_riscv.cpp @@ -6092,26 +6092,17 @@ static const int64_t right_3_bits = right_n_bits(3); address start = __ pc(); + // input parameters const Register crc = c_rarg0; // crc const Register buf = c_rarg1; // source java byte array address const Register len = c_rarg2; // length - const Register table0 = c_rarg3; // crc_table address - const Register table1 = c_rarg4; - const Register table2 = c_rarg5; - const Register table3 = c_rarg6; - - const Register tmp1 = c_rarg7; - const Register tmp2 = t2; - const Register tmp3 = x28; // t3 - const Register tmp4 = x29; // t4 - const Register tmp5 = x30; // t5 - const Register tmp6 = x31; // t6 BLOCK_COMMENT("Entry:"); __ enter(); // required for proper stackwalking of RuntimeStub frame - __ kernel_crc32(crc, buf, len, table0, table1, table2, - table3, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6); + __ kernel_crc32(crc, buf, len, + c_rarg3, c_rarg4, c_rarg5, c_rarg6, // tmp's for tables + c_rarg7, t2, x28, x29, x30, x31); // misc tmps __ leave(); // required for proper stackwalking of RuntimeStub frame __ ret(); diff --git a/src/hotspot/cpu/riscv/templateTable_riscv.cpp b/src/hotspot/cpu/riscv/templateTable_riscv.cpp index 078f54adc36..2e6902180a8 100644 --- a/src/hotspot/cpu/riscv/templateTable_riscv.cpp +++ b/src/hotspot/cpu/riscv/templateTable_riscv.cpp @@ -178,7 +178,6 @@ void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg, __ la(temp_reg, Address(temp_reg, in_bytes(ResolvedFieldEntry::put_code_offset()))); } // Load-acquire the bytecode to match store-release in ResolvedFieldEntry::fill_in() - __ membar(MacroAssembler::AnyAny); __ lbu(temp_reg, Address(temp_reg, 0)); __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); __ mv(bc_reg, bc); @@ -320,7 +319,6 @@ void TemplateTable::ldc(LdcType type) { // get type __ addi(x13, x11, tags_offset); __ add(x13, x10, x13); - __ membar(MacroAssembler::AnyAny); __ lbu(x13, Address(x13, 0)); __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); @@ -2189,7 +2187,6 @@ void TemplateTable::resolve_cache_and_index_for_method(int byte_no, break; } // Load-acquire the bytecode to match store-release in InterpreterRuntime - __ membar(MacroAssembler::AnyAny); __ lbu(temp, Address(temp, 0)); __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); @@ -2241,7 +2238,6 @@ void TemplateTable::resolve_cache_and_index_for_field(int byte_no, __ la(temp, Address(Rcache, in_bytes(ResolvedFieldEntry::put_code_offset()))); } // Load-acquire the bytecode to match store-release in ResolvedFieldEntry::fill_in() - __ membar(MacroAssembler::AnyAny); __ lbu(temp, Address(temp, 0)); __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); __ mv(t0, (int) code); // have we resolved this bytecode? @@ -2403,7 +2399,6 @@ void TemplateTable::load_invokedynamic_entry(Register method) { Label resolved; __ load_resolved_indy_entry(cache, index); - __ membar(MacroAssembler::AnyAny); __ ld(method, Address(cache, in_bytes(ResolvedIndyEntry::method_offset()))); __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); @@ -2418,7 +2413,6 @@ void TemplateTable::load_invokedynamic_entry(Register method) { __ call_VM(noreg, entry, method); // Update registers with resolved info __ load_resolved_indy_entry(cache, index); - __ membar(MacroAssembler::AnyAny); __ ld(method, Address(cache, in_bytes(ResolvedIndyEntry::method_offset()))); __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); @@ -3533,7 +3527,6 @@ void TemplateTable::_new() { const int tags_offset = Array::base_offset_in_bytes(); __ add(t0, x10, x13); __ la(t0, Address(t0, tags_offset)); - __ membar(MacroAssembler::AnyAny); __ lbu(t0, t0); __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); __ sub(t1, t0, (u1)JVM_CONSTANT_Class); @@ -3651,7 +3644,6 @@ void TemplateTable::checkcast() { // See if bytecode has already been quicked __ add(t0, x13, Array::base_offset_in_bytes()); __ add(x11, t0, x9); - __ membar(MacroAssembler::AnyAny); __ lbu(x11, x11); __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); __ sub(t0, x11, (u1)JVM_CONSTANT_Class); @@ -3707,7 +3699,6 @@ void TemplateTable::instanceof() { // See if bytecode has already been quicked __ add(t0, x13, Array::base_offset_in_bytes()); __ add(x11, t0, x9); - __ membar(MacroAssembler::AnyAny); __ lbu(x11, x11); __ membar(MacroAssembler::LoadLoad | MacroAssembler::LoadStore); __ sub(t0, x11, (u1)JVM_CONSTANT_Class); diff --git a/src/hotspot/cpu/s390/gc/g1/g1BarrierSetAssembler_s390.cpp b/src/hotspot/cpu/s390/gc/g1/g1BarrierSetAssembler_s390.cpp index 37631298920..544c82d34a7 100644 --- a/src/hotspot/cpu/s390/gc/g1/g1BarrierSetAssembler_s390.cpp +++ b/src/hotspot/cpu/s390/gc/g1/g1BarrierSetAssembler_s390.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2018, 2023 SAP SE. All rights reserved. + * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024 SAP SE. 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 @@ -42,11 +42,47 @@ #include "c1/c1_LIRAssembler.hpp" #include "c1/c1_MacroAssembler.hpp" #include "gc/g1/c1/g1BarrierSetC1.hpp" -#endif +#endif // COMPILER1 +#ifdef COMPILER2 +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#endif // COMPILER2 #define __ masm-> -#define BLOCK_COMMENT(str) if (PrintAssembly) __ block_comment(str) +#define BLOCK_COMMENT(str) __ block_comment(str) + +static void generate_pre_barrier_fast_path(MacroAssembler* masm, + const Register thread, + const Register tmp1) { + Address in_progress(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset())); + // Is marking active? + if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { + __ load_and_test_int(tmp1, in_progress); + } else { + assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); + __ load_and_test_byte(tmp1, in_progress); + } +} + +static void generate_queue_test_and_insertion(MacroAssembler* masm, ByteSize index_offset, ByteSize buffer_offset, Label& runtime, + const Register Z_thread, const Register value, const Register temp) { + BLOCK_COMMENT("generate_queue_test_and_insertion {"); + + assert_different_registers(temp, value); + // Can we store a value in the given thread's buffer? + // (The index field is typed as size_t.) + + __ load_and_test_long(temp, Address(Z_thread, in_bytes(index_offset))); // temp := *(index address) + __ branch_optimized(Assembler::bcondEqual, runtime); // jump to runtime if index == 0 (full buffer) + + // The buffer is not full, store value into it. + __ add2reg(temp, -wordSize); // temp := next index + __ z_stg(temp, in_bytes(index_offset), Z_thread); // *(index address) := next index + + __ z_ag(temp, Address(Z_thread, in_bytes(buffer_offset))); // temp := buffer address + next index + __ z_stg(value, 0, temp); // *(buffer address + next index) := value + BLOCK_COMMENT("} generate_queue_test_and_insertion"); +} void G1BarrierSetAssembler::gen_write_ref_array_pre_barrier(MacroAssembler* masm, DecoratorSet decorators, Register addr, Register count) { @@ -59,13 +95,8 @@ void G1BarrierSetAssembler::gen_write_ref_array_pre_barrier(MacroAssembler* masm assert_different_registers(addr, Z_R0_scratch); // would be destroyed by push_frame() assert_different_registers(count, Z_R0_scratch); // would be destroyed by push_frame() Register Rtmp1 = Z_R0_scratch; - const int active_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()); - if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { - __ load_and_test_int(Rtmp1, Address(Z_thread, active_offset)); - } else { - guarantee(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); - __ load_and_test_byte(Rtmp1, Address(Z_thread, active_offset)); - } + + generate_pre_barrier_fast_path(masm, Z_thread, Rtmp1); __ z_bre(filtered); // Activity indicator is zero, so there is no marking going on currently. RegisterSaver::save_live_registers(masm, RegisterSaver::arg_registers); // Creates frame. @@ -100,6 +131,181 @@ void G1BarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* mas } } +#if defined(COMPILER2) + +#undef __ +#define __ masm-> + +static void generate_c2_barrier_runtime_call(MacroAssembler* masm, G1BarrierStubC2* stub, const Register pre_val, const address runtime_path) { + BLOCK_COMMENT("generate_c2_barrier_runtime_call {"); + SaveLiveRegisters save_registers(masm, stub); + __ call_VM_leaf(runtime_path, pre_val, Z_thread); + BLOCK_COMMENT("} generate_c2_barrier_runtime_call"); +} + +void G1BarrierSetAssembler::g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register thread, + Register tmp1, + G1PreBarrierStubC2* stub) { + + BLOCK_COMMENT("g1_write_barrier_pre_c2 {"); + + assert(thread == Z_thread, "must be"); + assert_different_registers(obj, pre_val, tmp1); + assert(pre_val != noreg && tmp1 != noreg, "expecting a register"); + + stub->initialize_registers(obj, pre_val, thread, tmp1, noreg); + + generate_pre_barrier_fast_path(masm, thread, tmp1); + __ branch_optimized(Assembler::bcondNotEqual, *stub->entry()); // Activity indicator is zero, so there is no marking going on currently. + + __ bind(*stub->continuation()); + + BLOCK_COMMENT("} g1_write_barrier_pre_c2"); +} + +void G1BarrierSetAssembler::generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const { + + BLOCK_COMMENT("generate_c2_pre_barrier_stub {"); + + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + + Label runtime; + Register obj = stub->obj(); + Register pre_val = stub->pre_val(); + Register thread = stub->thread(); + Register tmp1 = stub->tmp1(); + + __ bind(*stub->entry()); + + BLOCK_COMMENT("generate_pre_val_not_null_test {"); + if (obj != noreg) { + __ load_heap_oop(pre_val, Address(obj), noreg, noreg, AS_RAW); + } + __ z_ltgr(pre_val, pre_val); + __ branch_optimized(Assembler::bcondEqual, *stub->continuation()); + BLOCK_COMMENT("} generate_pre_val_not_null_test"); + + generate_queue_test_and_insertion(masm, + G1ThreadLocalData::satb_mark_queue_index_offset(), + G1ThreadLocalData::satb_mark_queue_buffer_offset(), + runtime, + Z_thread, pre_val, tmp1); + + __ branch_optimized(Assembler::bcondAlways, *stub->continuation()); + + __ bind(runtime); + + generate_c2_barrier_runtime_call(masm, stub, pre_val, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_pre_entry)); + + __ branch_optimized(Assembler::bcondAlways, *stub->continuation()); + + BLOCK_COMMENT("} generate_c2_pre_barrier_stub"); +} + +void G1BarrierSetAssembler::g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register thread, + Register tmp1, + Register tmp2, + G1PostBarrierStubC2* stub) { + BLOCK_COMMENT("g1_write_barrier_post_c2 {"); + + assert(thread == Z_thread, "must be"); + assert_different_registers(store_addr, new_val, thread, tmp1, tmp2, Z_R1_scratch); + + assert(store_addr != noreg && new_val != noreg && tmp1 != noreg && tmp2 != noreg, "expecting a register"); + + stub->initialize_registers(thread, tmp1, tmp2); + + BLOCK_COMMENT("generate_region_crossing_test {"); + if (VM_Version::has_DistinctOpnds()) { + __ z_xgrk(tmp1, store_addr, new_val); + } else { + __ z_lgr(tmp1, store_addr); + __ z_xgr(tmp1, new_val); + } + __ z_srag(tmp1, tmp1, G1HeapRegion::LogOfHRGrainBytes); + __ branch_optimized(Assembler::bcondEqual, *stub->continuation()); + BLOCK_COMMENT("} generate_region_crossing_test"); + + // crosses regions, storing null? + if ((stub->barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ z_ltgr(new_val, new_val); + __ branch_optimized(Assembler::bcondEqual, *stub->continuation()); + } + + BLOCK_COMMENT("generate_card_young_test {"); + CardTableBarrierSet* ct = barrier_set_cast(BarrierSet::barrier_set()); + // calculate address of card + __ load_const_optimized(tmp2, (address)ct->card_table()->byte_map_base()); // Card table base. + __ z_srlg(tmp1, store_addr, CardTable::card_shift()); // Index into card table. + __ z_algr(tmp1, tmp2); // Explicit calculation needed for cli. + + // Filter young. + __ z_cli(0, tmp1, G1CardTable::g1_young_card_val()); + + BLOCK_COMMENT("} generate_card_young_test"); + + // From here on, tmp1 holds the card address. + __ branch_optimized(Assembler::bcondNotEqual, *stub->entry()); + + __ bind(*stub->continuation()); + + BLOCK_COMMENT("} g1_write_barrier_post_c2"); +} + +void G1BarrierSetAssembler::generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const { + + BLOCK_COMMENT("generate_c2_post_barrier_stub {"); + + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + + Register thread = stub->thread(); + Register tmp1 = stub->tmp1(); // tmp1 holds the card address. + Register tmp2 = stub->tmp2(); + Register Rcard_addr = tmp1; + + __ bind(*stub->entry()); + + BLOCK_COMMENT("generate_card_clean_test {"); + __ z_sync(); // Required to support concurrent cleaning. + __ z_cli(0, Rcard_addr, 0); // Reload after membar. + __ branch_optimized(Assembler::bcondEqual, *stub->continuation()); + BLOCK_COMMENT("} generate_card_clean_test"); + + BLOCK_COMMENT("generate_dirty_card {"); + // Storing a region crossing, non-null oop, card is clean. + // Dirty card and log. + STATIC_ASSERT(CardTable::dirty_card_val() == 0); + __ z_mvi(0, Rcard_addr, CardTable::dirty_card_val()); + BLOCK_COMMENT("} generate_dirty_card"); + + generate_queue_test_and_insertion(masm, + G1ThreadLocalData::dirty_card_queue_index_offset(), + G1ThreadLocalData::dirty_card_queue_buffer_offset(), + runtime, + Z_thread, tmp1, tmp2); + + __ branch_optimized(Assembler::bcondAlways, *stub->continuation()); + + __ bind(runtime); + + generate_c2_barrier_runtime_call(masm, stub, tmp1, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry)); + + __ branch_optimized(Assembler::bcondAlways, *stub->continuation()); + + BLOCK_COMMENT("} generate_c2_post_barrier_stub"); +} + +#endif //COMPILER2 + void G1BarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, const Address& src, Register dst, Register tmp1, Register tmp2, Label *L_handle_null) { bool on_oop = is_reference_type(type); @@ -136,9 +342,6 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Decorator const Register Robj = obj ? obj->base() : noreg, Roff = obj ? obj->index() : noreg; - const int active_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()); - const int buffer_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_buffer_offset()); - const int index_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_index_offset()); assert_different_registers(Rtmp1, Rtmp2, Z_R0_scratch); // None of the Rtmp must be Z_R0!! assert_different_registers(Robj, Z_R0_scratch); // Used for addressing. Furthermore, push_frame destroys Z_R0!! assert_different_registers(Rval, Z_R0_scratch); // push_frame destroys Z_R0!! @@ -147,14 +350,7 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Decorator BLOCK_COMMENT("g1_write_barrier_pre {"); - // Is marking active? - // Note: value is loaded for test purposes only. No further use here. - if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { - __ load_and_test_int(Rtmp1, Address(Z_thread, active_offset)); - } else { - guarantee(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); - __ load_and_test_byte(Rtmp1, Address(Z_thread, active_offset)); - } + generate_pre_barrier_fast_path(masm, Z_thread, Rtmp1); __ z_bre(filtered); // Activity indicator is zero, so there is no marking going on currently. assert(Rpre_val != noreg, "must have a real register"); @@ -194,24 +390,14 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Decorator // We can store the original value in the thread's buffer // only if index > 0. Otherwise, we need runtime to handle. // (The index field is typed as size_t.) - Register Rbuffer = Rtmp1, Rindex = Rtmp2; - assert_different_registers(Rbuffer, Rindex, Rpre_val); - - __ z_lg(Rbuffer, buffer_offset, Z_thread); - __ load_and_test_long(Rindex, Address(Z_thread, index_offset)); - __ z_bre(callRuntime); // If index == 0, goto runtime. - - __ add2reg(Rindex, -wordSize); // Decrement index. - __ z_stg(Rindex, index_offset, Z_thread); - - // Record the previous value. - __ z_stg(Rpre_val, 0, Rbuffer, Rindex); + generate_queue_test_and_insertion(masm, + G1ThreadLocalData::satb_mark_queue_index_offset(), + G1ThreadLocalData::satb_mark_queue_buffer_offset(), + callRuntime, + Z_thread, Rpre_val, Rtmp2); __ z_bru(filtered); // We are done. - Rbuffer = noreg; // end of life - Rindex = noreg; // end of life - __ bind(callRuntime); // Save some registers (inputs and result) over runtime call @@ -326,23 +512,16 @@ void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, Decorato Register Rcard_addr_x = Rcard_addr; Register Rqueue_index = (Rtmp2 != Z_R0_scratch) ? Rtmp2 : Rtmp1; - Register Rqueue_buf = (Rtmp3 != Z_R0_scratch) ? Rtmp3 : Rtmp1; - const int qidx_off = in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset()); - const int qbuf_off = in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset()); - if ((Rcard_addr == Rqueue_buf) || (Rcard_addr == Rqueue_index)) { + if (Rcard_addr == Rqueue_index) { Rcard_addr_x = Z_R0_scratch; // Register shortage. We have to use Z_R0. } __ lgr_if_needed(Rcard_addr_x, Rcard_addr); - __ load_and_test_long(Rqueue_index, Address(Z_thread, qidx_off)); - __ z_bre(callRuntime); // Index == 0 then jump to runtime. - - __ z_lg(Rqueue_buf, qbuf_off, Z_thread); - - __ add2reg(Rqueue_index, -wordSize); // Decrement index. - __ z_stg(Rqueue_index, qidx_off, Z_thread); - - __ z_stg(Rcard_addr_x, 0, Rqueue_index, Rqueue_buf); // Store card. + generate_queue_test_and_insertion(masm, + G1ThreadLocalData::dirty_card_queue_index_offset(), + G1ThreadLocalData::dirty_card_queue_buffer_offset(), + callRuntime, + Z_thread, Rcard_addr_x, Rqueue_index); __ z_bru(filtered); __ bind(callRuntime); diff --git a/src/hotspot/cpu/s390/gc/g1/g1BarrierSetAssembler_s390.hpp b/src/hotspot/cpu/s390/gc/g1/g1BarrierSetAssembler_s390.hpp index cc1d51d2fa1..0f0bdd8b83c 100644 --- a/src/hotspot/cpu/s390/gc/g1/g1BarrierSetAssembler_s390.hpp +++ b/src/hotspot/cpu/s390/gc/g1/g1BarrierSetAssembler_s390.hpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2018 SAP SE. All rights reserved. + * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024 SAP SE. 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,6 +34,8 @@ class LIR_Assembler; class StubAssembler; class G1PreBarrierStub; class G1PostBarrierStub; +class G1PreBarrierStubC2; +class G1PostBarrierStubC2; class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { protected: @@ -62,7 +64,27 @@ class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { void generate_c1_pre_barrier_runtime_stub(StubAssembler* sasm); void generate_c1_post_barrier_runtime_stub(StubAssembler* sasm); -#endif +#endif // COMPILER1 + +#ifdef COMPILER2 + void g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register thread, + Register tmp1, + G1PreBarrierStubC2* c2_stub); + void generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const; + void g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register thread, + Register tmp1, + Register tmp2, + G1PostBarrierStubC2* c2_stub); + void generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const; +#endif // COMPILER2 virtual void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, const Address& src, Register dst, Register tmp1, Register tmp2, Label *L_handle_null = nullptr); diff --git a/src/hotspot/cpu/s390/gc/g1/g1_s390.ad b/src/hotspot/cpu/s390/gc/g1/g1_s390.ad new file mode 100644 index 00000000000..31f60c4aeff --- /dev/null +++ b/src/hotspot/cpu/s390/gc/g1/g1_s390.ad @@ -0,0 +1,457 @@ +// +// Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. +// Copyright 2024 IBM Corporation. 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. +// + +source_hpp %{ + +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#include "gc/shared/gc_globals.hpp" + +%} + +source %{ + +#include "gc/g1/g1BarrierSetAssembler_s390.hpp" +#include "gc/g1/g1BarrierSetRuntime.hpp" + +static void write_barrier_pre(MacroAssembler* masm, + const MachNode* node, + Register obj, + Register pre_val, + Register tmp1, + RegSet preserve = RegSet(), + RegSet no_preserve = RegSet()) { + if (!G1PreBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PreBarrierStubC2* const stub = G1PreBarrierStubC2::create(node); + for (RegSetIterator reg = preserve.begin(); *reg != noreg; ++reg) { + stub->preserve(*reg); + } + for (RegSetIterator reg = no_preserve.begin(); *reg != noreg; ++reg) { + stub->dont_preserve(*reg); + } + g1_asm->g1_write_barrier_pre_c2(masm, obj, pre_val, Z_thread, tmp1, stub); +} + +static void write_barrier_post(MacroAssembler* masm, + const MachNode* node, + Register store_addr, + Register new_val, + Register tmp1, + Register tmp2) { + if (!G1PostBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PostBarrierStubC2* const stub = G1PostBarrierStubC2::create(node); + g1_asm->g1_write_barrier_post_c2(masm, store_addr, new_val, Z_thread, tmp1, tmp2, stub); +} + +%} // source + +// store pointer +instruct g1StoreP(indirect dst, memoryRegP src, iRegL tmp1, iRegL tmp2, flagsReg cr) %{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set dst (StoreP dst src)); + effect(TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(MEMORY_REF_COST); + format %{ "STG $src,$dst\t # ptr" %} + ins_encode %{ + __ block_comment("g1StoreP {"); + write_barrier_pre(masm, this, + $dst$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + RegSet::of($dst$$Register, $src$$Register) /* preserve */); + + __ z_stg($src$$Register, Address($dst$$Register)); + + write_barrier_post(masm, this, + $dst$$Register, /* store_addr */ + $src$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + __ block_comment("} g1StoreP"); + %} + ins_pipe(pipe_class_dummy); +%} + +// Store Compressed Pointer +instruct g1StoreN(indirect mem, iRegN_P2N src, iRegL tmp1, iRegL tmp2, iRegL tmp3, flagsReg cr) %{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(MEMORY_REF_COST); + format %{ "STY $src,$mem\t # (cOop)" %} + ins_encode %{ + __ block_comment("g1StoreN {"); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + + __ z_sty($src$$Register, Address($mem$$Register)); + + if ((barrier_data() & G1C2BarrierPost) != 0) { + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ oop_decoder($tmp1$$Register, $src$$Register, true /* maybe_null */); + } else { + __ oop_decoder($tmp1$$Register, $src$$Register, false /* maybe_null */); + } + } + + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + __ block_comment("} g1StoreN"); + %} + + ins_pipe(pipe_class_dummy); +%} + +instruct g1CompareAndSwapN(indirect mem_ptr, rarg5RegN oldval, iRegN_P2N newval, iRegI res, iRegL tmp1, iRegL tmp2, iRegL tmp3, flagsReg cr) %{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapN mem_ptr (Binary oldval newval))); + match(Set res (WeakCompareAndSwapN mem_ptr (Binary oldval newval))); + effect(USE mem_ptr, TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3, USE_KILL oldval, KILL cr); + format %{ "$res = CompareAndSwapN $oldval,$newval,$mem_ptr" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem_ptr$$Register); + assert_different_registers($newval$$Register, $mem_ptr$$Register); + __ block_comment("g1compareAndSwapN {"); + + Register Rcomp = reg_to_register_object($oldval$$reg); + Register Rnew = reg_to_register_object($newval$$reg); + Register Raddr = reg_to_register_object($mem_ptr$$reg); + Register Rres = reg_to_register_object($res$$reg); + + write_barrier_pre(masm, this, + Raddr /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + RegSet::of(Raddr, Rcomp, Rnew) /* preserve */, + RegSet::of(Rres) /* no_preserve */); + + __ z_cs(Rcomp, Rnew, 0, Raddr); + + assert_different_registers(Rres, Raddr); + if (VM_Version::has_LoadStoreConditional()) { + __ load_const_optimized(Z_R0_scratch, 0L); // false (failed) + __ load_const_optimized(Rres, 1L); // true (succeed) + __ z_locgr(Rres, Z_R0_scratch, Assembler::bcondNotEqual); + } else { + Label done; + __ load_const_optimized(Rres, 0L); // false (failed) + __ z_brne(done); // Assume true to be the common case. + __ load_const_optimized(Rres, 1L); // true (succeed) + __ bind(done); + } + + __ oop_decoder($tmp3$$Register, Rnew, true /* maybe_null */); + + write_barrier_post(masm, this, + Raddr /* store_addr */, + $tmp3$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + __ block_comment("} g1compareAndSwapN"); + %} + ins_pipe(pipe_class_dummy); +%} + +instruct g1CompareAndExchangeN(iRegP mem_ptr, rarg5RegN oldval, iRegN_P2N newval, iRegN res, iRegL tmp1, iRegL tmp2, iRegL tmp3, flagsReg cr) %{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeN mem_ptr (Binary oldval newval))); + effect(USE mem_ptr, TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3, USE_KILL oldval, KILL cr); + format %{ "$res = CompareAndExchangeN $oldval,$newval,$mem_ptr" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem_ptr$$Register); + assert_different_registers($newval$$Register, $mem_ptr$$Register); + __ block_comment("g1CompareAndExchangeN {"); + write_barrier_pre(masm, this, + $mem_ptr$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + RegSet::of($mem_ptr$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + + Register Rcomp = reg_to_register_object($oldval$$reg); + Register Rnew = reg_to_register_object($newval$$reg); + Register Raddr = reg_to_register_object($mem_ptr$$reg); + + Register Rres = reg_to_register_object($res$$reg); + assert_different_registers(Rres, Raddr); + + __ z_lgr(Rres, Rcomp); // previous contents + __ z_csy(Rres, Rnew, 0, Raddr); // Try to store new value. + + __ oop_decoder($tmp1$$Register, Rnew, true /* maybe_null */); + + write_barrier_post(masm, this, + Raddr /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + __ block_comment("} g1CompareAndExchangeN"); + %} + ins_pipe(pipe_class_dummy); +%} + +// Load narrow oop +instruct g1LoadN(iRegN dst, indirect mem, iRegP tmp1, iRegP tmp2, flagsReg cr) %{ + predicate(UseG1GC && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadN mem)); + effect(TEMP dst, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(MEMORY_REF_COST); + format %{ "LoadN $dst,$mem\t # (cOop)" %} + ins_encode %{ + __ block_comment("g1LoadN {"); + __ z_llgf($dst$$Register, Address($mem$$Register)); + if ((barrier_data() & G1C2BarrierPre) != 0) { + __ oop_decoder($tmp1$$Register, $dst$$Register, true); + write_barrier_pre(masm, this, + noreg /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register ); + } + __ block_comment("} g1LoadN"); + %} + ins_pipe(pipe_class_dummy); +%} + +instruct g1GetAndSetN(indirect mem, iRegN dst, iRegI tmp, iRegL tmp1, iRegL tmp2, iRegL tmp3, flagsReg cr) %{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set dst (GetAndSetN mem dst)); + effect(KILL cr, TEMP tmp, TEMP tmp1, TEMP tmp2, TEMP tmp3); // USE_DEF dst by match rule. + format %{ "XCHGN $dst,[$mem]\t # EXCHANGE (coop, atomic), temp $tmp" %} + ins_encode %{ + __ block_comment("g1GetAndSetN {"); + assert_different_registers($mem$$Register, $dst$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + RegSet::of($mem$$Register, $dst$$Register) /* preserve */); + + Register Rdst = reg_to_register_object($dst$$reg); + Register Rtmp = reg_to_register_object($tmp$$reg); + guarantee(Rdst != Rtmp, "Fix match rule to use TEMP_DEF"); + Label retry; + + // Iterate until swap succeeds. + __ z_llgf(Rtmp, Address($mem$$Register)); // current contents + __ bind(retry); + // Calculate incremented value. + __ z_csy(Rtmp, Rdst, Address($mem$$Register)); // Try to store new value. + __ z_brne(retry); // Yikes, concurrent update, need to retry. + + __ oop_decoder($tmp1$$Register, $dst$$Register, true /* maybe_null */); + + __ z_lgr(Rdst, Rtmp); // Exchanged value from memory is return value. + + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + + __ block_comment("} g1GetAndSetN"); + %} + ins_pipe(pipe_class_dummy); +%} + +instruct g1CompareAndSwapP(iRegP mem_ptr, rarg5RegP oldval, iRegP_N2P newval, iRegI res, iRegL tmp1, iRegL tmp2, flagsReg cr) %{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapP mem_ptr (Binary oldval newval))); + match(Set res (WeakCompareAndSwapP mem_ptr (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, USE mem_ptr, USE_KILL oldval, KILL cr); + format %{ "$res = CompareAndSwapP $oldval,$newval,$mem_ptr" %} + ins_encode %{ + __ block_comment("g1CompareAndSwapP {"); + assert_different_registers($oldval$$Register, $mem_ptr$$Register); + assert_different_registers($newval$$Register, $mem_ptr$$Register); + + Register Rcomp = reg_to_register_object($oldval$$reg); + Register Rnew = reg_to_register_object($newval$$reg); + Register Raddr = reg_to_register_object($mem_ptr$$reg); + Register Rres = reg_to_register_object($res$$reg); + + write_barrier_pre(masm, this, + noreg /* obj */, + Rcomp /* pre_val */, + $tmp1$$Register /* tmp1 */, + RegSet::of(Raddr, Rcomp, Rnew) /* preserve */, + RegSet::of(Rres) /* no_preserve */); + + __ z_csg(Rcomp, Rnew, 0, Raddr); + + if (VM_Version::has_LoadStoreConditional()) { + __ load_const_optimized(Z_R0_scratch, 0L); // false (failed) + __ load_const_optimized(Rres, 1L); // true (succeed) + __ z_locgr(Rres, Z_R0_scratch, Assembler::bcondNotEqual); + } else { + Label done; + __ load_const_optimized(Rres, 0L); // false (failed) + __ z_brne(done); // Assume true to be the common case. + __ load_const_optimized(Rres, 1L); // true (succeed) + __ bind(done); + } + + write_barrier_post(masm, this, + Raddr /* store_addr */, + Rnew /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + __ block_comment("} g1CompareAndSwapP"); + %} + ins_pipe(pipe_class_dummy); +%} + +instruct g1CompareAndExchangeP(iRegP mem_ptr, rarg5RegP oldval, iRegP_N2P newval, iRegP res, iRegL tmp1, iRegL tmp2, flagsReg cr) %{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndExchangeP mem_ptr (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, USE mem_ptr, USE_KILL oldval, KILL cr); + format %{ "$res = CompareAndExchangeP $oldval,$newval,$mem_ptr" %} + ins_encode %{ + __ block_comment("g1CompareAndExchangeP {"); + assert_different_registers($oldval$$Register, $mem_ptr$$Register); + assert_different_registers($newval$$Register, $mem_ptr$$Register); + + // Pass $oldval to the pre-barrier (instead of loading from $mem), because + // $oldval is the only value that can be overwritten. + // The same holds for g1CompareAndSwapP. + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + RegSet::of($mem_ptr$$Register, $oldval$$Register, $newval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + + __ z_lgr($res$$Register, $oldval$$Register); // previous content + + __ z_csg($oldval$$Register, $newval$$Register, 0, $mem_ptr$$reg); + + write_barrier_post(masm, this, + $mem_ptr$$Register /* store_addr */, + $newval$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + __ block_comment("} g1CompareAndExchangeP"); + %} + ins_pipe(pipe_class_dummy); +%} + +// Load Pointer +instruct g1LoadP(iRegP dst, memory mem, iRegL tmp1, flagsReg cr) %{ + predicate(UseG1GC && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadP mem)); + effect(TEMP dst, TEMP tmp1, KILL cr); + ins_cost(MEMORY_REF_COST); + format %{ "LG $dst,$mem\t # ptr" %} + ins_encode %{ + __ block_comment("g1LoadP {"); + __ z_lg($dst$$Register, $mem$$Address); + write_barrier_pre(masm, this, + noreg /* obj */, + $dst$$Register /* pre_val */, + $tmp1$$Register ); + __ block_comment("} g1LoadP"); + %} + ins_pipe(pipe_class_dummy); +%} + +instruct g1GetAndSetP(indirect mem, iRegP dst, iRegL tmp, iRegL tmp1, iRegL tmp2, flagsReg cr) %{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set dst (GetAndSetP mem dst)); + effect(KILL cr, TEMP tmp, TEMP tmp1, TEMP tmp2); // USE_DEF dst by match rule. + format %{ "XCHGP $dst,[$mem]\t # EXCHANGE (oop, atomic), temp $tmp" %} + ins_encode %{ + __ block_comment("g1GetAndSetP {"); + + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp$$Register /* pre_val (as a temporary register) */, + $tmp1$$Register /* tmp1 */, + RegSet::of($mem$$Register, $dst$$Register) /* preserve */); + + __ z_lgr($tmp1$$Register, $dst$$Register); + Register Rdst = reg_to_register_object($dst$$reg); + Register Rtmp = reg_to_register_object($tmp$$reg); + guarantee(Rdst != Rtmp, "Fix match rule to use TEMP_DEF"); + Label retry; + + // Iterate until swap succeeds. + __ z_lg(Rtmp, Address($mem$$Register)); // current contents + __ bind(retry); + // Calculate incremented value. + __ z_csg(Rtmp, Rdst, Address($mem$$Register)); // Try to store new value. + __ z_brne(retry); // Yikes, concurrent update, need to retry. + __ z_lgr(Rdst, Rtmp); // Exchanged value from memory is return value. + + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp$$Register /* tmp2 */); + __ block_comment("} g1GetAndSetP"); + %} + ins_pipe(pipe_class_dummy); +%} + +instruct g1EncodePAndStoreN(indirect mem, iRegP src, iRegL tmp1, iRegL tmp2, flagsReg cr) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem (EncodeP src))); + effect(TEMP tmp1, TEMP tmp2, KILL cr); + // ins_cost(INSN_COST); + format %{ "encode_heap_oop $tmp1, $src\n\t" + "st $tmp1, $mem\t# compressed ptr" %} + ins_encode %{ + __ block_comment("g1EncodePAndStoreN {"); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp1 */, + RegSet::of($mem$$Register, $src$$Register) /* preserve */); + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ oop_encoder($tmp1$$Register, $src$$Register, true /* maybe_null */); + } else { + __ oop_encoder($tmp1$$Register, $src$$Register, false /* maybe_null */); + } + __ z_st($tmp1$$Register, Address($mem$$Register)); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp1$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + __ block_comment("} g1EncodePAndStoreN"); + %} + ins_pipe(pipe_class_dummy); +%} diff --git a/src/hotspot/cpu/s390/gc/shared/barrierSetAssembler_s390.cpp b/src/hotspot/cpu/s390/gc/shared/barrierSetAssembler_s390.cpp index 28892da6ca4..d826b4a06f3 100644 --- a/src/hotspot/cpu/s390/gc/shared/barrierSetAssembler_s390.cpp +++ b/src/hotspot/cpu/s390/gc/shared/barrierSetAssembler_s390.cpp @@ -33,6 +33,9 @@ #include "runtime/jniHandles.hpp" #include "runtime/stubRoutines.hpp" #include "utilities/macros.hpp" +#ifdef COMPILER2 +#include "gc/shared/c2/barrierSetC2.hpp" +#endif // COMPILER2 #define __ masm-> @@ -194,8 +197,93 @@ void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm) { #ifdef COMPILER2 -OptoReg::Name BarrierSetAssembler::refine_register(const Node* node, OptoReg::Name opto_reg) { - Unimplemented(); // This must be implemented to support late barrier expansion. +OptoReg::Name BarrierSetAssembler::refine_register(const Node* node, OptoReg::Name opto_reg) const { + if (!OptoReg::is_reg(opto_reg)) { + return OptoReg::Bad; + } + + VMReg vm_reg = OptoReg::as_VMReg(opto_reg); + if ((vm_reg->is_Register() || vm_reg ->is_FloatRegister()) && (opto_reg & 1) != 0) { + return OptoReg::Bad; + } + + return opto_reg; +} + +#undef __ +#define __ _masm-> + +SaveLiveRegisters::SaveLiveRegisters(MacroAssembler *masm, BarrierStubC2 *stub) + : _masm(masm), _reg_mask(stub->preserve_set()) { + + const int register_save_size = iterate_over_register_mask(ACTION_COUNT_ONLY) * BytesPerWord; + + _frame_size = align_up(register_save_size, frame::alignment_in_bytes) + frame::z_abi_160_size; // FIXME: this could be restricted to argument only + + __ save_return_pc(); + __ push_frame(_frame_size, Z_R14); // FIXME: check if Z_R1_scaratch can do a job here; + + __ z_lg(Z_R14, _z_common_abi(return_pc) + _frame_size, Z_SP); + + iterate_over_register_mask(ACTION_SAVE, _frame_size); +} + +SaveLiveRegisters::~SaveLiveRegisters() { + iterate_over_register_mask(ACTION_RESTORE, _frame_size); + + __ pop_frame(); + + __ restore_return_pc(); +} + +int SaveLiveRegisters::iterate_over_register_mask(IterationAction action, int offset) { + int reg_save_index = 0; + RegMaskIterator live_regs_iterator(_reg_mask); + + while(live_regs_iterator.has_next()) { + const OptoReg::Name opto_reg = live_regs_iterator.next(); + + // Filter out stack slots (spilled registers, i.e., stack-allocated registers). + if (!OptoReg::is_reg(opto_reg)) { + continue; + } + + const VMReg vm_reg = OptoReg::as_VMReg(opto_reg); + if (vm_reg->is_Register()) { + Register std_reg = vm_reg->as_Register(); + + if (std_reg->encoding() >= Z_R2->encoding() && std_reg->encoding() <= Z_R15->encoding()) { + reg_save_index++; + + if (action == ACTION_SAVE) { + __ z_stg(std_reg, offset - reg_save_index * BytesPerWord, Z_SP); + } else if (action == ACTION_RESTORE) { + __ z_lg(std_reg, offset - reg_save_index * BytesPerWord, Z_SP); + } else { + assert(action == ACTION_COUNT_ONLY, "Sanity"); + } + } + } else if (vm_reg->is_FloatRegister()) { + FloatRegister fp_reg = vm_reg->as_FloatRegister(); + if (fp_reg->encoding() >= Z_F0->encoding() && fp_reg->encoding() <= Z_F15->encoding() + && fp_reg->encoding() != Z_F1->encoding()) { + reg_save_index++; + + if (action == ACTION_SAVE) { + __ z_std(fp_reg, offset - reg_save_index * BytesPerWord, Z_SP); + } else if (action == ACTION_RESTORE) { + __ z_ld(fp_reg, offset - reg_save_index * BytesPerWord, Z_SP); + } else { + assert(action == ACTION_COUNT_ONLY, "Sanity"); + } + } + } else if (false /* vm_reg->is_VectorRegister() */){ + fatal("Vector register support is not there yet!"); + } else { + fatal("Register type is not known"); + } + } + return reg_save_index; } #endif // COMPILER2 diff --git a/src/hotspot/cpu/s390/gc/shared/barrierSetAssembler_s390.hpp b/src/hotspot/cpu/s390/gc/shared/barrierSetAssembler_s390.hpp index de1de8a51a7..fb61adc55b5 100644 --- a/src/hotspot/cpu/s390/gc/shared/barrierSetAssembler_s390.hpp +++ b/src/hotspot/cpu/s390/gc/shared/barrierSetAssembler_s390.hpp @@ -32,7 +32,9 @@ #ifdef COMPILER2 #include "code/vmreg.hpp" #include "opto/optoreg.hpp" +#include "opto/regmask.hpp" +class BarrierStubC2; class Node; #endif // COMPILER2 @@ -62,8 +64,42 @@ class BarrierSetAssembler: public CHeapObj { #ifdef COMPILER2 OptoReg::Name refine_register(const Node* node, - OptoReg::Name opto_reg); + OptoReg::Name opto_reg) const; #endif // COMPILER2 }; +#ifdef COMPILER2 + +// This class saves and restores the registers that need to be preserved across +// the runtime call represented by a given C2 barrier stub. Use as follows: +// { +// SaveLiveRegisters save(masm, stub); +// .. +// __ call_VM_leaf(...); +// .. +// } + +class SaveLiveRegisters { + MacroAssembler* _masm; + RegMask _reg_mask; + Register _result_reg; + int _frame_size; + + public: + SaveLiveRegisters(MacroAssembler *masm, BarrierStubC2 *stub); + + ~SaveLiveRegisters(); + + private: + enum IterationAction : int { + ACTION_SAVE, + ACTION_RESTORE, + ACTION_COUNT_ONLY + }; + + int iterate_over_register_mask(IterationAction action, int offset = 0); +}; + +#endif // COMPILER2 + #endif // CPU_S390_GC_SHARED_BARRIERSETASSEMBLER_S390_HPP diff --git a/src/hotspot/cpu/s390/macroAssembler_s390.cpp b/src/hotspot/cpu/s390/macroAssembler_s390.cpp index 6c26e17d5ce..e192bbab0de 100644 --- a/src/hotspot/cpu/s390/macroAssembler_s390.cpp +++ b/src/hotspot/cpu/s390/macroAssembler_s390.cpp @@ -2127,8 +2127,9 @@ unsigned int MacroAssembler::push_frame_abi160(unsigned int bytes) { // Pop current C frame. void MacroAssembler::pop_frame() { - BLOCK_COMMENT("pop_frame:"); + BLOCK_COMMENT("pop_frame {"); Assembler::z_lg(Z_SP, _z_abi(callers_sp), Z_SP); + BLOCK_COMMENT("} pop_frame"); } // Pop current C frame and restore return PC register (Z_R14). @@ -3655,12 +3656,38 @@ void MacroAssembler::compiler_fast_unlock_object(Register oop, Register box, Reg bind(not_recursive); + NearLabel check_succ, set_eq_unlocked; + + // Set owner to null. + // Release to satisfy the JMM + z_release(); + z_lghi(temp, 0); + z_stg(temp, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner), currentHeader); + // We need a full fence after clearing owner to avoid stranding. + z_fence(); + + // Check if the entry lists are empty. load_and_test_long(temp, Address(currentHeader, OM_OFFSET_NO_MONITOR_VALUE_TAG(EntryList))); - z_brne(done); + z_brne(check_succ); load_and_test_long(temp, Address(currentHeader, OM_OFFSET_NO_MONITOR_VALUE_TAG(cxq))); - z_brne(done); - z_release(); - z_stg(temp/*=0*/, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner), currentHeader); + z_bre(done); // If so we are done. + + bind(check_succ); + + // Check if there is a successor. + load_and_test_long(temp, Address(currentHeader, OM_OFFSET_NO_MONITOR_VALUE_TAG(succ))); + z_brne(set_eq_unlocked); // If so we are done. + + // Save the monitor pointer in the current thread, so we can try to + // reacquire the lock in SharedRuntime::monitor_exit_helper(). + z_xilf(currentHeader, markWord::monitor_value); + z_stg(currentHeader, Address(Z_thread, JavaThread::unlocked_inflated_monitor_offset())); + + z_ltgr(oop, oop); // Set flag = NE + z_bru(done); + + bind(set_eq_unlocked); + z_cr(temp, temp); // Set flag = EQ bind(done); @@ -6454,6 +6481,7 @@ void MacroAssembler::compiler_fast_unlock_lightweight_object(Register obj, Regis const ByteSize monitor_tag = in_ByteSize(UseObjectMonitorTable ? 0 : checked_cast(markWord::monitor_value)); const Address recursions_address{monitor, ObjectMonitor::recursions_offset() - monitor_tag}; const Address cxq_address{monitor, ObjectMonitor::cxq_offset() - monitor_tag}; + const Address succ_address{monitor, ObjectMonitor::succ_offset() - monitor_tag}; const Address EntryList_address{monitor, ObjectMonitor::EntryList_offset() - monitor_tag}; const Address owner_address{monitor, ObjectMonitor::owner_offset() - monitor_tag}; @@ -6471,25 +6499,40 @@ void MacroAssembler::compiler_fast_unlock_lightweight_object(Register obj, Regis bind(not_recursive); - NearLabel not_ok; + NearLabel check_succ, set_eq_unlocked; + + // Set owner to null. + // Release to satisfy the JMM + z_release(); + z_lghi(tmp2, 0); + z_stg(tmp2 /*=0*/, owner_address); + // We need a full fence after clearing owner to avoid stranding. + z_fence(); + // Check if the entry lists are empty. load_and_test_long(tmp2, EntryList_address); - z_brne(not_ok); + z_brne(check_succ); load_and_test_long(tmp2, cxq_address); - z_brne(not_ok); + z_bre(unlocked); // If so we are done. - z_release(); - z_stg(tmp2 /*=0*/, owner_address); + bind(check_succ); - z_bru(unlocked); // CC = EQ here + // Check if there is a successor. + load_and_test_long(tmp2, succ_address); + z_brne(set_eq_unlocked); // If so we are done. - bind(not_ok); + // Save the monitor pointer in the current thread, so we can try to + // reacquire the lock in SharedRuntime::monitor_exit_helper(). + if (!UseObjectMonitorTable) { + z_xilf(monitor, markWord::monitor_value); + } + z_stg(monitor, Address(Z_thread, JavaThread::unlocked_inflated_monitor_offset())); + + z_ltgr(obj, obj); // Set flag = NE + z_bru(slow_path); - // The owner may be anonymous, and we removed the last obj entry in - // the lock-stack. This loses the information about the owner. - // Write the thread to the owner field so the runtime knows the owner. - z_stg(Z_thread, owner_address); - z_bru(slow_path); // CC = NE here + bind(set_eq_unlocked); + z_cr(tmp2, tmp2); // Set flag = EQ } bind(unlocked); diff --git a/src/hotspot/cpu/s390/register_s390.hpp b/src/hotspot/cpu/s390/register_s390.hpp index 931e899257e..18af232e569 100644 --- a/src/hotspot/cpu/s390/register_s390.hpp +++ b/src/hotspot/cpu/s390/register_s390.hpp @@ -448,4 +448,12 @@ constexpr Register Z_R0_scratch = Z_R0; constexpr Register Z_R1_scratch = Z_R1; constexpr FloatRegister Z_fscratch_1 = Z_F1; +typedef AbstractRegSet RegSet; + +template <> +inline Register AbstractRegSet::first() { + if (_bitset == 0) { return noreg; } + return as_Register(count_trailing_zeros(_bitset)); +} + #endif // CPU_S390_REGISTER_S390_HPP diff --git a/src/hotspot/cpu/s390/s390.ad b/src/hotspot/cpu/s390/s390.ad index 4de1a4e7b7f..8181e96ecfc 100644 --- a/src/hotspot/cpu/s390/s390.ad +++ b/src/hotspot/cpu/s390/s390.ad @@ -1644,6 +1644,10 @@ const RegMask Matcher::method_handle_invoke_SP_save_mask() { // Should the matcher clone input 'm' of node 'n'? bool Matcher::pd_clone_node(Node* n, Node* m, Matcher::MStack& mstack) { + if (is_encode_and_store_pattern(n, m)) { + mstack.push(m, Visit); + return true; + } return false; } @@ -3913,6 +3917,7 @@ instruct loadL_unaligned(iRegL dst, memory mem) %{ // Load Pointer instruct loadP(iRegP dst, memory mem) %{ match(Set dst (LoadP mem)); + predicate(n->as_Load()->barrier_data() == 0); ins_cost(MEMORY_REF_COST); size(Z_DISP3_SIZE); format %{ "LG $dst,$mem\t # ptr" %} @@ -3924,6 +3929,7 @@ instruct loadP(iRegP dst, memory mem) %{ // LoadP + CastP2L instruct castP2X_loadP(iRegL dst, memory mem) %{ match(Set dst (CastP2X (LoadP mem))); + predicate(n->as_Load()->barrier_data() == 0); ins_cost(MEMORY_REF_COST); size(Z_DISP3_SIZE); format %{ "LG $dst,$mem\t # ptr + p2x" %} @@ -4286,6 +4292,7 @@ instruct storeL(memory mem, iRegL src) %{ // Store Pointer instruct storeP(memory dst, memoryRegP src) %{ match(Set dst (StoreP dst src)); + predicate(n->as_Store()->barrier_data() == 0); ins_cost(MEMORY_REF_COST); size(Z_DISP3_SIZE); format %{ "STG $src,$dst\t # ptr" %} @@ -4388,6 +4395,7 @@ instruct memInitL(memoryRS mem, immL16 src) %{ // Move Immediate to 8-byte memory. instruct memInitP(memoryRS mem, immP16 src) %{ match(Set mem (StoreP mem src)); + predicate(n->as_Store()->barrier_data() == 0); ins_cost(MEMORY_REF_COST); size(6); format %{ "MVGHI $mem,$src\t # direct mem init 8" %} @@ -4417,6 +4425,7 @@ instruct negL_reg_reg(iRegL dst, immL_0 zero, iRegL src, flagsReg cr) %{ // Load narrow oop instruct loadN(iRegN dst, memory mem) %{ match(Set dst (LoadN mem)); + predicate(n->as_Load()->barrier_data() == 0); ins_cost(MEMORY_REF_COST); size(Z_DISP3_SIZE); format %{ "LoadN $dst,$mem\t # (cOop)" %} @@ -4480,7 +4489,7 @@ instruct loadConNKlass(iRegN dst, immNKlass src) %{ instruct decodeLoadN(iRegP dst, memory mem) %{ match(Set dst (DecodeN (LoadN mem))); - predicate(false && (CompressedOops::base()==nullptr)&&(CompressedOops::shift()==0)); + predicate(false && (CompressedOops::base()==nullptr) && (CompressedOops::shift()==0)); ins_cost(MEMORY_REF_COST); size(Z_DISP3_SIZE); format %{ "DecodeLoadN $dst,$mem\t # (cOop Load+Decode)" %} @@ -4628,7 +4637,7 @@ instruct encodeP(iRegN dst, iRegP src, flagsReg cr) %{ match(Set dst (EncodeP src)); effect(KILL cr); predicate((n->bottom_type()->make_ptr()->ptr() != TypePtr::NotNull) && - (CompressedOops::base() == 0 || + (CompressedOops::base() == nullptr || CompressedOops::base_disjoint() || !ExpandLoadingBaseEncode)); ins_cost(MEMORY_REF_COST+3 * DEFAULT_COST); @@ -4651,7 +4660,7 @@ instruct encodeP_NN(iRegN dst, iRegP src, flagsReg cr) %{ match(Set dst (EncodeP src)); effect(KILL cr); predicate((n->bottom_type()->make_ptr()->ptr() == TypePtr::NotNull) && - (CompressedOops::base() == 0 || + (CompressedOops::base() == nullptr || CompressedOops::base_disjoint() || !ExpandLoadingBaseEncode_NN)); ins_cost(MEMORY_REF_COST+3 * DEFAULT_COST); @@ -4735,6 +4744,7 @@ instruct encodeP_NN_Ex(iRegN dst, iRegP src, flagsReg cr) %{ // Store Compressed Pointer instruct storeN(memory mem, iRegN_P2N src) %{ match(Set mem (StoreN mem src)); + predicate(n->as_Store()->barrier_data() == 0); ins_cost(MEMORY_REF_COST); size(Z_DISP_SIZE); format %{ "ST $src,$mem\t # (cOop)" %} @@ -5146,6 +5156,7 @@ instruct compareAndSwapL_bool(iRegP mem_ptr, rarg5RegL oldval, iRegL newval, iRe instruct compareAndSwapP_bool(iRegP mem_ptr, rarg5RegP oldval, iRegP_N2P newval, iRegI res, flagsReg cr) %{ match(Set res (CompareAndSwapP mem_ptr (Binary oldval newval))); + predicate(n->as_LoadStore()->barrier_data() == 0); effect(USE mem_ptr, USE_KILL oldval, KILL cr); size(18); format %{ "$res = CompareAndSwapP $oldval,$newval,$mem_ptr" %} @@ -5156,6 +5167,7 @@ instruct compareAndSwapP_bool(iRegP mem_ptr, rarg5RegP oldval, iRegP_N2P newval, instruct compareAndSwapN_bool(iRegP mem_ptr, rarg5RegN oldval, iRegN_P2N newval, iRegI res, flagsReg cr) %{ match(Set res (CompareAndSwapN mem_ptr (Binary oldval newval))); + predicate(n->as_LoadStore()->barrier_data() == 0); effect(USE mem_ptr, USE_KILL oldval, KILL cr); size(16); format %{ "$res = CompareAndSwapN $oldval,$newval,$mem_ptr" %} @@ -5443,6 +5455,7 @@ instruct xchgL_reg_mem(memoryRSY mem, iRegL dst, iRegL tmp, flagsReg cr) %{ %} instruct xchgN_reg_mem(memoryRSY mem, iRegN dst, iRegI tmp, flagsReg cr) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); match(Set dst (GetAndSetN mem dst)); effect(KILL cr, TEMP tmp); // USE_DEF dst by match rule. format %{ "XCHGN $dst,[$mem]\t # EXCHANGE (coop, atomic), temp $tmp" %} @@ -5452,6 +5465,7 @@ instruct xchgN_reg_mem(memoryRSY mem, iRegN dst, iRegI tmp, flagsReg cr) %{ instruct xchgP_reg_mem(memoryRSY mem, iRegP dst, iRegL tmp, flagsReg cr) %{ match(Set dst (GetAndSetP mem dst)); + predicate(n->as_LoadStore()->barrier_data() == 0); effect(KILL cr, TEMP tmp); // USE_DEF dst by match rule. format %{ "XCHGP $dst,[$mem]\t # EXCHANGE (oop, atomic), temp $tmp" %} ins_encode(z_enc_SwapL(mem, dst, tmp)); @@ -5926,7 +5940,7 @@ instruct addP_regN_reg_imm20(iRegP dst, iRegP_N2P src1, iRegL src2, immL20 con) instruct addP_mem_imm(memoryRSY mem, immL8 src, flagsReg cr) %{ match(Set mem (StoreP mem (AddP (LoadP mem) src))); effect(KILL cr); - predicate(VM_Version::has_MemWithImmALUOps()); + predicate(VM_Version::has_MemWithImmALUOps() && n->as_LoadStore()->barrier_data() == 0); ins_cost(MEMORY_REF_COST); size(6); format %{ "AGSI $mem,$src\t # direct mem add 8 (ptr)" %} diff --git a/src/hotspot/cpu/x86/assembler_x86.cpp b/src/hotspot/cpu/x86/assembler_x86.cpp index 07476ab342f..c1679cd111f 100644 --- a/src/hotspot/cpu/x86/assembler_x86.cpp +++ b/src/hotspot/cpu/x86/assembler_x86.cpp @@ -1919,6 +1919,11 @@ void Assembler::cmpb(Address dst, int imm8) { emit_int8(imm8); } +void Assembler::cmpb(Register dst, int imm8) { + prefix(dst); + emit_arith_b(0x80, 0xF8, dst, imm8); +} + void Assembler::cmpl(Address dst, int32_t imm32) { InstructionMark im(this); prefix(dst); @@ -9667,6 +9672,15 @@ void Assembler::vinserti64x4(XMMRegister dst, XMMRegister nds, XMMRegister src, emit_int24(0x3A, (0xC0 | encode), imm8 & 0x01); } +void Assembler::evinserti64x2(XMMRegister dst, XMMRegister nds, XMMRegister src, uint8_t imm8, int vector_len) { + assert(VM_Version::supports_avx512dq(), ""); + assert(vector_len == AVX_512bit || VM_Version::supports_avx512vl(), ""); + InstructionAttr attributes(vector_len, /* vex_w */ true, /* legacy_mode */ false, /* no_mask_reg */ true, /* uses_vl */ true); + attributes.set_is_evex_instruction(); + int encode = vex_prefix_and_encode(dst->encoding(), nds->encoding(), src->encoding(), VEX_SIMD_66, VEX_OPCODE_0F_3A, &attributes); + emit_int24(0x38, (0xC0 | encode), imm8 & 0x03); +} + // vinsertf forms @@ -11731,6 +11745,21 @@ void Assembler::vbroadcastf128(XMMRegister dst, Address src, int vector_len) { emit_operand(dst, src, 0); } +void Assembler::evbroadcastf64x2(XMMRegister dst, Address src, int vector_len) { + assert(VM_Version::supports_avx512dq(), ""); + assert(vector_len == AVX_512bit || VM_Version::supports_avx512vl(), ""); + assert(dst != xnoreg, "sanity"); + InstructionMark im(this); + InstructionAttr attributes(vector_len, /* vex_w */ true, /* legacy_mode */ false, /* no_mask_reg */ true, /* uses_vl */ true); + attributes.set_address_attributes(/* tuple_type */ EVEX_T2, /* input_size_in_bits */ EVEX_64bit); + attributes.set_is_evex_instruction(); + // swap src<->dst for encoding + vex_prefix(src, 0, dst->encoding(), VEX_SIMD_66, VEX_OPCODE_0F_38, &attributes); + emit_int8(0x1A); + emit_operand(dst, src, 0); +} + + // gpr source broadcast forms // duplicate 1-byte integer data from src into programmed locations in dest : requires AVX512BW and AVX512VL diff --git a/src/hotspot/cpu/x86/assembler_x86.hpp b/src/hotspot/cpu/x86/assembler_x86.hpp index 62700d1fa1b..eace7bb9cc1 100644 --- a/src/hotspot/cpu/x86/assembler_x86.hpp +++ b/src/hotspot/cpu/x86/assembler_x86.hpp @@ -1239,6 +1239,7 @@ class Assembler : public AbstractAssembler { void cmpb(Address dst, int imm8); void cmpb(Address dst, Register reg); void cmpb(Register reg, Address dst); + void cmpb(Register reg, int imm8); void cmpl(Address dst, int32_t imm32); void cmpl(Register dst, int32_t imm32); @@ -2986,6 +2987,7 @@ class Assembler : public AbstractAssembler { void vinserti32x4(XMMRegister dst, XMMRegister nds, XMMRegister src, uint8_t imm8); void vinserti32x4(XMMRegister dst, XMMRegister nds, Address src, uint8_t imm8); void vinserti64x4(XMMRegister dst, XMMRegister nds, XMMRegister src, uint8_t imm8); + void evinserti64x2(XMMRegister dst, XMMRegister nds, XMMRegister src, uint8_t imm8, int vector_len); // vinsertf forms void vinsertf128(XMMRegister dst, XMMRegister nds, XMMRegister src, uint8_t imm8); @@ -3035,6 +3037,7 @@ class Assembler : public AbstractAssembler { void vbroadcastsd(XMMRegister dst, XMMRegister src, int vector_len); void vbroadcastsd(XMMRegister dst, Address src, int vector_len); void vbroadcastf128(XMMRegister dst, Address src, int vector_len); + void evbroadcastf64x2(XMMRegister dst, Address src, int vector_len); // gpr sourced byte/word/dword/qword replicate void evpbroadcastb(XMMRegister dst, Register src, int vector_len); diff --git a/src/hotspot/cpu/x86/c2_CodeStubs_x86.cpp b/src/hotspot/cpu/x86/c2_CodeStubs_x86.cpp index 1990488d8a0..44f897529e7 100644 --- a/src/hotspot/cpu/x86/c2_CodeStubs_x86.cpp +++ b/src/hotspot/cpu/x86/c2_CodeStubs_x86.cpp @@ -80,8 +80,6 @@ int C2FastUnlockLightweightStub::max_size() const { void C2FastUnlockLightweightStub::emit(C2_MacroAssembler& masm) { assert(_t == rax, "must be"); - Label restore_held_monitor_count_and_slow_path; - { // Restore lock-stack and handle the unlock in runtime. __ bind(_push_and_slow_path); @@ -91,61 +89,9 @@ void C2FastUnlockLightweightStub::emit(C2_MacroAssembler& masm) { __ movptr(Address(_thread, _t), _obj); #endif __ addl(Address(_thread, JavaThread::lock_stack_top_offset()), oopSize); - } - - { // Restore held monitor count and slow path. - - __ bind(restore_held_monitor_count_and_slow_path); - __ bind(_slow_path); - // Restore held monitor count. - __ increment(Address(_thread, JavaThread::held_monitor_count_offset())); - // increment will always result in ZF = 0 (no overflows). + // addl will always result in ZF = 0 (no overflows). __ jmp(slow_path_continuation()); } - - { // Handle monitor medium path. - - __ bind(_check_successor); - - Label fix_zf_and_unlocked; - const Register monitor = _mark; - -#ifndef _LP64 - __ jmpb(restore_held_monitor_count_and_slow_path); -#else // _LP64 - const ByteSize monitor_tag = in_ByteSize(UseObjectMonitorTable ? 0 : checked_cast(markWord::monitor_value)); - const Address succ_address(monitor, ObjectMonitor::succ_offset() - monitor_tag); - const Address owner_address(monitor, ObjectMonitor::owner_offset() - monitor_tag); - - // successor null check. - __ cmpptr(succ_address, NULL_WORD); - __ jccb(Assembler::equal, restore_held_monitor_count_and_slow_path); - - // Release lock. - __ movptr(owner_address, NULL_WORD); - - // Fence. - // Instead of MFENCE we use a dummy locked add of 0 to the top-of-stack. - __ lock(); __ addl(Address(rsp, 0), 0); - - // Recheck successor. - __ cmpptr(succ_address, NULL_WORD); - // Observed a successor after the release -> fence we have handed off the monitor - __ jccb(Assembler::notEqual, fix_zf_and_unlocked); - - // Try to relock, if it fails the monitor has been handed over - // TODO: Caveat, this may fail due to deflation, which does - // not handle the monitor handoff. Currently only works - // due to the responsible thread. - __ xorptr(rax, rax); - __ lock(); __ cmpxchgptr(_thread, owner_address); - __ jccb (Assembler::equal, restore_held_monitor_count_and_slow_path); -#endif - - __ bind(fix_zf_and_unlocked); - __ xorl(rax, rax); - __ jmp(unlocked_continuation()); - } } #undef __ diff --git a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp index c2801a791cb..839745f76ec 100644 --- a/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp @@ -459,87 +459,43 @@ void C2_MacroAssembler::fast_unlock(Register objReg, Register boxReg, Register t // IA32's memory-model is SPO, so STs are ordered with respect to // each other and there's no need for an explicit barrier (fence). // See also http://gee.cs.oswego.edu/dl/jmm/cookbook.html. -#ifndef _LP64 - // Note that we could employ various encoding schemes to reduce - // the number of loads below (currently 4) to just 2 or 3. - // Refer to the comments in synchronizer.cpp. - // In practice the chain of fetches doesn't seem to impact performance, however. - xorptr(boxReg, boxReg); - orptr(boxReg, Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(recursions))); - jccb (Assembler::notZero, DONE_LABEL); - movptr(boxReg, Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(EntryList))); - orptr(boxReg, Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(cxq))); - jccb (Assembler::notZero, DONE_LABEL); - movptr(Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner)), NULL_WORD); - jmpb (DONE_LABEL); -#else // _LP64 - // It's inflated - Label CheckSucc, LNotRecursive, LSuccess, LGoSlowPath; + Label LSuccess, LNotRecursive; cmpptr(Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(recursions)), 0); jccb(Assembler::equal, LNotRecursive); // Recursive inflated unlock - decq(Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(recursions))); + decrement(Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(recursions))); jmpb(LSuccess); bind(LNotRecursive); - movptr(boxReg, Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(cxq))); - orptr(boxReg, Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(EntryList))); - jccb (Assembler::notZero, CheckSucc); - // Without cast to int32_t this style of movptr will destroy r10 which is typically obj. + + // Set owner to null. + // Release to satisfy the JMM movptr(Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner)), NULL_WORD); - jmpb (DONE_LABEL); + // We need a full fence after clearing owner to avoid stranding. + // StoreLoad achieves this. + membar(StoreLoad); - // Try to avoid passing control into the slow_path ... - bind (CheckSucc); + // Check if the entry lists are empty. + movptr(boxReg, Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(cxq))); + orptr(boxReg, Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(EntryList))); + jccb(Assembler::zero, LSuccess); // If so we are done. - // The following optional optimization can be elided if necessary - // Effectively: if (succ == null) goto slow path - // The code reduces the window for a race, however, - // and thus benefits performance. + // Check if there is a successor. cmpptr(Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(succ)), NULL_WORD); - jccb (Assembler::zero, LGoSlowPath); - - xorptr(boxReg, boxReg); - // Without cast to int32_t this style of movptr will destroy r10 which is typically obj. - movptr(Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner)), NULL_WORD); + jccb(Assembler::notZero, LSuccess); // If so we are done. - // Memory barrier/fence - // Dekker pivot point -- fulcrum : ST Owner; MEMBAR; LD Succ - // Instead of MFENCE we use a dummy locked add of 0 to the top-of-stack. - // This is faster on Nehalem and AMD Shanghai/Barcelona. - // See https://blogs.oracle.com/dave/entry/instruction_selection_for_volatile_fences - // We might also restructure (ST Owner=0;barrier;LD _Succ) to - // (mov box,0; xchgq box, &m->Owner; LD _succ) . - lock(); addl(Address(rsp, 0), 0); + // Save the monitor pointer in the current thread, so we can try to + // reacquire the lock in SharedRuntime::monitor_exit_helper(). + andptr(tmpReg, ~(int32_t)markWord::monitor_value); +#ifndef _LP64 + get_thread(boxReg); + movptr(Address(boxReg, JavaThread::unlocked_inflated_monitor_offset()), tmpReg); +#else // _LP64 + movptr(Address(r15_thread, JavaThread::unlocked_inflated_monitor_offset()), tmpReg); +#endif - cmpptr(Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(succ)), NULL_WORD); - jccb (Assembler::notZero, LSuccess); - - // Rare inopportune interleaving - race. - // The successor vanished in the small window above. - // The lock is contended -- (cxq|EntryList) != null -- and there's no apparent successor. - // We need to ensure progress and succession. - // Try to reacquire the lock. - // If that fails then the new owner is responsible for succession and this - // thread needs to take no further action and can exit via the fast path (success). - // If the re-acquire succeeds then pass control into the slow path. - // As implemented, this latter mode is horrible because we generated more - // coherence traffic on the lock *and* artificially extended the critical section - // length while by virtue of passing control into the slow path. - - // box is really RAX -- the following CMPXCHG depends on that binding - // cmpxchg R,[M] is equivalent to rax = CAS(M,rax,R) - lock(); - cmpxchgptr(r15_thread, Address(tmpReg, OM_OFFSET_NO_MONITOR_VALUE_TAG(owner))); - // There's no successor so we tried to regrab the lock. - // If that didn't work, then another thread grabbed the - // lock so we're done (and exit was a success). - jccb (Assembler::notEqual, LSuccess); - // Intentional fall-through into slow path - - bind (LGoSlowPath); orl (boxReg, 1); // set ICC.ZF=0 to indicate failure jmpb (DONE_LABEL); @@ -547,7 +503,6 @@ void C2_MacroAssembler::fast_unlock(Register objReg, Register boxReg, Register t testl (boxReg, 0); // set ICC.ZF=1 to indicate success jmpb (DONE_LABEL); -#endif if (LockingMode == LM_LEGACY) { bind (Stacked); movptr(tmpReg, Address (boxReg, 0)); // re-fetch @@ -744,10 +699,7 @@ void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register reg_rax, // Handle inflated monitor. Label inflated, inflated_check_lock_stack; // Finish fast unlock successfully. MUST jump with ZF == 1 - Label unlocked; - - // Assume success. - decrement(Address(thread, JavaThread::held_monitor_count_offset())); + Label unlocked, slow_path; const Register mark = t; const Register monitor = t; @@ -763,8 +715,6 @@ void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register reg_rax, } Label& push_and_slow_path = stub == nullptr ? dummy : stub->push_and_slow_path(); - Label& check_successor = stub == nullptr ? dummy : stub->check_successor(); - Label& slow_path = stub == nullptr ? dummy : stub->slow_path(); { // Lightweight Unlock @@ -839,6 +789,7 @@ void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register reg_rax, const ByteSize monitor_tag = in_ByteSize(UseObjectMonitorTable ? 0 : checked_cast(markWord::monitor_value)); const Address recursions_address{monitor, ObjectMonitor::recursions_offset() - monitor_tag}; const Address cxq_address{monitor, ObjectMonitor::cxq_offset() - monitor_tag}; + const Address succ_address{monitor, ObjectMonitor::succ_offset() - monitor_tag}; const Address EntryList_address{monitor, ObjectMonitor::EntryList_offset() - monitor_tag}; const Address owner_address{monitor, ObjectMonitor::owner_offset() - monitor_tag}; @@ -846,27 +797,42 @@ void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register reg_rax, // Check if recursive. cmpptr(recursions_address, 0); - jccb(Assembler::notEqual, recursive); + jccb(Assembler::notZero, recursive); + + // Set owner to null. + // Release to satisfy the JMM + movptr(owner_address, NULL_WORD); + // We need a full fence after clearing owner to avoid stranding. + // StoreLoad achieves this. + membar(StoreLoad); // Check if the entry lists are empty. movptr(reg_rax, cxq_address); orptr(reg_rax, EntryList_address); - jcc(Assembler::notZero, check_successor); + jccb(Assembler::zero, unlocked); // If so we are done. - // Release lock. - movptr(owner_address, NULL_WORD); - jmpb(unlocked); + // Check if there is a successor. + cmpptr(succ_address, NULL_WORD); + jccb(Assembler::notZero, unlocked); // If so we are done. + + // Save the monitor pointer in the current thread, so we can try to + // reacquire the lock in SharedRuntime::monitor_exit_helper(). + if (!UseObjectMonitorTable) { + andptr(monitor, ~(int32_t)markWord::monitor_value); + } + movptr(Address(thread, JavaThread::unlocked_inflated_monitor_offset()), monitor); + + testl(monitor, monitor); // Fast Unlock ZF = 0 + jmpb(slow_path); // Recursive unlock. bind(recursive); decrement(recursions_address); - xorl(t, t); } bind(unlocked); - if (stub != nullptr) { - bind(stub->unlocked_continuation()); - } + decrement(Address(thread, JavaThread::held_monitor_count_offset())); + xorl(t, t); // Fast Unlock ZF = 1 #ifdef ASSERT // Check that unlocked label is reached with ZF set. @@ -875,6 +841,7 @@ void C2_MacroAssembler::fast_unlock_lightweight(Register obj, Register reg_rax, stop("Fast Unlock ZF != 1"); #endif + bind(slow_path); if (stub != nullptr) { bind(stub->slow_path_continuation()); } diff --git a/src/hotspot/cpu/x86/gc/g1/g1BarrierSetAssembler_x86.cpp b/src/hotspot/cpu/x86/gc/g1/g1BarrierSetAssembler_x86.cpp index b52be627776..b6be4012519 100644 --- a/src/hotspot/cpu/x86/gc/g1/g1BarrierSetAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/gc/g1/g1BarrierSetAssembler_x86.cpp @@ -38,7 +38,10 @@ #include "c1/c1_LIRAssembler.hpp" #include "c1/c1_MacroAssembler.hpp" #include "gc/g1/c1/g1BarrierSetC1.hpp" -#endif +#endif // COMPILER1 +#ifdef COMPILER2 +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#endif // COMPILER2 #define __ masm-> @@ -160,6 +163,56 @@ void G1BarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorator } } +static void generate_queue_insertion(MacroAssembler* masm, ByteSize index_offset, ByteSize buffer_offset, Label& runtime, + const Register thread, const Register value, const Register temp) { + // This code assumes that buffer index is pointer sized. + STATIC_ASSERT(in_bytes(SATBMarkQueue::byte_width_of_index()) == sizeof(intptr_t)); + // Can we store a value in the given thread's buffer? + // (The index field is typed as size_t.) + __ movptr(temp, Address(thread, in_bytes(index_offset))); // temp := *(index address) + __ testptr(temp, temp); // index == 0? + __ jcc(Assembler::zero, runtime); // jump to runtime if index == 0 (full buffer) + // The buffer is not full, store value into it. + __ subptr(temp, wordSize); // temp := next index + __ movptr(Address(thread, in_bytes(index_offset)), temp); // *(index address) := next index + __ addptr(temp, Address(thread, in_bytes(buffer_offset))); // temp := buffer address + next index + __ movptr(Address(temp, 0), value); // *(buffer address + next index) := value +} + +static void generate_pre_barrier_fast_path(MacroAssembler* masm, + const Register thread) { + Address in_progress(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset())); + // Is marking active? + if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { + __ cmpl(in_progress, 0); + } else { + assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); + __ cmpb(in_progress, 0); + } +} + +static void generate_pre_barrier_slow_path(MacroAssembler* masm, + const Register obj, + const Register pre_val, + const Register thread, + const Register tmp, + Label& done, + Label& runtime) { + // Do we need to load the previous value? + if (obj != noreg) { + __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW); + } + // Is the previous value null? + __ cmpptr(pre_val, NULL_WORD); + __ jcc(Assembler::equal, done); + generate_queue_insertion(masm, + G1ThreadLocalData::satb_mark_queue_index_offset(), + G1ThreadLocalData::satb_mark_queue_buffer_offset(), + runtime, + thread, pre_val, tmp); + __ jmp(done); +} + void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Register obj, Register pre_val, @@ -185,43 +238,10 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, assert(pre_val != rax, "check this code"); } - Address in_progress(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset())); - Address index(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_index_offset())); - Address buffer(thread, in_bytes(G1ThreadLocalData::satb_mark_queue_buffer_offset())); - - // Is marking active? - if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) { - __ cmpl(in_progress, 0); - } else { - assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption"); - __ cmpb(in_progress, 0); - } - __ jcc(Assembler::equal, done); - - // Do we need to load the previous value? - if (obj != noreg) { - __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW); - } - - // Is the previous value null? - __ cmpptr(pre_val, NULL_WORD); + generate_pre_barrier_fast_path(masm, thread); + // If marking is not active (*(mark queue active address) == 0), jump to done __ jcc(Assembler::equal, done); - - // Can we store original value in the thread's buffer? - // Is index == 0? - // (The index field is typed as size_t.) - - __ movptr(tmp, index); // tmp := *index_adr - __ cmpptr(tmp, 0); // tmp == 0? - __ jcc(Assembler::equal, runtime); // If yes, goto runtime - - __ subptr(tmp, wordSize); // tmp := tmp - wordSize - __ movptr(index, tmp); // *index_adr := tmp - __ addptr(tmp, buffer); // tmp := tmp + *buffer_adr - - // Record the previous value - __ movptr(Address(tmp, 0), pre_val); - __ jmp(done); + generate_pre_barrier_slow_path(masm, obj, pre_val, thread, tmp, done, runtime); __ bind(runtime); @@ -263,6 +283,54 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, __ bind(done); } +static void generate_post_barrier_fast_path(MacroAssembler* masm, + const Register store_addr, + const Register new_val, + const Register tmp, + const Register tmp2, + Label& done, + bool new_val_may_be_null) { + CardTableBarrierSet* ct = barrier_set_cast(BarrierSet::barrier_set()); + // Does store cross heap regions? + __ movptr(tmp, store_addr); // tmp := store address + __ xorptr(tmp, new_val); // tmp := store address ^ new value + __ shrptr(tmp, G1HeapRegion::LogOfHRGrainBytes); // ((store address ^ new value) >> LogOfHRGrainBytes) == 0? + __ jcc(Assembler::equal, done); + // Crosses regions, storing null? + if (new_val_may_be_null) { + __ cmpptr(new_val, NULL_WORD); // new value == null? + __ jcc(Assembler::equal, done); + } + // Storing region crossing non-null, is card young? + __ movptr(tmp, store_addr); // tmp := store address + __ shrptr(tmp, CardTable::card_shift()); // tmp := card address relative to card table base + // Do not use ExternalAddress to load 'byte_map_base', since 'byte_map_base' is NOT + // a valid address and therefore is not properly handled by the relocation code. + __ movptr(tmp2, (intptr_t)ct->card_table()->byte_map_base()); // tmp2 := card table base address + __ addptr(tmp, tmp2); // tmp := card address + __ cmpb(Address(tmp, 0), G1CardTable::g1_young_card_val()); // *(card address) == young_card_val? +} + +static void generate_post_barrier_slow_path(MacroAssembler* masm, + const Register thread, + const Register tmp, + const Register tmp2, + Label& done, + Label& runtime) { + __ membar(Assembler::Membar_mask_bits(Assembler::StoreLoad)); // StoreLoad membar + __ cmpb(Address(tmp, 0), G1CardTable::dirty_card_val()); // *(card address) == dirty_card_val? + __ jcc(Assembler::equal, done); + // Storing a region crossing, non-null oop, card is clean. + // Dirty card and log. + __ movb(Address(tmp, 0), G1CardTable::dirty_card_val()); // *(card address) := dirty_card_val + generate_queue_insertion(masm, + G1ThreadLocalData::dirty_card_queue_index_offset(), + G1ThreadLocalData::dirty_card_queue_buffer_offset(), + runtime, + thread, tmp, tmp2); + __ jmp(done); +} + void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, Register store_addr, Register new_val, @@ -273,74 +341,125 @@ void G1BarrierSetAssembler::g1_write_barrier_post(MacroAssembler* masm, assert(thread == r15_thread, "must be"); #endif // _LP64 - Address queue_index(thread, in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset())); - Address buffer(thread, in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset())); - - CardTableBarrierSet* ct = - barrier_set_cast(BarrierSet::barrier_set()); - Label done; Label runtime; - // Does store cross heap regions? - - __ movptr(tmp, store_addr); - __ xorptr(tmp, new_val); - __ shrptr(tmp, G1HeapRegion::LogOfHRGrainBytes); + generate_post_barrier_fast_path(masm, store_addr, new_val, tmp, tmp2, done, true /* new_val_may_be_null */); + // If card is young, jump to done __ jcc(Assembler::equal, done); + generate_post_barrier_slow_path(masm, thread, tmp, tmp2, done, runtime); - // crosses regions, storing null? + __ bind(runtime); + // save the live input values + RegSet saved = RegSet::of(store_addr NOT_LP64(COMMA thread)); + __ push_set(saved); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry), tmp, thread); + __ pop_set(saved); - __ cmpptr(new_val, NULL_WORD); - __ jcc(Assembler::equal, done); + __ bind(done); +} - // storing region crossing non-null, is card already dirty? +#if defined(COMPILER2) - const Register card_addr = tmp; - const Register cardtable = tmp2; +static void generate_c2_barrier_runtime_call(MacroAssembler* masm, G1BarrierStubC2* stub, const Register arg, const address runtime_path) { +#ifdef _LP64 + SaveLiveRegisters save_registers(masm, stub); + if (c_rarg0 != arg) { + __ mov(c_rarg0, arg); + } + __ mov(c_rarg1, r15_thread); + // rax is a caller-saved, non-argument-passing register, so it does not + // interfere with c_rarg0 or c_rarg1. If it contained any live value before + // entering this stub, it is saved at this point, and restored after the + // call. If it did not contain any live value, it is free to be used. In + // either case, it is safe to use it here as a call scratch register. + __ call(RuntimeAddress(runtime_path), rax); +#else + Unimplemented(); +#endif // _LP64 +} - __ movptr(card_addr, store_addr); - __ shrptr(card_addr, CardTable::card_shift()); - // Do not use ExternalAddress to load 'byte_map_base', since 'byte_map_base' is NOT - // a valid address and therefore is not properly handled by the relocation code. - __ movptr(cardtable, (intptr_t)ct->card_table()->byte_map_base()); - __ addptr(card_addr, cardtable); +void G1BarrierSetAssembler::g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register thread, + Register tmp, + G1PreBarrierStubC2* stub) { +#ifdef _LP64 + assert(thread == r15_thread, "must be"); +#endif // _LP64 + assert(pre_val != noreg, "check this code"); + if (obj != noreg) { + assert_different_registers(obj, pre_val, tmp); + } - __ cmpb(Address(card_addr, 0), G1CardTable::g1_young_card_val()); - __ jcc(Assembler::equal, done); + stub->initialize_registers(obj, pre_val, thread, tmp); - __ membar(Assembler::Membar_mask_bits(Assembler::StoreLoad)); - __ cmpb(Address(card_addr, 0), G1CardTable::dirty_card_val()); - __ jcc(Assembler::equal, done); + generate_pre_barrier_fast_path(masm, thread); + // If marking is active (*(mark queue active address) != 0), jump to stub (slow path) + __ jcc(Assembler::notEqual, *stub->entry()); + __ bind(*stub->continuation()); +} - // storing a region crossing, non-null oop, card is clean. - // dirty card and log. +void G1BarrierSetAssembler::generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const { + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + Register obj = stub->obj(); + Register pre_val = stub->pre_val(); + Register thread = stub->thread(); + Register tmp = stub->tmp1(); + assert(stub->tmp2() == noreg, "not needed in this platform"); - __ movb(Address(card_addr, 0), G1CardTable::dirty_card_val()); + __ bind(*stub->entry()); + generate_pre_barrier_slow_path(masm, obj, pre_val, thread, tmp, *stub->continuation(), runtime); - // The code below assumes that buffer index is pointer sized. - STATIC_ASSERT(in_bytes(G1DirtyCardQueue::byte_width_of_index()) == sizeof(intptr_t)); + __ bind(runtime); + generate_c2_barrier_runtime_call(masm, stub, pre_val, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_pre_entry)); + __ jmp(*stub->continuation()); +} - __ movptr(tmp2, queue_index); - __ testptr(tmp2, tmp2); - __ jcc(Assembler::zero, runtime); - __ subptr(tmp2, wordSize); - __ movptr(queue_index, tmp2); - __ addptr(tmp2, buffer); - __ movptr(Address(tmp2, 0), card_addr); - __ jmp(done); +void G1BarrierSetAssembler::g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register thread, + Register tmp, + Register tmp2, + G1PostBarrierStubC2* stub) { +#ifdef _LP64 + assert(thread == r15_thread, "must be"); +#endif // _LP64 - __ bind(runtime); - // save the live input values - RegSet saved = RegSet::of(store_addr NOT_LP64(COMMA thread)); - __ push_set(saved); - __ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry), card_addr, thread); - __ pop_set(saved); + stub->initialize_registers(thread, tmp, tmp2); - __ bind(done); + bool new_val_may_be_null = (stub->barrier_data() & G1C2BarrierPostNotNull) == 0; + generate_post_barrier_fast_path(masm, store_addr, new_val, tmp, tmp2, *stub->continuation(), new_val_may_be_null); + // If card is not young, jump to stub (slow path) + __ jcc(Assembler::notEqual, *stub->entry()); + + __ bind(*stub->continuation()); +} + +void G1BarrierSetAssembler::generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const { + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + Label runtime; + Register thread = stub->thread(); + Register tmp = stub->tmp1(); // tmp holds the card address. + Register tmp2 = stub->tmp2(); + assert(stub->tmp3() == noreg, "not needed in this platform"); + + __ bind(*stub->entry()); + generate_post_barrier_slow_path(masm, thread, tmp, tmp2, *stub->continuation(), runtime); + + __ bind(runtime); + generate_c2_barrier_runtime_call(masm, stub, tmp, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry)); + __ jmp(*stub->continuation()); } +#endif // COMPILER2 + void G1BarrierSetAssembler::oop_store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Address dst, Register val, Register tmp1, Register tmp2, Register tmp3) { bool in_heap = (decorators & IN_HEAP) != 0; diff --git a/src/hotspot/cpu/x86/gc/g1/g1BarrierSetAssembler_x86.hpp b/src/hotspot/cpu/x86/gc/g1/g1BarrierSetAssembler_x86.hpp index a5695f5657a..4dbb1efd885 100644 --- a/src/hotspot/cpu/x86/gc/g1/g1BarrierSetAssembler_x86.hpp +++ b/src/hotspot/cpu/x86/gc/g1/g1BarrierSetAssembler_x86.hpp @@ -32,6 +32,9 @@ class LIR_Assembler; class StubAssembler; class G1PreBarrierStub; class G1PostBarrierStub; +class G1BarrierStubC2; +class G1PreBarrierStubC2; +class G1PostBarrierStubC2; class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { protected: @@ -65,6 +68,26 @@ class G1BarrierSetAssembler: public ModRefBarrierSetAssembler { virtual void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type, Register dst, Address src, Register tmp1, Register tmp_thread); + +#ifdef COMPILER2 + void g1_write_barrier_pre_c2(MacroAssembler* masm, + Register obj, + Register pre_val, + Register thread, + Register tmp, + G1PreBarrierStubC2* c2_stub); + void generate_c2_pre_barrier_stub(MacroAssembler* masm, + G1PreBarrierStubC2* stub) const; + void g1_write_barrier_post_c2(MacroAssembler* masm, + Register store_addr, + Register new_val, + Register thread, + Register tmp, + Register tmp2, + G1PostBarrierStubC2* c2_stub); + void generate_c2_post_barrier_stub(MacroAssembler* masm, + G1PostBarrierStubC2* stub) const; +#endif // COMPILER2 }; #endif // CPU_X86_GC_G1_G1BARRIERSETASSEMBLER_X86_HPP diff --git a/src/hotspot/cpu/x86/gc/g1/g1_x86_64.ad b/src/hotspot/cpu/x86/gc/g1/g1_x86_64.ad new file mode 100644 index 00000000000..8c1559f90f4 --- /dev/null +++ b/src/hotspot/cpu/x86/gc/g1/g1_x86_64.ad @@ -0,0 +1,371 @@ +// +// Copyright (c) 2024, 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. +// + +source_hpp %{ + +#include "gc/g1/c2/g1BarrierSetC2.hpp" +#include "gc/shared/gc_globals.hpp" + +%} + +source %{ + +#include "gc/g1/g1BarrierSetAssembler_x86.hpp" +#include "gc/g1/g1BarrierSetRuntime.hpp" + +static void write_barrier_pre(MacroAssembler* masm, + const MachNode* node, + Register obj, + Register pre_val, + Register tmp, + RegSet preserve = RegSet(), + RegSet no_preserve = RegSet()) { + if (!G1PreBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PreBarrierStubC2* const stub = G1PreBarrierStubC2::create(node); + for (RegSetIterator reg = preserve.begin(); *reg != noreg; ++reg) { + stub->preserve(*reg); + } + for (RegSetIterator reg = no_preserve.begin(); *reg != noreg; ++reg) { + stub->dont_preserve(*reg); + } + g1_asm->g1_write_barrier_pre_c2(masm, obj, pre_val, r15_thread, tmp, stub); +} + +static void write_barrier_post(MacroAssembler* masm, + const MachNode* node, + Register store_addr, + Register new_val, + Register tmp1, + Register tmp2) { + if (!G1PostBarrierStubC2::needs_barrier(node)) { + return; + } + Assembler::InlineSkippedInstructionsCounter skip_counter(masm); + G1BarrierSetAssembler* g1_asm = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + G1PostBarrierStubC2* const stub = G1PostBarrierStubC2::create(node); + g1_asm->g1_write_barrier_post_c2(masm, store_addr, new_val, r15_thread, tmp1, tmp2, stub); +} + +%} + +instruct g1StoreP(memory mem, any_RegP src, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreP mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(125); // XXX + format %{ "movq $mem, $src\t# ptr" %} + ins_encode %{ + // Materialize the store address internally (as opposed to defining 'mem' as + // an indirect memory operand) to reduce the overhead of LCM when processing + // large basic blocks with many stores. Such basic blocks arise, for + // instance, from static initializations of large String arrays. + // The same holds for g1StoreN and g1EncodePAndStoreN. + __ lea($tmp1$$Register, $mem$$Address); + write_barrier_pre(masm, this, + $tmp1$$Register /* obj */, + $tmp2$$Register /* pre_val */, + $tmp3$$Register /* tmp */, + RegSet::of($tmp1$$Register, $src$$Register) /* preserve */); + __ movq(Address($tmp1$$Register, 0), $src$$Register); + write_barrier_post(masm, this, + $tmp1$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp3$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(ialu_mem_reg); +%} + +instruct g1StoreN(memory mem, rRegN src, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem src)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(125); // XXX + format %{ "movl $mem, $src\t# ptr" %} + ins_encode %{ + __ lea($tmp1$$Register, $mem$$Address); + write_barrier_pre(masm, this, + $tmp1$$Register /* obj */, + $tmp2$$Register /* pre_val */, + $tmp3$$Register /* tmp */, + RegSet::of($tmp1$$Register, $src$$Register) /* preserve */); + __ movl(Address($tmp1$$Register, 0), $src$$Register); + if ((barrier_data() & G1C2BarrierPost) != 0) { + __ movl($tmp2$$Register, $src$$Register); + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ decode_heap_oop($tmp2$$Register); + } else { + __ decode_heap_oop_not_null($tmp2$$Register); + } + } + write_barrier_post(masm, this, + $tmp1$$Register /* store_addr */, + $tmp2$$Register /* new_val */, + $tmp3$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(ialu_mem_reg); +%} + +instruct g1EncodePAndStoreN(memory mem, any_RegP src, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_Store()->barrier_data() != 0); + match(Set mem (StoreN mem (EncodeP src))); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + ins_cost(125); // XXX + format %{ "encode_heap_oop $src\n\t" + "movl $mem, $src\t# ptr" %} + ins_encode %{ + __ lea($tmp1$$Register, $mem$$Address); + write_barrier_pre(masm, this, + $tmp1$$Register /* obj */, + $tmp2$$Register /* pre_val */, + $tmp3$$Register /* tmp */, + RegSet::of($tmp1$$Register, $src$$Register) /* preserve */); + __ movq($tmp2$$Register, $src$$Register); + if ((barrier_data() & G1C2BarrierPostNotNull) == 0) { + __ encode_heap_oop($tmp2$$Register); + } else { + __ encode_heap_oop_not_null($tmp2$$Register); + } + __ movl(Address($tmp1$$Register, 0), $tmp2$$Register); + write_barrier_post(masm, this, + $tmp1$$Register /* store_addr */, + $src$$Register /* new_val */, + $tmp3$$Register /* tmp1 */, + $tmp2$$Register /* tmp2 */); + %} + ins_pipe(ialu_mem_reg); +%} + +instruct g1CompareAndExchangeP(indirect mem, rRegP newval, rRegP tmp1, rRegP tmp2, rRegP tmp3, rax_RegP oldval, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set oldval (CompareAndExchangeP mem (Binary oldval newval))); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + format %{ "lock\n\t" + "cmpxchgq $newval, $mem" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + // Pass $oldval to the pre-barrier (instead of loading from $mem), because + // $oldval is the only value that can be overwritten. + // The same holds for g1CompareAndSwapP. + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp3$$Register /* tmp */, + RegSet::of($mem$$Register, $newval$$Register, $oldval$$Register) /* preserve */); + __ movq($tmp1$$Register, $newval$$Register); + __ lock(); + __ cmpxchgq($tmp1$$Register, Address($mem$$Register, 0)); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_cmpxchg); +%} + +instruct g1CompareAndExchangeN(indirect mem, rRegN newval, rRegP tmp1, rRegP tmp2, rRegP tmp3, rax_RegN oldval, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set oldval (CompareAndExchangeN mem (Binary oldval newval))); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + format %{ "lock\n\t" + "cmpxchgq $newval, $mem" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp2$$Register /* pre_val */, + $tmp3$$Register /* tmp */, + RegSet::of($mem$$Register, $newval$$Register, $oldval$$Register) /* preserve */); + __ movl($tmp1$$Register, $newval$$Register); + __ lock(); + __ cmpxchgl($tmp1$$Register, Address($mem$$Register, 0)); + __ decode_heap_oop($tmp1$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_cmpxchg); +%} + +instruct g1CompareAndSwapP(rRegI res, indirect mem, rRegP newval, rRegP tmp1, rRegP tmp2, rRegP tmp3, rax_RegP oldval, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapP mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapP mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL oldval, KILL cr); + format %{ "lock\n\t" + "cmpxchgq $newval, $mem\n\t" + "sete $res\n\t" + "movzbl $res, $res" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $oldval$$Register /* pre_val */, + $tmp3$$Register /* tmp */, + RegSet::of($mem$$Register, $newval$$Register, $oldval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ movq($tmp1$$Register, $newval$$Register); + __ lock(); + __ cmpxchgq($tmp1$$Register, Address($mem$$Register, 0)); + __ setb(Assembler::equal, $res$$Register); + __ movzbl($res$$Register, $res$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_cmpxchg); +%} + +instruct g1CompareAndSwapN(rRegI res, indirect mem, rRegN newval, rRegP tmp1, rRegP tmp2, rRegP tmp3, rax_RegN oldval, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set res (CompareAndSwapN mem (Binary oldval newval))); + match(Set res (WeakCompareAndSwapN mem (Binary oldval newval))); + effect(TEMP res, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL oldval, KILL cr); + format %{ "lock\n\t" + "cmpxchgq $newval, $mem\n\t" + "sete $res\n\t" + "movzbl $res, $res" %} + ins_encode %{ + assert_different_registers($oldval$$Register, $mem$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp2$$Register /* pre_val */, + $tmp3$$Register /* tmp */, + RegSet::of($mem$$Register, $newval$$Register, $oldval$$Register) /* preserve */, + RegSet::of($res$$Register) /* no_preserve */); + __ movl($tmp1$$Register, $newval$$Register); + __ lock(); + __ cmpxchgl($tmp1$$Register, Address($mem$$Register, 0)); + __ setb(Assembler::equal, $res$$Register); + __ movzbl($res$$Register, $res$$Register); + __ decode_heap_oop($tmp1$$Register); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_cmpxchg); +%} + +instruct g1GetAndSetP(indirect mem, rRegP newval, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set newval (GetAndSetP mem newval)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + format %{ "xchgq $newval, $mem" %} + ins_encode %{ + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp2$$Register /* pre_val */, + $tmp3$$Register /* tmp */, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */); + __ movq($tmp1$$Register, $newval$$Register); + __ xchgq($newval$$Register, Address($mem$$Register, 0)); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_cmpxchg); +%} + +instruct g1GetAndSetN(indirect mem, rRegN newval, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_LoadStore()->barrier_data() != 0); + match(Set newval (GetAndSetN mem newval)); + effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr); + format %{ "xchgq $newval, $mem" %} + ins_encode %{ + assert_different_registers($mem$$Register, $newval$$Register); + write_barrier_pre(masm, this, + $mem$$Register /* obj */, + $tmp2$$Register /* pre_val */, + $tmp3$$Register /* tmp */, + RegSet::of($mem$$Register, $newval$$Register) /* preserve */); + __ movl($tmp1$$Register, $newval$$Register); + __ decode_heap_oop($tmp1$$Register); + __ xchgl($newval$$Register, Address($mem$$Register, 0)); + write_barrier_post(masm, this, + $mem$$Register /* store_addr */, + $tmp1$$Register /* new_val */, + $tmp2$$Register /* tmp1 */, + $tmp3$$Register /* tmp2 */); + %} + ins_pipe(pipe_cmpxchg); +%} + +instruct g1LoadP(rRegP dst, memory mem, rRegP tmp, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadP mem)); + effect(TEMP dst, TEMP tmp, KILL cr); + ins_cost(125); // XXX + format %{ "movq $dst, $mem\t# ptr" %} + ins_encode %{ + __ movq($dst$$Register, $mem$$Address); + write_barrier_pre(masm, this, + noreg /* obj */, + $dst$$Register /* pre_val */, + $tmp$$Register /* tmp */); + %} + ins_pipe(ialu_reg_mem); // XXX +%} + +instruct g1LoadN(rRegN dst, memory mem, rRegP tmp1, rRegP tmp2, rFlagsReg cr) +%{ + predicate(UseG1GC && n->as_Load()->barrier_data() != 0); + match(Set dst (LoadN mem)); + effect(TEMP dst, TEMP tmp1, TEMP tmp2, KILL cr); + ins_cost(125); // XXX + format %{ "movl $dst, $mem\t# compressed ptr" %} + ins_encode %{ + __ movl($dst$$Register, $mem$$Address); + __ movl($tmp1$$Register, $dst$$Register); + __ decode_heap_oop($tmp1$$Register); + write_barrier_pre(masm, this, + noreg /* obj */, + $tmp1$$Register /* pre_val */, + $tmp2$$Register /* tmp */); + %} + ins_pipe(ialu_reg_mem); // XXX +%} diff --git a/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp b/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp index 47078dff907..a7682fe0c38 100644 --- a/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp +++ b/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp @@ -163,12 +163,12 @@ void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, Dec assert(dst == rsi, "expected"); assert(count == rdx, "expected"); if (UseCompressedOops) { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_narrow_oop_entry), + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_narrow_oop), src, dst, count); } else #endif { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_oop_entry), + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::arraycopy_barrier_oop), src, dst, count); } @@ -296,9 +296,9 @@ void ShenandoahBarrierSetAssembler::satb_write_barrier_pre(MacroAssembler* masm, __ push(thread); __ push(pre_val); #endif - __ MacroAssembler::call_VM_leaf_base(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), 2); + __ MacroAssembler::call_VM_leaf_base(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), 2); } else { - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), LP64_ONLY(c_rarg0) NOT_LP64(pre_val), thread); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), LP64_ONLY(c_rarg0) NOT_LP64(pre_val), thread); } NOT_LP64( __ pop(thread); ) @@ -925,7 +925,7 @@ void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAss // load the pre-value __ load_parameter(0, rcx); - __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), rcx, thread); + __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), rcx, thread); __ restore_live_registers(true); diff --git a/src/hotspot/cpu/x86/macroAssembler_x86_md5.cpp b/src/hotspot/cpu/x86/macroAssembler_x86_md5.cpp index 439c17b10d3..09d379a4296 100644 --- a/src/hotspot/cpu/x86/macroAssembler_x86_md5.cpp +++ b/src/hotspot/cpu/x86/macroAssembler_x86_md5.cpp @@ -81,8 +81,8 @@ void MacroAssembler::fast_md5(Register buf, Address state, Address ofs, Address notl(rsi); \ andl(rdi, r2); \ andl(rsi, r3); \ - orl(rsi, rdi); \ addl(r1, rsi); \ + addl(r1, rdi); \ roll(r1, s); \ addl(r1, r2); diff --git a/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp b/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp index 4bd91f640fc..174e2e02779 100644 --- a/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp +++ b/src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp @@ -2674,7 +2674,7 @@ void SharedRuntime::generate_deopt_blob() { int reexecute_offset = __ pc() - start; #if INCLUDE_JVMCI && !defined(COMPILER1) - if (EnableJVMCI && UseJVMCICompiler) { + if (UseJVMCICompiler) { // JVMCI does not use this kind of deoptimization __ should_not_reach_here(); } diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64.hpp b/src/hotspot/cpu/x86/stubGenerator_x86_64.hpp index 0a81da4f7c9..71777fbfffe 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_64.hpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64.hpp @@ -376,11 +376,22 @@ class StubGenerator: public StubCodeGenerator { void roundDec(XMMRegister key, int rnum); void lastroundDec(XMMRegister key, int rnum); void gfmul_avx512(XMMRegister ghash, XMMRegister hkey); - void generateHtbl_48_block_zmm(Register htbl, Register avx512_subkeyHtbl, Register rscratch); - void ghash16_encrypt16_parallel(Register key, Register subkeyHtbl, XMMRegister ctr_blockx, - XMMRegister aad_hashx, Register in, Register out, Register data, Register pos, bool reduction, - XMMRegister addmask, bool no_ghash_input, Register rounds, Register ghash_pos, - bool final_reduction, int index, XMMRegister counter_inc_mask); + void ghash16_encrypt_parallel16_avx512(Register in, Register out, Register ct, Register pos, Register avx512_subkeyHtbl, + Register CTR_CHECK, Register NROUNDS, Register key, XMMRegister CTR, XMMRegister GHASH, + XMMRegister ADDBE_4x4, XMMRegister ADDBE_1234, XMMRegister ADD_1234, XMMRegister SHUF_MASK, + bool hk_broadcast, bool is_hash_start, bool do_hash_reduction, bool do_hash_hxor, + bool no_ghash_in, int ghashin_offset, int aesout_offset, int hashkey_offset); + void generateHtbl_32_blocks_avx512(Register htbl, Register avx512_htbl); + void initial_blocks_16_avx512(Register in, Register out, Register ct, Register pos, Register key, Register avx512_subkeyHtbl, + Register CTR_CHECK, Register rounds, XMMRegister CTR, XMMRegister GHASH, XMMRegister ADDBE_4x4, + XMMRegister ADDBE_1234, XMMRegister ADD_1234, XMMRegister SHUF_MASK, int stack_offset); + void gcm_enc_dec_last_avx512(Register len, Register in, Register pos, XMMRegister HASH, XMMRegister SHUFM, Register subkeyHtbl, + int ghashin_offset, int hashkey_offset, bool start_ghash, bool do_reduction); + void ghash16_avx512(bool start_ghash, bool do_reduction, bool uload_shuffle, bool hk_broadcast, bool do_hxor, + Register in, Register pos, Register subkeyHtbl, XMMRegister HASH, XMMRegister SHUFM, int in_offset, + int in_disp, int displacement, int hashkey_offset); + void aesgcm_avx512(Register in, Register len, Register ct, Register out, Register key, + Register state, Register subkeyHtbl, Register avx512_subkeyHtbl, Register counter); // AVX2 AES-GCM related functions void initial_blocks_avx2(XMMRegister ctr, Register rounds, Register key, Register len, Register in, Register out, Register ct, XMMRegister aad_hashx, Register pos); diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64_aes.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_64_aes.cpp index 9744169498c..f14d368c376 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_64_aes.cpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64_aes.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2019, 2023, Intel Corporation. All rights reserved. +* Copyright (c) 2019, 2024, Intel Corporation. All rights reserved. * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -172,6 +172,38 @@ static address ghash_polynomial_two_one_addr() { return (address)GHASH_POLYNOMIAL_TWO_ONE; } +// This mask is used for incrementing counter value +ATTRIBUTE_ALIGNED(64) static const uint64_t COUNTER_MASK_ADDBE_4444[] = { + 0x0000000000000000ULL, 0x0400000000000000ULL, + 0x0000000000000000ULL, 0x0400000000000000ULL, + 0x0000000000000000ULL, 0x0400000000000000ULL, + 0x0000000000000000ULL, 0x0400000000000000ULL, +}; +static address counter_mask_addbe_4444_addr() { + return (address)COUNTER_MASK_ADDBE_4444; +} + +// This mask is used for incrementing counter value +ATTRIBUTE_ALIGNED(64) static const uint64_t COUNTER_MASK_ADDBE_1234[] = { + 0x0000000000000000ULL, 0x0100000000000000ULL, + 0x0000000000000000ULL, 0x0200000000000000ULL, + 0x0000000000000000ULL, 0x0300000000000000ULL, + 0x0000000000000000ULL, 0x0400000000000000ULL, +}; +static address counter_mask_addbe_1234_addr() { + return (address)COUNTER_MASK_ADDBE_1234; +} + +// This mask is used for incrementing counter value +ATTRIBUTE_ALIGNED(64) static const uint64_t COUNTER_MASK_ADD_1234[] = { + 0x0000000000000001ULL, 0x0000000000000000ULL, + 0x0000000000000002ULL, 0x0000000000000000ULL, + 0x0000000000000003ULL, 0x0000000000000000ULL, + 0x0000000000000004ULL, 0x0000000000000000ULL, +}; +static address counter_mask_add_1234_addr() { + return (address)COUNTER_MASK_ADD_1234; +} // AES intrinsic stubs @@ -209,10 +241,10 @@ void StubGenerator::generate_aes_stubs() { // len = rdx (c_rarg1) | rdi (c_rarg1) // ct = r8 (c_rarg2) | rdx (c_rarg2) // out = r9 (c_rarg3) | rcx (c_rarg3) -// key = r10 | r8 (c_rarg4) -// state = r13 | r9 (c_rarg5) -// subkeyHtbl = r14 | r11 -// counter = rsi | r12 +// key = rsi | r8 (c_rarg4) +// state = rdi | r9 (c_rarg5) +// subkeyHtbl = r10 | r10 +// counter = r11 | r11 // // Output: // rax - number of processed bytes @@ -230,31 +262,31 @@ address StubGenerator::generate_galoisCounterMode_AESCrypt() { const Register key = c_rarg4; const Register state = c_rarg5; const Address subkeyH_mem(rbp, 2 * wordSize); - const Register subkeyHtbl = r11; - const Register avx512_subkeyHtbl = r13; + const Register subkeyHtbl = r10; + const Register avx512_subkeyHtbl = r12; const Address counter_mem(rbp, 3 * wordSize); - const Register counter = r12; + const Register counter = r11; #else const Address key_mem(rbp, 6 * wordSize); - const Register key = r10; + const Register key = rsi; const Address state_mem(rbp, 7 * wordSize); - const Register state = r13; + const Register state = rdi; const Address subkeyH_mem(rbp, 8 * wordSize); - const Register subkeyHtbl = r14; + const Register subkeyHtbl = r10; const Register avx512_subkeyHtbl = r12; const Address counter_mem(rbp, 9 * wordSize); - const Register counter = rsi; + const Register counter = r11; #endif __ enter(); // Save state before entering routine - __ push(r12); - __ push(r13); - __ push(r14); - __ push(r15); - __ push(rbx); + __ push(r12);//holds pointer to avx512_subkeyHtbl + __ push(r14);//holds CTR_CHECK value to check for overflow + __ push(r15);//holds number of rounds + __ push(rbx);//scratch register #ifdef _WIN64 // on win64, fill len_reg from stack position __ push(rsi); + __ push(rdi); __ movptr(key, key_mem); __ movptr(state, state_mem); #endif @@ -262,24 +294,24 @@ address StubGenerator::generate_galoisCounterMode_AESCrypt() { __ movptr(counter, counter_mem); // Align stack __ andq(rsp, -64); - __ subptr(rsp, 96 * longSize); // Create space on the stack for htbl entries + __ subptr(rsp, 200 * longSize); // Create space on the stack for 64 htbl entries and 8 zmm AES entries __ movptr(avx512_subkeyHtbl, rsp); - aesgcm_encrypt(in, len, ct, out, key, state, subkeyHtbl, avx512_subkeyHtbl, counter); + aesgcm_avx512(in, len, ct, out, key, state, subkeyHtbl, avx512_subkeyHtbl, counter); __ vzeroupper(); // Restore state before leaving routine #ifdef _WIN64 __ lea(rsp, Address(rbp, -6 * wordSize)); + __ pop(rdi); __ pop(rsi); #else - __ lea(rsp, Address(rbp, -5 * wordSize)); + __ lea(rsp, Address(rbp, -4 * wordSize)); #endif __ pop(rbx); __ pop(r15); __ pop(r14); - __ pop(r13); __ pop(r12); __ leave(); // required for proper stackwalking of RuntimeStub frame @@ -2708,87 +2740,100 @@ void StubGenerator::gfmul_avx512(XMMRegister GH, XMMRegister HK) { __ vpternlogq(GH, 0x96, TMP1, TMP2, Assembler::AVX_512bit); } -void StubGenerator::generateHtbl_48_block_zmm(Register htbl, Register avx512_htbl, Register rscratch) { +// Holds 64 Htbl entries, 32 HKey and 32 HkKey (derived from HKey) +void StubGenerator::generateHtbl_32_blocks_avx512(Register htbl, Register avx512_htbl) { const XMMRegister HK = xmm6; - const XMMRegister ZT5 = xmm4; - const XMMRegister ZT7 = xmm7; - const XMMRegister ZT8 = xmm8; - - Label GFMUL_AVX512; + const XMMRegister ZT1 = xmm0, ZT2 = xmm1, ZT3 = xmm2, ZT4 = xmm3; + const XMMRegister ZT5 = xmm4, ZT6 = xmm5, ZT7 = xmm7, ZT8 = xmm8; + const XMMRegister ZT10 = xmm10, ZT11 = xmm11, ZT12 = xmm12; __ movdqu(HK, Address(htbl, 0)); - __ movdqu(xmm10, ExternalAddress(ghash_long_swap_mask_addr()), rscratch); - __ vpshufb(HK, HK, xmm10, Assembler::AVX_128bit); - - __ movdqu(xmm11, ExternalAddress(ghash_polynomial_addr()), rscratch); - __ movdqu(xmm12, ExternalAddress(ghash_polynomial_two_one_addr()), rscratch); + __ movdqu(ZT10, ExternalAddress(ghash_long_swap_mask_addr()), r15); + __ vpshufb(HK, HK, ZT10, Assembler::AVX_128bit); + __ movdqu(ZT11, ExternalAddress(ghash_polynomial_addr()), r15); + __ movdqu(ZT12, ExternalAddress(ghash_polynomial_two_one_addr()), r15); // Compute H ^ 2 from the input subkeyH - __ movdqu(xmm2, xmm6); - __ vpsllq(xmm6, xmm6, 1, Assembler::AVX_128bit); - __ vpsrlq(xmm2, xmm2, 63, Assembler::AVX_128bit); - __ movdqu(xmm1, xmm2); - __ vpslldq(xmm2, xmm2, 8, Assembler::AVX_128bit); - __ vpsrldq(xmm1, xmm1, 8, Assembler::AVX_128bit); - __ vpor(xmm6, xmm6, xmm2, Assembler::AVX_128bit); + __ movdqu(ZT3, HK); + __ vpsllq(HK, HK, 1, Assembler::AVX_128bit); + __ vpsrlq(ZT3, ZT3, 63, Assembler::AVX_128bit); + __ movdqu(ZT2, ZT3); + __ vpslldq(ZT3, ZT3, 8, Assembler::AVX_128bit); + __ vpsrldq(ZT2, ZT2, 8, Assembler::AVX_128bit); + __ vpor(HK, HK, ZT3, Assembler::AVX_128bit); + __ vpshufd(ZT3, ZT2, 0x24, Assembler::AVX_128bit); + __ vpcmpeqd(ZT3, ZT3, ZT12, Assembler::AVX_128bit); + __ vpand(ZT3, ZT3, ZT11, Assembler::AVX_128bit); + __ vpxor(HK, HK, ZT3, Assembler::AVX_128bit); + __ movdqu(Address(avx512_htbl, 16 * 31), HK); // H ^ 2 - __ vpshufd(xmm2, xmm1, 0x24, Assembler::AVX_128bit); - __ vpcmpeqd(xmm2, xmm2, xmm12, Assembler::AVX_128bit); - __ vpand(xmm2, xmm2, xmm11, Assembler::AVX_128bit); - __ vpxor(xmm6, xmm6, xmm2, Assembler::AVX_128bit); - __ movdqu(Address(avx512_htbl, 16 * 47), xmm6); // H ^ 2 - // Compute the remaining three powers of H using XMM registers and all following powers using ZMM __ movdqu(ZT5, HK); - __ vinserti32x4(ZT7, ZT7, HK, 3); + __ evinserti64x2(ZT7, ZT7, HK, 3, Assembler::AVX_512bit); + //calculate HashKey ^ 2 << 1 mod poly gfmul_avx512(ZT5, HK); - __ movdqu(Address(avx512_htbl, 16 * 46), ZT5); // H ^ 2 * 2 - __ vinserti32x4(ZT7, ZT7, ZT5, 2); + __ movdqu(Address(avx512_htbl, 16 * 30), ZT5); + __ evinserti64x2(ZT7, ZT7, ZT5, 2, Assembler::AVX_512bit); + //calculate HashKey ^ 3 << 1 mod poly gfmul_avx512(ZT5, HK); - __ movdqu(Address(avx512_htbl, 16 * 45), ZT5); // H ^ 2 * 3 - __ vinserti32x4(ZT7, ZT7, ZT5, 1); + __ movdqu(Address(avx512_htbl, 16 * 29), ZT5); + __ evinserti64x2(ZT7, ZT7, ZT5, 1, Assembler::AVX_512bit); + //calculate HashKey ^ 4 << 1 mod poly gfmul_avx512(ZT5, HK); - __ movdqu(Address(avx512_htbl, 16 * 44), ZT5); // H ^ 2 * 4 - __ vinserti32x4(ZT7, ZT7, ZT5, 0); - - __ evshufi64x2(ZT5, ZT5, ZT5, 0x00, Assembler::AVX_512bit); - __ evmovdquq(ZT8, ZT7, Assembler::AVX_512bit); - gfmul_avx512(ZT7, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 40), ZT7, Assembler::AVX_512bit); - __ evshufi64x2(ZT5, ZT7, ZT7, 0x00, Assembler::AVX_512bit); - gfmul_avx512(ZT8, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 36), ZT8, Assembler::AVX_512bit); + __ movdqu(Address(avx512_htbl, 16 * 28), ZT5); + __ evinserti64x2(ZT7, ZT7, ZT5, 0, Assembler::AVX_512bit); + // ZT5 amd ZT7 to be cleared(hash key) + //calculate HashKeyK = HashKey x POLY + __ evmovdquq(xmm11, ExternalAddress(ghash_polynomial_addr()), Assembler::AVX_512bit, r15); + __ evpclmulqdq(ZT1, ZT7, xmm11, 0x10, Assembler::AVX_512bit); + __ vpshufd(ZT2, ZT7, 78, Assembler::AVX_512bit); + __ evpxorq(ZT1, ZT1, ZT2, Assembler::AVX_512bit); + __ evmovdquq(Address(avx512_htbl, 16 * 60), ZT1, Assembler::AVX_512bit); + //**ZT1 amd ZT2 to be cleared(hash key) + + //switch to 4x128 - bit computations now + __ evshufi64x2(ZT5, ZT5, ZT5, 0x00, Assembler::AVX_512bit); //;; broadcast HashKey ^ 4 across all ZT5 + __ evmovdquq(ZT8, ZT7, Assembler::AVX_512bit);//; save HashKey ^ 4 to HashKey ^ 1 in ZT8 + //**ZT8 to be cleared(hash key) + + //calculate HashKey ^ 5 << 1 mod poly, HashKey ^ 6 << 1 mod poly, ... HashKey ^ 8 << 1 mod poly gfmul_avx512(ZT7, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 32), ZT7, Assembler::AVX_512bit); - gfmul_avx512(ZT8, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 28), ZT8, Assembler::AVX_512bit); - gfmul_avx512(ZT7, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 24), ZT7, Assembler::AVX_512bit); - gfmul_avx512(ZT8, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 20), ZT8, Assembler::AVX_512bit); - gfmul_avx512(ZT7, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 16), ZT7, Assembler::AVX_512bit); - gfmul_avx512(ZT8, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 12), ZT8, Assembler::AVX_512bit); - gfmul_avx512(ZT7, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 8), ZT7, Assembler::AVX_512bit); - gfmul_avx512(ZT8, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 4), ZT8, Assembler::AVX_512bit); - gfmul_avx512(ZT7, ZT5); - __ evmovdquq(Address(avx512_htbl, 16 * 0), ZT7, Assembler::AVX_512bit); - __ ret(0); -} - -#define vclmul_reduce(out, poly, hi128, lo128, tmp0, tmp1) \ -__ evpclmulqdq(tmp0, poly, lo128, 0x01, Assembler::AVX_512bit); \ -__ vpslldq(tmp0, tmp0, 8, Assembler::AVX_512bit); \ -__ evpxorq(tmp0, lo128, tmp0, Assembler::AVX_512bit); \ -__ evpclmulqdq(tmp1, poly, tmp0, 0x00, Assembler::AVX_512bit); \ -__ vpsrldq(tmp1, tmp1, 4, Assembler::AVX_512bit); \ -__ evpclmulqdq(out, poly, tmp0, 0x10, Assembler::AVX_512bit); \ -__ vpslldq(out, out, 4, Assembler::AVX_512bit); \ -__ vpternlogq(out, 0x96, tmp1, hi128, Assembler::AVX_512bit); \ + __ evmovdquq(Address(avx512_htbl, 16 * 24), ZT7, Assembler::AVX_512bit);//; HashKey ^ 8 to HashKey ^ 5 in ZT7 now + + //calculate HashKeyX = HashKey x POLY + __ evpclmulqdq(ZT1, ZT7, xmm11, 0x10, Assembler::AVX_512bit); + __ vpshufd(ZT2, ZT7, 78, Assembler::AVX_512bit); + __ evpxorq(ZT1, ZT1, ZT2, Assembler::AVX_512bit); + __ evmovdquq(Address(avx512_htbl, 16 * 56), ZT1, Assembler::AVX_512bit); + + __ evshufi64x2(ZT5, ZT7, ZT7, 0x00, Assembler::AVX_512bit);//;; broadcast HashKey ^ 8 across all ZT5 + + for (int i = 20, j = 52; i > 0;) { + gfmul_avx512(ZT8, ZT5); + __ evmovdquq(Address(avx512_htbl, 16 * i), ZT8, Assembler::AVX_512bit); + //calculate HashKeyK = HashKey x POLY + __ evpclmulqdq(ZT1, ZT8, xmm11, 0x10, Assembler::AVX_512bit); + __ vpshufd(ZT2, ZT8, 78, Assembler::AVX_512bit); + __ evpxorq(ZT1, ZT1, ZT2, Assembler::AVX_512bit); + __ evmovdquq(Address(avx512_htbl, 16 * j), ZT1, Assembler::AVX_512bit); + + i -= 4; + j -= 4; + //compute HashKey ^ (8 + n), HashKey ^ (7 + n), ... HashKey ^ (5 + n) + gfmul_avx512(ZT7, ZT5); + __ evmovdquq(Address(avx512_htbl, 16 * i), ZT7, Assembler::AVX_512bit); + + //calculate HashKeyK = HashKey x POLY + __ evpclmulqdq(ZT1, ZT7, xmm11, 0x10, Assembler::AVX_512bit); + __ vpshufd(ZT2, ZT7, 78, Assembler::AVX_512bit); + __ evpxorq(ZT1, ZT1, ZT2, Assembler::AVX_512bit); + __ evmovdquq(Address(avx512_htbl, 16 * j), ZT1, Assembler::AVX_512bit); + + i -= 4; + j -= 4; + } + } #define vhpxori4x128(reg, tmp) \ __ vextracti64x4(tmp, reg, 1); \ @@ -2820,21 +2865,17 @@ __ evmovdquq(dst2, Address(src, position, Address::times_1, 1 * 64), Assembler:: __ evmovdquq(dst3, Address(src, position, Address::times_1, 2 * 64), Assembler::AVX_512bit); \ __ evmovdquq(dst4, Address(src, position, Address::times_1, 3 * 64), Assembler::AVX_512bit); \ -#define carrylessMultiply(dst00, dst01, dst10, dst11, ghdata, hkey) \ -__ evpclmulqdq(dst00, ghdata, hkey, 0x00, Assembler::AVX_512bit); \ -__ evpclmulqdq(dst01, ghdata, hkey, 0x01, Assembler::AVX_512bit); \ -__ evpclmulqdq(dst10, ghdata, hkey, 0x10, Assembler::AVX_512bit); \ -__ evpclmulqdq(dst11, ghdata, hkey, 0x11, Assembler::AVX_512bit); \ - -#define shuffleExorRnd1Key(dst0, dst1, dst2, dst3, shufmask, rndkey) \ -__ vpshufb(dst0, dst0, shufmask, Assembler::AVX_512bit); \ -__ evpxorq(dst0, dst0, rndkey, Assembler::AVX_512bit); \ -__ vpshufb(dst1, dst1, shufmask, Assembler::AVX_512bit); \ -__ evpxorq(dst1, dst1, rndkey, Assembler::AVX_512bit); \ -__ vpshufb(dst2, dst2, shufmask, Assembler::AVX_512bit); \ -__ evpxorq(dst2, dst2, rndkey, Assembler::AVX_512bit); \ -__ vpshufb(dst3, dst3, shufmask, Assembler::AVX_512bit); \ -__ evpxorq(dst3, dst3, rndkey, Assembler::AVX_512bit); \ +#define carrylessMultiply(dst00, dst01, dst10, dst11, ghdata, hkey2, hkey1) \ +__ evpclmulqdq(dst00, ghdata, hkey2, 0x00, Assembler::AVX_512bit); \ +__ evpclmulqdq(dst01, ghdata, hkey2, 0x10, Assembler::AVX_512bit); \ +__ evpclmulqdq(dst10, ghdata, hkey1, 0x01, Assembler::AVX_512bit); \ +__ evpclmulqdq(dst11, ghdata, hkey1, 0x11, Assembler::AVX_512bit); \ + +#define shuffle(dst0, dst1, dst2, dst3, src0, src1, src2, src3, shufmask) \ +__ vpshufb(dst0, src0, shufmask, Assembler::AVX_512bit); \ +__ vpshufb(dst1, src1, shufmask, Assembler::AVX_512bit); \ +__ vpshufb(dst2, src2, shufmask, Assembler::AVX_512bit); \ +__ vpshufb(dst3, src3, shufmask, Assembler::AVX_512bit); \ #define xorBeforeStore(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \ __ evpxorq(dst0, dst0, src0, Assembler::AVX_512bit); \ @@ -2848,211 +2889,462 @@ __ vpternlogq(dst1, 0x96, src12, src13, Assembler::AVX_512bit); \ __ vpternlogq(dst2, 0x96, src22, src23, Assembler::AVX_512bit); \ __ vpternlogq(dst3, 0x96, src32, src33, Assembler::AVX_512bit); \ -void StubGenerator::ghash16_encrypt16_parallel(Register key, Register subkeyHtbl, XMMRegister ctr_blockx, XMMRegister aad_hashx, - Register in, Register out, Register data, Register pos, bool first_time_reduction, XMMRegister addmask, bool ghash_input, Register rounds, - Register ghash_pos, bool final_reduction, int i, XMMRegister counter_inc_mask) { - Label AES_192, AES_256, LAST_AES_RND; +//schoolbook multiply of 16 blocks(8 x 16 bytes) +//it is assumed that data read is already shuffledand +void StubGenerator::ghash16_avx512(bool start_ghash, bool do_reduction, bool uload_shuffle, bool hk_broadcast, bool do_hxor, + Register in, Register pos, Register subkeyHtbl, XMMRegister HASH, XMMRegister SHUFM, int in_offset, + int in_disp, int displacement, int hashkey_offset) { const XMMRegister ZTMP0 = xmm0; const XMMRegister ZTMP1 = xmm3; const XMMRegister ZTMP2 = xmm4; const XMMRegister ZTMP3 = xmm5; + const XMMRegister ZTMP4 = xmm6; const XMMRegister ZTMP5 = xmm7; const XMMRegister ZTMP6 = xmm10; const XMMRegister ZTMP7 = xmm11; const XMMRegister ZTMP8 = xmm12; const XMMRegister ZTMP9 = xmm13; - const XMMRegister ZTMP10 = xmm15; - const XMMRegister ZTMP11 = xmm16; - const XMMRegister ZTMP12 = xmm17; + const XMMRegister ZTMPA = xmm26; + const XMMRegister ZTMPB = xmm23; + const XMMRegister GH = xmm24; + const XMMRegister GL = xmm25; + const int hkey_gap = 16 * 32; + + if (uload_shuffle) { + __ evmovdquq(ZTMP9, Address(subkeyHtbl, in_offset * 16 + in_disp), Assembler::AVX_512bit); + __ vpshufb(ZTMP9, ZTMP9, SHUFM, Assembler::AVX_512bit); + } else { + __ evmovdquq(ZTMP9, Address(subkeyHtbl, in_offset * 16 + in_disp), Assembler::AVX_512bit); + } - const XMMRegister ZTMP13 = xmm19; - const XMMRegister ZTMP14 = xmm20; - const XMMRegister ZTMP15 = xmm21; - const XMMRegister ZTMP16 = xmm30; - const XMMRegister ZTMP17 = xmm31; - const XMMRegister ZTMP18 = xmm1; - const XMMRegister ZTMP19 = xmm2; - const XMMRegister ZTMP20 = xmm8; - const XMMRegister ZTMP21 = xmm22; - const XMMRegister ZTMP22 = xmm23; + if (start_ghash) { + __ evpxorq(ZTMP9, ZTMP9, HASH, Assembler::AVX_512bit); + } + if (hk_broadcast) { + __ evbroadcastf64x2(ZTMP8, Address(subkeyHtbl, hashkey_offset + displacement + 0 * 64), Assembler::AVX_512bit); + __ evbroadcastf64x2(ZTMPA, Address(subkeyHtbl, hashkey_offset + displacement + hkey_gap + 0 * 64), Assembler::AVX_512bit); + } else { + __ evmovdquq(ZTMP8, Address(subkeyHtbl, hashkey_offset + displacement + 0 * 64), Assembler::AVX_512bit); + __ evmovdquq(ZTMPA, Address(subkeyHtbl, hashkey_offset + displacement + hkey_gap + 0 * 64), Assembler::AVX_512bit); + } + + carrylessMultiply(ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP9, ZTMPA, ZTMP8); + + //ghash blocks 4 - 7 + if (uload_shuffle) { + __ evmovdquq(ZTMP9, Address(subkeyHtbl, in_offset * 16 + in_disp + 64), Assembler::AVX_512bit); + __ vpshufb(ZTMP9, ZTMP9, SHUFM, Assembler::AVX_512bit); + } else { + __ evmovdquq(ZTMP9, Address(subkeyHtbl, in_offset * 16 + in_disp + 64), Assembler::AVX_512bit); + } + + if (hk_broadcast) { + __ evbroadcastf64x2(ZTMP8, Address(subkeyHtbl, hashkey_offset + displacement + 1 * 64), Assembler::AVX_512bit);; + __ evbroadcastf64x2(ZTMPA, Address(subkeyHtbl, hashkey_offset + displacement + hkey_gap + 1 * 64), Assembler::AVX_512bit); + } else { + __ evmovdquq(ZTMP8, Address(subkeyHtbl, hashkey_offset + displacement + 1 * 64), Assembler::AVX_512bit); + __ evmovdquq(ZTMPA, Address(subkeyHtbl, hashkey_offset + displacement + hkey_gap + 1 * 64), Assembler::AVX_512bit); + } + + carrylessMultiply(ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP9, ZTMPA, ZTMP8); + + //update sums + if (start_ghash) { + __ evpxorq(GL, ZTMP0, ZTMP2, Assembler::AVX_512bit);//T2 = THL + TLL + __ evpxorq(GH, ZTMP1, ZTMP3, Assembler::AVX_512bit);//T1 = THH + TLH + } else { //mid, end, end_reduce + __ vpternlogq(GL, 0x96, ZTMP0, ZTMP2, Assembler::AVX_512bit);//T2 = THL + TLL + __ vpternlogq(GH, 0x96, ZTMP1, ZTMP3, Assembler::AVX_512bit);//T1 = THH + TLH + } + //ghash blocks 8 - 11 + if (uload_shuffle) { + __ evmovdquq(ZTMP9, Address(subkeyHtbl, in_offset * 16 + in_disp + 128), Assembler::AVX_512bit); + __ vpshufb(ZTMP9, ZTMP9, SHUFM, Assembler::AVX_512bit); + } else { + __ evmovdquq(ZTMP9, Address(subkeyHtbl, in_offset * 16 + in_disp + 128), Assembler::AVX_512bit); + } + if (hk_broadcast) { + __ evbroadcastf64x2(ZTMP8, Address(subkeyHtbl, hashkey_offset + displacement + 2 * 64), Assembler::AVX_512bit); + __ evbroadcastf64x2(ZTMPA, Address(subkeyHtbl, hashkey_offset + displacement + hkey_gap + 2 * 64), Assembler::AVX_512bit); + } else { + __ evmovdquq(ZTMP8, Address(subkeyHtbl, hashkey_offset + displacement + 2 * 64), Assembler::AVX_512bit); + __ evmovdquq(ZTMPA, Address(subkeyHtbl, hashkey_offset + displacement + hkey_gap + 2 * 64), Assembler::AVX_512bit); + } + + carrylessMultiply(ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP9, ZTMPA, ZTMP8); + + //update sums + __ vpternlogq(GL, 0x96, ZTMP6, ZTMP4, Assembler::AVX_512bit);//T2 = THL + TLL + __ vpternlogq(GH, 0x96, ZTMP7, ZTMP5, Assembler::AVX_512bit);//T1 = THH + TLH + //ghash blocks 12 - 15 + if (uload_shuffle) { + __ evmovdquq(ZTMP9, Address(subkeyHtbl, in_offset * 16 + in_disp + 192), Assembler::AVX_512bit); + __ vpshufb(ZTMP9, ZTMP9, SHUFM, Assembler::AVX_512bit); + } else { + __ evmovdquq(ZTMP9, Address(subkeyHtbl, in_offset * 16 + in_disp + 192), Assembler::AVX_512bit); + } + + if (hk_broadcast) { + __ evbroadcastf64x2(ZTMP8, Address(subkeyHtbl, hashkey_offset + displacement + 3 * 64), Assembler::AVX_512bit); + __ evbroadcastf64x2(ZTMPA, Address(subkeyHtbl, hashkey_offset + displacement + hkey_gap + 3 * 64), Assembler::AVX_512bit); + } else { + __ evmovdquq(ZTMP8, Address(subkeyHtbl, hashkey_offset + displacement + 3 * 64), Assembler::AVX_512bit); + __ evmovdquq(ZTMPA, Address(subkeyHtbl, hashkey_offset + displacement + hkey_gap + 3 * 64), Assembler::AVX_512bit); + } + carrylessMultiply(ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP9, ZTMPA, ZTMP8); + + //update sums + xorGHASH(GL, GH, GL, GH, ZTMP0, ZTMP2, ZTMP1, ZTMP3, ZTMP6, ZTMP4, ZTMP7, ZTMP5); + + if (do_reduction) { + //new reduction + __ evmovdquq(ZTMPB, ExternalAddress(ghash_polynomial_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); + __ evpclmulqdq(HASH, GL, ZTMPB, 0x10, Assembler::AVX_512bit); + __ vpshufd(ZTMP0, GL, 78, Assembler::AVX_512bit); + __ vpternlogq(HASH, 0x96, GH, ZTMP0, Assembler::AVX_512bit); + if (do_hxor) { + vhpxori4x128(HASH, ZTMP0); + } + } +} - // Pre increment counters - __ vpaddd(ZTMP0, ctr_blockx, counter_inc_mask, Assembler::AVX_512bit); - __ vpaddd(ZTMP1, ZTMP0, counter_inc_mask, Assembler::AVX_512bit); - __ vpaddd(ZTMP2, ZTMP1, counter_inc_mask, Assembler::AVX_512bit); - __ vpaddd(ZTMP3, ZTMP2, counter_inc_mask, Assembler::AVX_512bit); - // Save counter value - __ evmovdquq(ctr_blockx, ZTMP3, Assembler::AVX_512bit); - - // Reuse ZTMP17 / ZTMP18 for loading AES Keys - // Pre-load AES round keys - ev_load_key(ZTMP17, key, 0, xmm29); - ev_load_key(ZTMP18, key, 1 * 16, xmm29); - - // ZTMP19 & ZTMP20 used for loading hash key - // Pre-load hash key - __ evmovdquq(ZTMP19, Address(subkeyHtbl, i * 64), Assembler::AVX_512bit); - __ evmovdquq(ZTMP20, Address(subkeyHtbl, ++i * 64), Assembler::AVX_512bit); - // Load data for computing ghash - __ evmovdquq(ZTMP21, Address(data, ghash_pos, Address::times_1, 0 * 64), Assembler::AVX_512bit); - __ vpshufb(ZTMP21, ZTMP21, xmm24, Assembler::AVX_512bit); - - // Xor cipher block 0 with input ghash, if available - if (ghash_input) { - __ evpxorq(ZTMP21, ZTMP21, aad_hashx, Assembler::AVX_512bit); +//Stitched GHASH of 16 blocks(with reduction) with encryption of 0 blocks +void StubGenerator::gcm_enc_dec_last_avx512(Register len, Register in, Register pos, XMMRegister HASH, XMMRegister SHUFM, Register subkeyHtbl, + int ghashin_offset, int hashkey_offset, bool start_ghash, bool do_reduction) { + //there is 0 blocks to cipher so there are only 16 blocks for ghash and reduction + ghash16_avx512(start_ghash, do_reduction, false, false, true, in, pos, subkeyHtbl, HASH, SHUFM, ghashin_offset, 0, 0, hashkey_offset); +} + +//Main GCM macro stitching cipher with GHASH +//encrypts 16 blocks at a time +//ghash the 16 previously encrypted ciphertext blocks +void StubGenerator::ghash16_encrypt_parallel16_avx512(Register in, Register out, Register ct, Register pos, Register avx512_subkeyHtbl, + Register CTR_CHECK, Register NROUNDS, Register key, XMMRegister CTR_BE, XMMRegister GHASH_IN, + XMMRegister ADDBE_4x4, XMMRegister ADDBE_1234, XMMRegister ADD_1234, XMMRegister SHFMSK, + bool hk_broadcast, bool is_hash_start, bool do_hash_reduction, bool do_hash_hxor, + bool no_ghash_in, int ghashin_offset, int aesout_offset, int hashkey_offset) { + const XMMRegister B00_03 = xmm0; + const XMMRegister B04_07 = xmm3; + const XMMRegister B08_11 = xmm4; + const XMMRegister B12_15 = xmm5; + const XMMRegister THH1 = xmm6; + const XMMRegister THL1 = xmm7; + const XMMRegister TLH1 = xmm10; + const XMMRegister TLL1 = xmm11, THH2 = xmm12, THL2 = xmm13, TLH2 = xmm15; + const XMMRegister TLL2 = xmm16, THH3 = xmm17, THL3 = xmm19, TLH3 = xmm20; + const XMMRegister TLL3 = xmm21, DATA1 = xmm17, DATA2 = xmm19, DATA3 = xmm20, DATA4 = xmm21; + const XMMRegister AESKEY1 = xmm30, AESKEY2 = xmm31; + const XMMRegister GHKEY1 = xmm1, GHKEY2 = xmm18, GHDAT1 = xmm8, GHDAT2 = xmm22; + const XMMRegister ZT = xmm23, TO_REDUCE_L = xmm25, TO_REDUCE_H = xmm24; + const int hkey_gap = 16 * 32; + + Label blocks_overflow, blocks_ok, skip_shuffle, cont, aes_256, aes_192, last_aes_rnd; + + __ cmpb(CTR_CHECK, (256 - 16)); + __ jcc(Assembler::aboveEqual, blocks_overflow); + __ vpaddd(B00_03, CTR_BE, ADDBE_1234, Assembler::AVX_512bit); + __ vpaddd(B04_07, B00_03, ADDBE_4x4, Assembler::AVX_512bit); + __ vpaddd(B08_11, B04_07, ADDBE_4x4, Assembler::AVX_512bit); + __ vpaddd(B12_15, B08_11, ADDBE_4x4, Assembler::AVX_512bit); + __ jmp(blocks_ok); + __ bind(blocks_overflow); + __ vpshufb(CTR_BE, CTR_BE, SHFMSK, Assembler::AVX_512bit); + __ evmovdquq(B12_15, ExternalAddress(counter_mask_linc4_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); + __ vpaddd(B00_03, CTR_BE, ADD_1234, Assembler::AVX_512bit); + __ vpaddd(B04_07, B00_03, B12_15, Assembler::AVX_512bit); + __ vpaddd(B08_11, B04_07, B12_15, Assembler::AVX_512bit); + __ vpaddd(B12_15, B08_11, B12_15, Assembler::AVX_512bit); + shuffle(B00_03, B04_07, B08_11, B12_15, B00_03, B04_07, B08_11, B12_15, SHFMSK); + + __ bind(blocks_ok); + + //pre - load constants + ev_load_key(AESKEY1, key, 0, rbx); + if (!no_ghash_in) { + __ evpxorq(GHDAT1, GHASH_IN, Address(avx512_subkeyHtbl, 16 * ghashin_offset), Assembler::AVX_512bit); + } else { + __ evmovdquq(GHDAT1, Address(avx512_subkeyHtbl, 16 * ghashin_offset), Assembler::AVX_512bit); + } + + if (hk_broadcast) { + __ evbroadcastf64x2(GHKEY1, Address(avx512_subkeyHtbl, hashkey_offset + 0 * 64), Assembler::AVX_512bit); + __ evbroadcastf64x2(GHKEY2, Address(avx512_subkeyHtbl, hashkey_offset + hkey_gap + 0 * 64), Assembler::AVX_512bit); + } else { + __ evmovdquq(GHKEY1, Address(avx512_subkeyHtbl, hashkey_offset + 0 * 64), Assembler::AVX_512bit); + __ evmovdquq(GHKEY2, Address(avx512_subkeyHtbl, hashkey_offset + hkey_gap + 0 * 64), Assembler::AVX_512bit); + } + + //save counter for the next round + //increment counter overflow check register + __ evshufi64x2(CTR_BE, B12_15, B12_15, 255, Assembler::AVX_512bit); + __ addb(CTR_CHECK, 16); + + //pre - load constants + ev_load_key(AESKEY2, key, 1 * 16, rbx); + __ evmovdquq(GHDAT2, Address(avx512_subkeyHtbl, 16 * (ghashin_offset +4)), Assembler::AVX_512bit); + + //stitch AES rounds with GHASH + //AES round 0 + __ evpxorq(B00_03, B00_03, AESKEY1, Assembler::AVX_512bit); + __ evpxorq(B04_07, B04_07, AESKEY1, Assembler::AVX_512bit); + __ evpxorq(B08_11, B08_11, AESKEY1, Assembler::AVX_512bit); + __ evpxorq(B12_15, B12_15, AESKEY1, Assembler::AVX_512bit); + ev_load_key(AESKEY1, key, 2 * 16, rbx); + + //GHASH 4 blocks(15 to 12) + carrylessMultiply(TLL1, TLH1, THL1, THH1, GHDAT1, GHKEY2, GHKEY1); + + if (hk_broadcast) { + __ evbroadcastf64x2(GHKEY1, Address(avx512_subkeyHtbl, hashkey_offset + 1 * 64), Assembler::AVX_512bit); + __ evbroadcastf64x2(GHKEY2, Address(avx512_subkeyHtbl, hashkey_offset + hkey_gap + 1 * 64), Assembler::AVX_512bit); + } else { + __ evmovdquq(GHKEY1, Address(avx512_subkeyHtbl, hashkey_offset + 1 * 64), Assembler::AVX_512bit); + __ evmovdquq(GHKEY2, Address(avx512_subkeyHtbl, hashkey_offset + hkey_gap + 1 * 64), Assembler::AVX_512bit); + } + + __ evmovdquq(GHDAT1, Address(avx512_subkeyHtbl, 16 * (ghashin_offset + 8)), Assembler::AVX_512bit); + + //AES round 1 + roundEncode(AESKEY2, B00_03, B04_07, B08_11, B12_15); + + ev_load_key(AESKEY2, key, 3 * 16, rbx); + + //GHASH 4 blocks(11 to 8) + carrylessMultiply(TLL2, TLH2, THL2, THH2, GHDAT2, GHKEY2, GHKEY1); + + if (hk_broadcast) { + __ evbroadcastf64x2(GHKEY1, Address(avx512_subkeyHtbl, hashkey_offset + 2 * 64), Assembler::AVX_512bit); + __ evbroadcastf64x2(GHKEY2, Address(avx512_subkeyHtbl, hashkey_offset + hkey_gap + 2 * 64), Assembler::AVX_512bit); + } else { + __ evmovdquq(GHKEY1, Address(avx512_subkeyHtbl, hashkey_offset + 2 * 64 ), Assembler::AVX_512bit); + __ evmovdquq(GHKEY2, Address(avx512_subkeyHtbl, hashkey_offset + hkey_gap + 2 * 64), Assembler::AVX_512bit); } - // Load data for computing ghash - __ evmovdquq(ZTMP22, Address(data, ghash_pos, Address::times_1, 1 * 64), Assembler::AVX_512bit); - __ vpshufb(ZTMP22, ZTMP22, xmm24, Assembler::AVX_512bit); - - // stitch AES rounds with GHASH - // AES round 0, xmm24 has shuffle mask - shuffleExorRnd1Key(ZTMP0, ZTMP1, ZTMP2, ZTMP3, xmm24, ZTMP17); - // Reuse ZTMP17 / ZTMP18 for loading remaining AES Keys - ev_load_key(ZTMP17, key, 2 * 16, xmm29); - // GHASH 4 blocks - carrylessMultiply(ZTMP6, ZTMP7, ZTMP8, ZTMP5, ZTMP21, ZTMP19); - // Load the next hkey and Ghash data - __ evmovdquq(ZTMP19, Address(subkeyHtbl, ++i * 64), Assembler::AVX_512bit); - __ evmovdquq(ZTMP21, Address(data, ghash_pos, Address::times_1, 2 * 64), Assembler::AVX_512bit); - __ vpshufb(ZTMP21, ZTMP21, xmm24, Assembler::AVX_512bit); - - // AES round 1 - roundEncode(ZTMP18, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP18, key, 3 * 16, xmm29); - - // GHASH 4 blocks(11 to 8) - carrylessMultiply(ZTMP10, ZTMP12, ZTMP11, ZTMP9, ZTMP22, ZTMP20); - // Load the next hkey and GDATA - __ evmovdquq(ZTMP20, Address(subkeyHtbl, ++i * 64), Assembler::AVX_512bit); - __ evmovdquq(ZTMP22, Address(data, ghash_pos, Address::times_1, 3 * 64), Assembler::AVX_512bit); - __ vpshufb(ZTMP22, ZTMP22, xmm24, Assembler::AVX_512bit); - - // AES round 2 - roundEncode(ZTMP17, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP17, key, 4 * 16, xmm29); - - // GHASH 4 blocks(7 to 4) - carrylessMultiply(ZTMP14, ZTMP16, ZTMP15, ZTMP13, ZTMP21, ZTMP19); - // AES rounds 3 - roundEncode(ZTMP18, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP18, key, 5 * 16, xmm29); - - // Gather(XOR) GHASH for 12 blocks - xorGHASH(ZTMP5, ZTMP6, ZTMP8, ZTMP7, ZTMP9, ZTMP13, ZTMP10, ZTMP14, ZTMP12, ZTMP16, ZTMP11, ZTMP15); - - // AES rounds 4 - roundEncode(ZTMP17, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP17, key, 6 * 16, xmm29); - - // load plain / cipher text(recycle registers) - loadData(in, pos, ZTMP13, ZTMP14, ZTMP15, ZTMP16); - - // AES rounds 5 - roundEncode(ZTMP18, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP18, key, 7 * 16, xmm29); - // GHASH 4 blocks(3 to 0) - carrylessMultiply(ZTMP10, ZTMP12, ZTMP11, ZTMP9, ZTMP22, ZTMP20); - - // AES round 6 - roundEncode(ZTMP17, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP17, key, 8 * 16, xmm29); - - // gather GHASH in ZTMP6(low) and ZTMP5(high) - if (first_time_reduction) { - __ vpternlogq(ZTMP7, 0x96, ZTMP8, ZTMP12, Assembler::AVX_512bit); - __ evpxorq(xmm25, ZTMP7, ZTMP11, Assembler::AVX_512bit); - __ evpxorq(xmm27, ZTMP5, ZTMP9, Assembler::AVX_512bit); - __ evpxorq(xmm26, ZTMP6, ZTMP10, Assembler::AVX_512bit); - } else if (!first_time_reduction && !final_reduction) { - xorGHASH(ZTMP7, xmm25, xmm27, xmm26, ZTMP8, ZTMP12, ZTMP7, ZTMP11, ZTMP5, ZTMP9, ZTMP6, ZTMP10); + __ evmovdquq(GHDAT2, Address(avx512_subkeyHtbl, 16 * (ghashin_offset + 12)), Assembler::AVX_512bit); + + //AES round 2 + roundEncode(AESKEY1, B00_03, B04_07, B08_11, B12_15); + ev_load_key(AESKEY1, key, 4 * 16, rbx); + + //GHASH 4 blocks(7 to 4) + carrylessMultiply(TLL3, TLH3, THL3, THH3, GHDAT1, GHKEY2, GHKEY1); + + if (hk_broadcast) { + __ evbroadcastf64x2(GHKEY1, Address(avx512_subkeyHtbl, hashkey_offset + 3 * 64), Assembler::AVX_512bit); + __ evbroadcastf64x2(GHKEY2, Address(avx512_subkeyHtbl, hashkey_offset + hkey_gap + 3 * 64), Assembler::AVX_512bit); + } else { + __ evmovdquq(GHKEY1, Address(avx512_subkeyHtbl, hashkey_offset + 3 * 64), Assembler::AVX_512bit); + __ evmovdquq(GHKEY2, Address(avx512_subkeyHtbl, hashkey_offset + hkey_gap + 3 * 64), Assembler::AVX_512bit); } - if (final_reduction) { - // Phase one: Add mid products together - // Also load polynomial constant for reduction - __ vpternlogq(ZTMP7, 0x96, ZTMP8, ZTMP12, Assembler::AVX_512bit); - __ vpternlogq(ZTMP7, 0x96, xmm25, ZTMP11, Assembler::AVX_512bit); - __ vpsrldq(ZTMP11, ZTMP7, 8, Assembler::AVX_512bit); - __ vpslldq(ZTMP7, ZTMP7, 8, Assembler::AVX_512bit); - __ evmovdquq(ZTMP12, ExternalAddress(ghash_polynomial_reduction_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); + //AES rounds 3 + roundEncode(AESKEY2, B00_03, B04_07, B08_11, B12_15); + ev_load_key(AESKEY2, key, 5 * 16, rbx); + + //Gather(XOR) GHASH for 12 blocks + xorGHASH(TLL1, TLH1, THL1, THH1, TLL2, TLL3, TLH2, TLH3, THL2, THL3, THH2, THH3); + + //AES rounds 4 + roundEncode(AESKEY1, B00_03, B04_07, B08_11, B12_15); + ev_load_key(AESKEY1, key, 6 * 16, rbx); + + //load plain / cipher text(recycle GH3xx registers) + loadData(in, pos, DATA1, DATA2, DATA3, DATA4); + + //AES rounds 5 + roundEncode(AESKEY2, B00_03, B04_07, B08_11, B12_15); + ev_load_key(AESKEY2, key, 7 * 16, rbx); + + //GHASH 4 blocks(3 to 0) + carrylessMultiply(TLL2, TLH2, THL2, THH2, GHDAT2, GHKEY2, GHKEY1); + + //AES round 6 + roundEncode(AESKEY1, B00_03, B04_07, B08_11, B12_15); + ev_load_key(AESKEY1, key, 8 * 16, rbx); + + //gather GHASH in TO_REDUCE_H / L + if (is_hash_start) { + __ evpxorq(TO_REDUCE_L, TLL2, THL2, Assembler::AVX_512bit); + __ evpxorq(TO_REDUCE_H, THH2, TLH2, Assembler::AVX_512bit); + __ vpternlogq(TO_REDUCE_L, 0x96, TLL1, THL1, Assembler::AVX_512bit); + __ vpternlogq(TO_REDUCE_H, 0x96, THH1, TLH1, Assembler::AVX_512bit); + } else { + //not the first round so sums need to be updated + xorGHASH(TO_REDUCE_L, TO_REDUCE_H, TO_REDUCE_L, TO_REDUCE_H, TLL2, THL2, THH2, TLH2, TLL1, THL1, THH1, TLH1); } - // AES round 7 - roundEncode(ZTMP18, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP18, key, 9 * 16, xmm29); - if (final_reduction) { - __ vpternlogq(ZTMP5, 0x96, ZTMP9, ZTMP11, Assembler::AVX_512bit); - __ evpxorq(ZTMP5, ZTMP5, xmm27, Assembler::AVX_512bit); - __ vpternlogq(ZTMP6, 0x96, ZTMP10, ZTMP7, Assembler::AVX_512bit); - __ evpxorq(ZTMP6, ZTMP6, xmm26, Assembler::AVX_512bit); + + //AES round 7 + roundEncode(AESKEY2, B00_03, B04_07, B08_11, B12_15); + ev_load_key(AESKEY2, key, 9 * 16, rbx); + + //new reduction + if (do_hash_reduction) { + __ evmovdquq(ZT, ExternalAddress(ghash_polynomial_reduction_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); + __ evpclmulqdq(THH1, TO_REDUCE_L, ZT, 0x10, Assembler::AVX_512bit); + __ vpshufd(TO_REDUCE_L, TO_REDUCE_L, 78, Assembler::AVX_512bit); + __ vpternlogq(THH1, 0x96, TO_REDUCE_H, TO_REDUCE_L, Assembler::AVX_512bit); } - // AES round 8 - roundEncode(ZTMP17, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP17, key, 10 * 16, xmm29); - - // Horizontal xor of low and high 4*128 - if (final_reduction) { - vhpxori4x128(ZTMP5, ZTMP9); - vhpxori4x128(ZTMP6, ZTMP10); + + //AES round 8 + roundEncode(AESKEY1, B00_03, B04_07, B08_11, B12_15); + ev_load_key(AESKEY1, key, 10 * 16, rbx); + + //horizontalxor of 4 reduced hashes + if (do_hash_hxor) { + vhpxori4x128(THH1, TLL1); } - // AES round 9 - roundEncode(ZTMP18, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - // First phase of reduction - if (final_reduction) { - __ evpclmulqdq(ZTMP10, ZTMP12, ZTMP6, 0x01, Assembler::AVX_128bit); - __ vpslldq(ZTMP10, ZTMP10, 8, Assembler::AVX_128bit); - __ evpxorq(ZTMP10, ZTMP6, ZTMP10, Assembler::AVX_128bit); + + //AES round 9 + roundEncode(AESKEY2, B00_03, B04_07, B08_11, B12_15); + ev_load_key(AESKEY2, key, 11 * 16, rbx); + //AES rounds up to 11 (AES192) or 13 (AES256) + //AES128 is done + __ cmpl(NROUNDS, 52); + __ jcc(Assembler::less, last_aes_rnd); + __ bind(aes_192); + roundEncode(AESKEY1, B00_03, B04_07, B08_11, B12_15); + ev_load_key(AESKEY1, key, 12 * 16, rbx); + roundEncode(AESKEY2, B00_03, B04_07, B08_11, B12_15); + __ cmpl(NROUNDS, 60); + __ jcc(Assembler::less, last_aes_rnd); + __ bind(aes_256); + ev_load_key(AESKEY2, key, 13 * 16, rbx); + roundEncode(AESKEY1, B00_03, B04_07, B08_11, B12_15); + ev_load_key(AESKEY1, key, 14 * 16, rbx); + roundEncode(AESKEY2, B00_03, B04_07, B08_11, B12_15); + + __ bind(last_aes_rnd); + //the last AES round + lastroundEncode(AESKEY1, B00_03, B04_07, B08_11, B12_15); + //AESKEY1and AESKEY2 contain AES round keys + + //XOR against plain / cipher text + xorBeforeStore(B00_03, B04_07, B08_11, B12_15, DATA1, DATA2, DATA3, DATA4); + + //store cipher / plain text + storeData(out, pos, B00_03, B04_07, B08_11, B12_15); + //**B00_03, B04_07, B08_011, B12_B15 may contain sensitive data + + //shuffle cipher text blocks for GHASH computation + __ cmpptr(ct, out); + __ jcc(Assembler::notEqual, skip_shuffle); + shuffle(B00_03, B04_07, B08_11, B12_15, B00_03, B04_07, B08_11, B12_15, SHFMSK); + __ jmp(cont); + __ bind(skip_shuffle); + shuffle(B00_03, B04_07, B08_11, B12_15, DATA1, DATA2, DATA3, DATA4, SHFMSK); + + //**B00_03, B04_07, B08_011, B12_B15 overwritten with shuffled cipher text + __ bind(cont); + //store shuffled cipher text for ghashing + __ evmovdquq(Address(avx512_subkeyHtbl, 16 * aesout_offset), B00_03, Assembler::AVX_512bit); + __ evmovdquq(Address(avx512_subkeyHtbl, 16 * (aesout_offset + 4)), B04_07, Assembler::AVX_512bit); + __ evmovdquq(Address(avx512_subkeyHtbl, 16 * (aesout_offset + 8)), B08_11, Assembler::AVX_512bit); + __ evmovdquq(Address(avx512_subkeyHtbl, 16 * (aesout_offset + 12)), B12_15, Assembler::AVX_512bit); +} + + +//Encrypt / decrypt the initial 16 blocks +void StubGenerator::initial_blocks_16_avx512(Register in, Register out, Register ct, Register pos, Register key, Register avx512_subkeyHtbl, + Register CTR_CHECK, Register rounds, XMMRegister CTR, XMMRegister GHASH, XMMRegister ADDBE_4x4, + XMMRegister ADDBE_1234, XMMRegister ADD_1234, XMMRegister SHUF_MASK, int stack_offset) { + const XMMRegister B00_03 = xmm7; + const XMMRegister B04_07 = xmm10; + const XMMRegister B08_11 = xmm11; + const XMMRegister B12_15 = xmm12; + const XMMRegister T0 = xmm0; + const XMMRegister T1 = xmm3; + const XMMRegister T2 = xmm4; + const XMMRegister T3 = xmm5; + const XMMRegister T4 = xmm6; + const XMMRegister T5 = xmm30; + + Label next_16_overflow, next_16_ok, cont, skip_shuffle, aes_256, aes_192, last_aes_rnd; + //prepare counter blocks + __ cmpb(CTR_CHECK, (256 - 16)); + __ jcc(Assembler::aboveEqual, next_16_overflow); + __ vpaddd(B00_03, CTR, ADDBE_1234, Assembler::AVX_512bit); + __ vpaddd(B04_07, B00_03, ADDBE_4x4, Assembler::AVX_512bit); + __ vpaddd(B08_11, B04_07, ADDBE_4x4, Assembler::AVX_512bit); + __ vpaddd(B12_15, B08_11, ADDBE_4x4, Assembler::AVX_512bit); + __ jmp(next_16_ok); + __ bind(next_16_overflow); + __ vpshufb(CTR, CTR, SHUF_MASK, Assembler::AVX_512bit); + __ evmovdquq(B12_15, ExternalAddress(counter_mask_linc4_addr()), Assembler::AVX_512bit, rbx); + __ vpaddd(B00_03, CTR, ADD_1234, Assembler::AVX_512bit); + __ vpaddd(B04_07, B00_03, B12_15, Assembler::AVX_512bit); + __ vpaddd(B08_11, B04_07, B12_15, Assembler::AVX_512bit); + __ vpaddd(B12_15, B08_11, B12_15, Assembler::AVX_512bit); + shuffle(B00_03, B04_07, B08_11, B12_15, B00_03, B04_07, B08_11, B12_15, SHUF_MASK); + __ bind(next_16_ok); + __ evshufi64x2(CTR, B12_15, B12_15, 255, Assembler::AVX_512bit); + __ addb(CTR_CHECK, 16); + + //load 16 blocks of data + loadData(in, pos, T0, T1, T2, T3); + + //move to AES encryption rounds + __ movdqu(T5, ExternalAddress(key_shuffle_mask_addr()), rbx /*rscratch*/); + ev_load_key(T4, key, 0, T5); + __ evpxorq(B00_03, B00_03, T4, Assembler::AVX_512bit); + __ evpxorq(B04_07, B04_07, T4, Assembler::AVX_512bit); + __ evpxorq(B08_11, B08_11, T4, Assembler::AVX_512bit); + __ evpxorq(B12_15, B12_15, T4, Assembler::AVX_512bit); + + for (int i = 1; i < 10; i++) { + ev_load_key(T4, key, i * 16, T5); + roundEncode(T4, B00_03, B04_07, B08_11, B12_15); } + + ev_load_key(T4, key, 10 * 16, T5); __ cmpl(rounds, 52); - __ jcc(Assembler::greaterEqual, AES_192); - __ jmp(LAST_AES_RND); - // AES rounds up to 11 (AES192) or 13 (AES256) - __ bind(AES_192); - roundEncode(ZTMP17, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP18, key, 11 * 16, xmm29); - roundEncode(ZTMP18, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP17, key, 12 * 16, xmm29); + __ jcc(Assembler::less, last_aes_rnd); + __ bind(aes_192); + roundEncode(T4, B00_03, B04_07, B08_11, B12_15); + ev_load_key(T4, key, 16 * 11, T5); + roundEncode(T4, B00_03, B04_07, B08_11, B12_15); + ev_load_key(T4, key, 16 * 12, T5); __ cmpl(rounds, 60); - __ jcc(Assembler::aboveEqual, AES_256); - __ jmp(LAST_AES_RND); - - __ bind(AES_256); - roundEncode(ZTMP17, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP18, key, 13 * 16, xmm29); - roundEncode(ZTMP18, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - ev_load_key(ZTMP17, key, 14 * 16, xmm29); - - __ bind(LAST_AES_RND); - // Second phase of reduction - if (final_reduction) { - __ evpclmulqdq(ZTMP9, ZTMP12, ZTMP10, 0x00, Assembler::AVX_128bit); - __ vpsrldq(ZTMP9, ZTMP9, 4, Assembler::AVX_128bit); // Shift-R 1-DW to obtain 2-DWs shift-R - __ evpclmulqdq(ZTMP11, ZTMP12, ZTMP10, 0x10, Assembler::AVX_128bit); - __ vpslldq(ZTMP11, ZTMP11, 4, Assembler::AVX_128bit); // Shift-L 1-DW for result - // ZTMP5 = ZTMP5 X ZTMP11 X ZTMP9 - __ vpternlogq(ZTMP5, 0x96, ZTMP11, ZTMP9, Assembler::AVX_128bit); - } - // Last AES round - lastroundEncode(ZTMP17, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - // XOR against plain / cipher text - xorBeforeStore(ZTMP0, ZTMP1, ZTMP2, ZTMP3, ZTMP13, ZTMP14, ZTMP15, ZTMP16); - // store cipher / plain text - storeData(out, pos, ZTMP0, ZTMP1, ZTMP2, ZTMP3); + __ jcc(Assembler::less, last_aes_rnd); + __ bind(aes_256); + roundEncode(T4, B00_03, B04_07, B08_11, B12_15); + ev_load_key(T4, key, 16 * 13, T5); + roundEncode(T4, B00_03, B04_07, B08_11, B12_15); + ev_load_key(T4, key, 16 * 14, T5); + + __ bind(last_aes_rnd); + lastroundEncode(T4, B00_03, B04_07, B08_11, B12_15); + + //xor against text + xorBeforeStore(B00_03, B04_07, B08_11, B12_15, T0, T1, T2, T3); + + //store + storeData(out, pos, B00_03, B04_07, B08_11, B12_15); + + __ cmpptr(ct, out); + __ jcc(Assembler::equal, skip_shuffle); + //decryption - cipher text needs to go to GHASH phase + shuffle(B00_03, B04_07, B08_11, B12_15, T0, T1, T2, T3, SHUF_MASK); + __ jmp(cont); + __ bind(skip_shuffle); + shuffle(B00_03, B04_07, B08_11, B12_15, B00_03, B04_07, B08_11, B12_15, SHUF_MASK); + + //B00_03, B04_07, B08_11, B12_15 overwritten with shuffled cipher text + __ bind(cont); + __ evmovdquq(Address(avx512_subkeyHtbl, 16 * stack_offset), B00_03, Assembler::AVX_512bit); + __ evmovdquq(Address(avx512_subkeyHtbl, 16 * (stack_offset + 4)), B04_07, Assembler::AVX_512bit); + __ evmovdquq(Address(avx512_subkeyHtbl, 16 * (stack_offset + 8)), B08_11, Assembler::AVX_512bit); + __ evmovdquq(Address(avx512_subkeyHtbl, 16 * (stack_offset + 12)), B12_15, Assembler::AVX_512bit); } -void StubGenerator::aesgcm_encrypt(Register in, Register len, Register ct, Register out, Register key, - Register state, Register subkeyHtbl, Register avx512_subkeyHtbl, Register counter) { - Label ENC_DEC_DONE, GENERATE_HTBL_48_BLKS, AES_192, AES_256, STORE_CT, GHASH_LAST_32, - AES_32_BLOCKS, GHASH_AES_PARALLEL, LOOP, ACCUMULATE, GHASH_16_AES_16; - const XMMRegister CTR_BLOCKx = xmm9; +void StubGenerator::aesgcm_avx512(Register in, Register len, Register ct, Register out, Register key, Register state, + Register subkeyHtbl, Register avx512_subkeyHtbl, Register counter) { + Label ENC_DEC_DONE, MESG_BELOW_32_BLKS, NO_BIG_BLKS, ENCRYPT_BIG_BLKS_NO_HXOR, + ENCRYPT_BIG_NBLKS, ENCRYPT_16_BLKS, ENCRYPT_N_GHASH_32_N_BLKS, GHASH_DONE; + const XMMRegister CTR_BLOCKx = xmm2; const XMMRegister AAD_HASHx = xmm14; - const Register pos = rax; - const Register rounds = r15; - const Register ghash_pos = NOT_WIN64( r14) WIN64_ONLY( r11 ); const XMMRegister ZTMP0 = xmm0; - const XMMRegister ZTMP1 = xmm3; - const XMMRegister ZTMP2 = xmm4; - const XMMRegister ZTMP3 = xmm5; + const XMMRegister ZTMP1 = xmm3; //**sensitive + const XMMRegister ZTMP2 = xmm4; //**sensitive(small data) + const XMMRegister ZTMP3 = xmm5; //**sensitive(small data) const XMMRegister ZTMP4 = xmm6; const XMMRegister ZTMP5 = xmm7; const XMMRegister ZTMP6 = xmm10; @@ -3066,235 +3358,170 @@ void StubGenerator::aesgcm_encrypt(Register in, Register len, Register ct, Regis const XMMRegister ZTMP14 = xmm20; const XMMRegister ZTMP15 = xmm21; const XMMRegister ZTMP16 = xmm30; - const XMMRegister COUNTER_INC_MASK = xmm18; - - __ movl(pos, 0); // Total length processed - // Min data size processed = 768 bytes - __ cmpl(len, 768); - __ jcc(Assembler::less, ENC_DEC_DONE); + const XMMRegister ZTMP17 = xmm31; + const XMMRegister ZTMP18 = xmm1; + const XMMRegister ZTMP19 = xmm18; + const XMMRegister ZTMP20 = xmm8; + const XMMRegister ZTMP21 = xmm22; + const XMMRegister ZTMP22 = xmm23; + const XMMRegister ZTMP23 = xmm26; + const XMMRegister GH = xmm24; + const XMMRegister GL = xmm25; + const XMMRegister SHUF_MASK = xmm29; + const XMMRegister ADDBE_4x4 = xmm27; + const XMMRegister ADDBE_1234 = xmm28; + const XMMRegister ADD_1234 = xmm9; + const KRegister MASKREG = k1; + const Register pos = rax; + const Register rounds = r15; + const Register CTR_CHECK = r14; - // Generate 48 constants for htbl - __ call(GENERATE_HTBL_48_BLKS, relocInfo::none); - int index = 0; // Index for choosing subkeyHtbl entry - __ movl(ghash_pos, 0); // Pointer for ghash read and store operations + const int stack_offset = 64; + const int ghashin_offset = 64; + const int aesout_offset = 64; + const int hashkey_offset = 0; + const int hashkey_gap = 16 * 32; + const int HashKey_32 = 0; + const int HashKey_16 = 16 * 16; - // Move initial counter value and STATE value into variables + __ movl(pos, 0); + __ cmpl(len, 256); + __ jcc(Assembler::lessEqual, ENC_DEC_DONE); + + /* Structure of the Htbl is as follows: + * Where 0 - 31 we have 32 Hashkey's and 32-63 we have 32 HashKeyK (derived from HashKey) + * Rest 8 entries are for storing CTR values post AES rounds + * ---------------------------------------------------------------------------------------- + Hashkey32 -> 16 * 0 + Hashkey31 -> 16 * 1 + Hashkey30 -> 16 * 2 + ........ + Hashkey1 -> 16 * 31 + --------------------- + HaskeyK32 -> 16 * 32 + HashkeyK31 -> 16 * 33 + ......... + HashkeyK1 -> 16 * 63 + --------------------- + 1st set of AES Entries + B00_03 -> 16 * 64 + B04_07 -> 16 * 68 + B08_11 -> 16 * 72 + B12_15 -> 16 * 80 + --------------------- + 2nd set of AES Entries + B00_03 -> 16 * 84 + B04_07 -> 16 * 88 + B08_11 -> 16 * 92 + B12_15 -> 16 * 96 + ---------------------*/ + generateHtbl_32_blocks_avx512(subkeyHtbl, avx512_subkeyHtbl); + + //Move initial counter value and STATE value into variables __ movdqu(CTR_BLOCKx, Address(counter, 0)); __ movdqu(AAD_HASHx, Address(state, 0)); - // Load lswap mask for ghash + + //Load lswap mask for ghash __ movdqu(xmm24, ExternalAddress(ghash_long_swap_mask_addr()), rbx /*rscratch*/); - // Shuffle input state using lswap mask + //Shuffle input state using lswap mask __ vpshufb(AAD_HASHx, AAD_HASHx, xmm24, Assembler::AVX_128bit); // Compute #rounds for AES based on the length of the key array __ movl(rounds, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT))); - // Broadcast counter value to 512 bit register + __ evmovdquq(ADDBE_4x4, ExternalAddress(counter_mask_addbe_4444_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); + __ evmovdquq(ADDBE_1234, ExternalAddress(counter_mask_addbe_1234_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); + __ evmovdquq(SHUF_MASK, ExternalAddress(counter_shuffle_mask_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); + __ evmovdquq(ADD_1234, ExternalAddress(counter_mask_add_1234_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); + + //Shuffle counter, subtract 1 from the pre-incremented counter value and broadcast counter value to 512 bit register + __ vpshufb(CTR_BLOCKx, CTR_BLOCKx, SHUF_MASK, Assembler::AVX_128bit); + __ vpsubd(CTR_BLOCKx, CTR_BLOCKx, ADD_1234, Assembler::AVX_128bit); __ evshufi64x2(CTR_BLOCKx, CTR_BLOCKx, CTR_BLOCKx, 0, Assembler::AVX_512bit); - // Load counter shuffle mask - __ evmovdquq(xmm24, ExternalAddress(counter_shuffle_mask_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); - // Shuffle counter - __ vpshufb(CTR_BLOCKx, CTR_BLOCKx, xmm24, Assembler::AVX_512bit); - - // Load mask for incrementing counter - __ evmovdquq(COUNTER_INC_MASK, ExternalAddress(counter_mask_linc4_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); - // Pre-increment counter - __ vpaddd(ZTMP5, CTR_BLOCKx, ExternalAddress(counter_mask_linc0_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); - __ vpaddd(ZTMP6, ZTMP5, COUNTER_INC_MASK, Assembler::AVX_512bit); - __ vpaddd(ZTMP7, ZTMP6, COUNTER_INC_MASK, Assembler::AVX_512bit); - __ vpaddd(ZTMP8, ZTMP7, COUNTER_INC_MASK, Assembler::AVX_512bit); - - // Begin 32 blocks of AES processing - __ bind(AES_32_BLOCKS); - // Save incremented counter before overwriting it with AES data - __ evmovdquq(CTR_BLOCKx, ZTMP8, Assembler::AVX_512bit); - - // Move 256 bytes of data - loadData(in, pos, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - // Load key shuffle mask - __ movdqu(xmm29, ExternalAddress(key_shuffle_mask_addr()), rbx /*rscratch*/); - // Load 0th AES round key - ev_load_key(ZTMP4, key, 0, xmm29); - // AES-ROUND0, xmm24 has the shuffle mask - shuffleExorRnd1Key(ZTMP5, ZTMP6, ZTMP7, ZTMP8, xmm24, ZTMP4); - - for (int j = 1; j < 10; j++) { - ev_load_key(ZTMP4, key, j * 16, xmm29); - roundEncode(ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8); - } - ev_load_key(ZTMP4, key, 10 * 16, xmm29); - // AES rounds up to 11 (AES192) or 13 (AES256) - __ cmpl(rounds, 52); - __ jcc(Assembler::greaterEqual, AES_192); - lastroundEncode(ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8); - __ jmp(STORE_CT); - - __ bind(AES_192); - roundEncode(ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8); - ev_load_key(ZTMP4, key, 11 * 16, xmm29); - roundEncode(ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8); - __ cmpl(rounds, 60); - __ jcc(Assembler::aboveEqual, AES_256); - ev_load_key(ZTMP4, key, 12 * 16, xmm29); - lastroundEncode(ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8); - __ jmp(STORE_CT); - - __ bind(AES_256); - ev_load_key(ZTMP4, key, 12 * 16, xmm29); - roundEncode(ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8); - ev_load_key(ZTMP4, key, 13 * 16, xmm29); - roundEncode(ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8); - ev_load_key(ZTMP4, key, 14 * 16, xmm29); - // Last AES round - lastroundEncode(ZTMP4, ZTMP5, ZTMP6, ZTMP7, ZTMP8); - - __ bind(STORE_CT); - // Xor the encrypted key with PT to obtain CT - xorBeforeStore(ZTMP5, ZTMP6, ZTMP7, ZTMP8, ZTMP0, ZTMP1, ZTMP2, ZTMP3); - storeData(out, pos, ZTMP5, ZTMP6, ZTMP7, ZTMP8); - // 16 blocks encryption completed - __ addl(pos, 256); - __ cmpl(pos, 512); - __ jcc(Assembler::aboveEqual, GHASH_AES_PARALLEL); - __ vpaddd(ZTMP5, CTR_BLOCKx, COUNTER_INC_MASK, Assembler::AVX_512bit); - __ vpaddd(ZTMP6, ZTMP5, COUNTER_INC_MASK, Assembler::AVX_512bit); - __ vpaddd(ZTMP7, ZTMP6, COUNTER_INC_MASK, Assembler::AVX_512bit); - __ vpaddd(ZTMP8, ZTMP7, COUNTER_INC_MASK, Assembler::AVX_512bit); - __ jmp(AES_32_BLOCKS); - - __ bind(GHASH_AES_PARALLEL); - // Ghash16_encrypt16_parallel takes place in the order with three reduction values: - // 1) First time -> cipher xor input ghash - // 2) No reduction -> accumulate multiplication values - // 3) Final reduction post 48 blocks -> new ghash value is computed for the next round - // Reduction value = first time - ghash16_encrypt16_parallel(key, avx512_subkeyHtbl, CTR_BLOCKx, AAD_HASHx, in, out, ct, pos, true, xmm24, true, rounds, ghash_pos, false, index, COUNTER_INC_MASK); - __ addl(pos, 256); - __ addl(ghash_pos, 256); - index += 4; - - // At this point we have processed 768 bytes of AES and 256 bytes of GHASH. - // If the remaining length is less than 768, process remaining 512 bytes of ghash in GHASH_LAST_32 code - __ subl(len, 768); - __ cmpl(len, 768); - __ jcc(Assembler::less, GHASH_LAST_32); - - // AES 16 blocks and GHASH 16 blocks in parallel - // For multiples of 48 blocks we will do ghash16_encrypt16 interleaved multiple times - // Reduction value = no reduction means that the carryless multiplication values are accumulated for further calculations - // Each call uses 4 subkeyHtbl values, so increment the index by 4. - __ bind(GHASH_16_AES_16); - // Reduction value = no reduction - ghash16_encrypt16_parallel(key, avx512_subkeyHtbl, CTR_BLOCKx, AAD_HASHx, in, out, ct, pos, false, xmm24, false, rounds, ghash_pos, false, index, COUNTER_INC_MASK); - __ addl(pos, 256); - __ addl(ghash_pos, 256); - index += 4; - // Reduction value = final reduction means that the accumulated values have to be reduced as we have completed 48 blocks of ghash - ghash16_encrypt16_parallel(key, avx512_subkeyHtbl, CTR_BLOCKx, AAD_HASHx, in, out, ct, pos, false, xmm24, false, rounds, ghash_pos, true, index, COUNTER_INC_MASK); - __ addl(pos, 256); - __ addl(ghash_pos, 256); - // Calculated ghash value needs to be __ moved to AAD_HASHX so that we can restart the ghash16-aes16 pipeline - __ movdqu(AAD_HASHx, ZTMP5); - index = 0; // Reset subkeyHtbl index - - // Restart the pipeline - // Reduction value = first time - ghash16_encrypt16_parallel(key, avx512_subkeyHtbl, CTR_BLOCKx, AAD_HASHx, in, out, ct, pos, true, xmm24, true, rounds, ghash_pos, false, index, COUNTER_INC_MASK); - __ addl(pos, 256); - __ addl(ghash_pos, 256); - index += 4; - - __ subl(len, 768); - __ cmpl(len, 768); - __ jcc(Assembler::greaterEqual, GHASH_16_AES_16); - - // GHASH last 32 blocks processed here - // GHASH products accumulated in ZMM27, ZMM25 and ZMM26 during GHASH16-AES16 operation is used - __ bind(GHASH_LAST_32); - // Use rbx as a pointer to the htbl; For last 32 blocks of GHASH, use key# 4-11 entry in subkeyHtbl - __ movl(rbx, 256); - // Load cipher blocks - __ evmovdquq(ZTMP13, Address(ct, ghash_pos, Address::times_1, 0 * 64), Assembler::AVX_512bit); - __ evmovdquq(ZTMP14, Address(ct, ghash_pos, Address::times_1, 1 * 64), Assembler::AVX_512bit); - __ vpshufb(ZTMP13, ZTMP13, xmm24, Assembler::AVX_512bit); - __ vpshufb(ZTMP14, ZTMP14, xmm24, Assembler::AVX_512bit); - // Load ghash keys - __ evmovdquq(ZTMP15, Address(avx512_subkeyHtbl, rbx, Address::times_1, 0 * 64), Assembler::AVX_512bit); - __ evmovdquq(ZTMP16, Address(avx512_subkeyHtbl, rbx, Address::times_1, 1 * 64), Assembler::AVX_512bit); - - // Ghash blocks 0 - 3 - carrylessMultiply(ZTMP2, ZTMP3, ZTMP4, ZTMP1, ZTMP13, ZTMP15); - // Ghash blocks 4 - 7 - carrylessMultiply(ZTMP6, ZTMP7, ZTMP8, ZTMP5, ZTMP14, ZTMP16); - - __ vpternlogq(ZTMP1, 0x96, ZTMP5, xmm27, Assembler::AVX_512bit); // ZTMP1 = ZTMP1 + ZTMP5 + zmm27 - __ vpternlogq(ZTMP2, 0x96, ZTMP6, xmm26, Assembler::AVX_512bit); // ZTMP2 = ZTMP2 + ZTMP6 + zmm26 - __ vpternlogq(ZTMP3, 0x96, ZTMP7, xmm25, Assembler::AVX_512bit); // ZTMP3 = ZTMP3 + ZTMP7 + zmm25 - __ evpxorq(ZTMP4, ZTMP4, ZTMP8, Assembler::AVX_512bit); // ZTMP4 = ZTMP4 + ZTMP8 - - __ addl(ghash_pos, 128); - __ addl(rbx, 128); - - // Ghash remaining blocks - __ bind(LOOP); - __ cmpl(ghash_pos, pos); - __ jcc(Assembler::aboveEqual, ACCUMULATE); - // Load next cipher blocks and corresponding ghash keys - __ evmovdquq(ZTMP13, Address(ct, ghash_pos, Address::times_1, 0 * 64), Assembler::AVX_512bit); - __ evmovdquq(ZTMP14, Address(ct, ghash_pos, Address::times_1, 1 * 64), Assembler::AVX_512bit); - __ vpshufb(ZTMP13, ZTMP13, xmm24, Assembler::AVX_512bit); - __ vpshufb(ZTMP14, ZTMP14, xmm24, Assembler::AVX_512bit); - __ evmovdquq(ZTMP15, Address(avx512_subkeyHtbl, rbx, Address::times_1, 0 * 64), Assembler::AVX_512bit); - __ evmovdquq(ZTMP16, Address(avx512_subkeyHtbl, rbx, Address::times_1, 1 * 64), Assembler::AVX_512bit); - - // ghash blocks 0 - 3 - carrylessMultiply(ZTMP6, ZTMP7, ZTMP8, ZTMP5, ZTMP13, ZTMP15); - - // ghash blocks 4 - 7 - carrylessMultiply(ZTMP10, ZTMP11, ZTMP12, ZTMP9, ZTMP14, ZTMP16); - - // update sums - // ZTMP1 = ZTMP1 + ZTMP5 + ZTMP9 - // ZTMP2 = ZTMP2 + ZTMP6 + ZTMP10 - // ZTMP3 = ZTMP3 + ZTMP7 xor ZTMP11 - // ZTMP4 = ZTMP4 + ZTMP8 xor ZTMP12 - xorGHASH(ZTMP1, ZTMP2, ZTMP3, ZTMP4, ZTMP5, ZTMP9, ZTMP6, ZTMP10, ZTMP7, ZTMP11, ZTMP8, ZTMP12); - __ addl(ghash_pos, 128); - __ addl(rbx, 128); - __ jmp(LOOP); - // Integrate ZTMP3/ZTMP4 into ZTMP1 and ZTMP2 - __ bind(ACCUMULATE); - __ evpxorq(ZTMP3, ZTMP3, ZTMP4, Assembler::AVX_512bit); - __ vpsrldq(ZTMP7, ZTMP3, 8, Assembler::AVX_512bit); - __ vpslldq(ZTMP8, ZTMP3, 8, Assembler::AVX_512bit); - __ evpxorq(ZTMP1, ZTMP1, ZTMP7, Assembler::AVX_512bit); - __ evpxorq(ZTMP2, ZTMP2, ZTMP8, Assembler::AVX_512bit); - - // Add ZTMP1 and ZTMP2 128 - bit words horizontally - vhpxori4x128(ZTMP1, ZTMP11); - vhpxori4x128(ZTMP2, ZTMP12); - // Load reduction polynomial and compute final reduction - __ evmovdquq(ZTMP15, ExternalAddress(ghash_polynomial_reduction_addr()), Assembler::AVX_512bit, rbx /*rscratch*/); - vclmul_reduce(AAD_HASHx, ZTMP15, ZTMP1, ZTMP2, ZTMP3, ZTMP4); - - // Pre-increment counter for next operation - __ vpaddd(CTR_BLOCKx, CTR_BLOCKx, xmm18, Assembler::AVX_128bit); - // Shuffle counter and save the updated value - __ vpshufb(CTR_BLOCKx, CTR_BLOCKx, xmm24, Assembler::AVX_512bit); + __ movdl(CTR_CHECK, CTR_BLOCKx); + __ andl(CTR_CHECK, 255); + + // Reshuffle counter + __ vpshufb(CTR_BLOCKx, CTR_BLOCKx, SHUF_MASK, Assembler::AVX_512bit); + + initial_blocks_16_avx512(in, out, ct, pos, key, avx512_subkeyHtbl, CTR_CHECK, rounds, CTR_BLOCKx, AAD_HASHx, ADDBE_4x4, ADDBE_1234, ADD_1234, SHUF_MASK, stack_offset); + __ addl(pos, 16 * 16); + __ cmpl(len, 32 * 16); + __ jcc(Assembler::below, MESG_BELOW_32_BLKS); + + initial_blocks_16_avx512(in, out, ct, pos, key, avx512_subkeyHtbl, CTR_CHECK, rounds, CTR_BLOCKx, AAD_HASHx, ADDBE_4x4, ADDBE_1234, ADD_1234, SHUF_MASK, stack_offset + 16); + __ addl(pos, 16 * 16); + __ subl(len, 32 * 16); + + __ cmpl(len, 32 * 16); + __ jcc(Assembler::below, NO_BIG_BLKS); + + __ bind(ENCRYPT_BIG_BLKS_NO_HXOR); + __ cmpl(len, 2 * 32 * 16); + __ jcc(Assembler::below, ENCRYPT_BIG_NBLKS); + ghash16_encrypt_parallel16_avx512(in, out, ct, pos, avx512_subkeyHtbl, CTR_CHECK, rounds, key, CTR_BLOCKx, AAD_HASHx, ADDBE_4x4, ADDBE_1234, ADD_1234, SHUF_MASK, + true, true, false, false, false, ghashin_offset, aesout_offset, HashKey_32); + __ addl(pos, 16 * 16); + + ghash16_encrypt_parallel16_avx512(in, out, ct, pos, avx512_subkeyHtbl, CTR_CHECK, rounds, key, CTR_BLOCKx, AAD_HASHx, ADDBE_4x4, ADDBE_1234, ADD_1234, SHUF_MASK, + true, false, true, false, true, ghashin_offset + 16, aesout_offset + 16, HashKey_16); + __ evmovdquq(AAD_HASHx, ZTMP4, Assembler::AVX_512bit); + __ addl(pos, 16 * 16); + __ subl(len, 32 * 16); + __ jmp(ENCRYPT_BIG_BLKS_NO_HXOR); + + __ bind(ENCRYPT_BIG_NBLKS); + ghash16_encrypt_parallel16_avx512(in, out, ct, pos, avx512_subkeyHtbl, CTR_CHECK, rounds, key, CTR_BLOCKx, AAD_HASHx, ADDBE_4x4, ADDBE_1234, ADD_1234, SHUF_MASK, + false, true, false, false, false, ghashin_offset, aesout_offset, HashKey_32); + __ addl(pos, 16 * 16); + ghash16_encrypt_parallel16_avx512(in, out, ct, pos, avx512_subkeyHtbl, CTR_CHECK, rounds, key, CTR_BLOCKx, AAD_HASHx, ADDBE_4x4, ADDBE_1234, ADD_1234, SHUF_MASK, + false, false, true, true, true, ghashin_offset + 16, aesout_offset + 16, HashKey_16); + + __ movdqu(AAD_HASHx, ZTMP4); + __ addl(pos, 16 * 16); + __ subl(len, 32 * 16); + + __ bind(NO_BIG_BLKS); + __ cmpl(len, 16 * 16); + __ jcc(Assembler::aboveEqual, ENCRYPT_16_BLKS); + + __ bind(ENCRYPT_N_GHASH_32_N_BLKS); + ghash16_avx512(true, false, false, false, true, in, pos, avx512_subkeyHtbl, AAD_HASHx, SHUF_MASK, stack_offset, 0, 0, HashKey_32); + gcm_enc_dec_last_avx512(len, in, pos, AAD_HASHx, SHUF_MASK, avx512_subkeyHtbl, ghashin_offset + 16, HashKey_16, false, true); + __ jmp(GHASH_DONE); + + __ bind(ENCRYPT_16_BLKS); + ghash16_encrypt_parallel16_avx512(in, out, ct, pos, avx512_subkeyHtbl, CTR_CHECK, rounds, key, CTR_BLOCKx, AAD_HASHx, ADDBE_4x4, ADDBE_1234, ADD_1234, SHUF_MASK, + false, true, false, false, false, ghashin_offset, aesout_offset, HashKey_32); + + ghash16_avx512(false, true, false, false, true, in, pos, avx512_subkeyHtbl, AAD_HASHx, SHUF_MASK, stack_offset, 16 * 16, 0, HashKey_16); + + __ bind(MESG_BELOW_32_BLKS); + __ subl(len, 16 * 16); + __ addl(pos, 16 * 16); + gcm_enc_dec_last_avx512(len, in, pos, AAD_HASHx, SHUF_MASK, avx512_subkeyHtbl, ghashin_offset, HashKey_16, true, true); + + __ bind(GHASH_DONE); + //Pre-increment counter for next operation, make sure that counter value is incremented on the LSB + __ vpshufb(CTR_BLOCKx, CTR_BLOCKx, SHUF_MASK, Assembler::AVX_128bit); + __ vpaddd(CTR_BLOCKx, CTR_BLOCKx, ADD_1234, Assembler::AVX_128bit); + __ vpshufb(CTR_BLOCKx, CTR_BLOCKx, SHUF_MASK, Assembler::AVX_128bit); __ movdqu(Address(counter, 0), CTR_BLOCKx); - // Load ghash lswap mask + //Load ghash lswap mask __ movdqu(xmm24, ExternalAddress(ghash_long_swap_mask_addr()), rbx /*rscratch*/); - // Shuffle ghash using lbswap_mask and store it + //Shuffle ghash using lbswap_mask and store it __ vpshufb(AAD_HASHx, AAD_HASHx, xmm24, Assembler::AVX_128bit); __ movdqu(Address(state, 0), AAD_HASHx); - __ jmp(ENC_DEC_DONE); - __ bind(GENERATE_HTBL_48_BLKS); - generateHtbl_48_block_zmm(subkeyHtbl, avx512_subkeyHtbl, rbx /*rscratch*/); + //Zero out sensitive data + __ evpxorq(ZTMP21, ZTMP21, ZTMP21, Assembler::AVX_512bit); + __ evpxorq(ZTMP0, ZTMP0, ZTMP0, Assembler::AVX_512bit); + __ evpxorq(ZTMP1, ZTMP1, ZTMP1, Assembler::AVX_512bit); + __ evpxorq(ZTMP2, ZTMP2, ZTMP2, Assembler::AVX_512bit); + __ evpxorq(ZTMP3, ZTMP3, ZTMP3, Assembler::AVX_512bit); __ bind(ENC_DEC_DONE); - __ movq(rax, pos); } //Implements data * hashkey mod (128, 127, 126, 121, 0) diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64_ghash.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_64_ghash.cpp index 2056fa05765..5a9b0848413 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_64_ghash.cpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64_ghash.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2019, 2021, Intel Corporation. All rights reserved. +* Copyright (c) 2019, 2024, Intel Corporation. All rights reserved. * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -57,7 +57,10 @@ address StubGenerator::ghash_byte_swap_mask_addr() { // Polynomial x^128+x^127+x^126+x^121+1 ATTRIBUTE_ALIGNED(16) static const uint64_t GHASH_POLYNOMIAL[] = { - 0x0000000000000001UL, 0xC200000000000000UL, + 0x0000000000000001ULL, 0xC200000000000000ULL, + 0x0000000000000001ULL, 0xC200000000000000ULL, + 0x0000000000000001ULL, 0xC200000000000000ULL, + 0x0000000000000001ULL, 0xC200000000000000ULL }; address StubGenerator::ghash_polynomial_addr() { return (address)GHASH_POLYNOMIAL; diff --git a/src/hotspot/cpu/x86/x86.ad b/src/hotspot/cpu/x86/x86.ad index 2b29dd14e4b..b55a1208cf2 100644 --- a/src/hotspot/cpu/x86/x86.ad +++ b/src/hotspot/cpu/x86/x86.ad @@ -2457,6 +2457,10 @@ bool Matcher::pd_clone_node(Node* n, Node* m, Matcher::MStack& mstack) { mstack.push(m, Visit); // m = ShiftCntV return true; } + if (is_encode_and_store_pattern(n, m)) { + mstack.push(m, Visit); + return true; + } return false; } diff --git a/src/hotspot/cpu/x86/x86_64.ad b/src/hotspot/cpu/x86/x86_64.ad index 1b271683bd6..fee265473be 100644 --- a/src/hotspot/cpu/x86/x86_64.ad +++ b/src/hotspot/cpu/x86/x86_64.ad @@ -4341,6 +4341,7 @@ instruct loadP(rRegP dst, memory mem) // Load Compressed Pointer instruct loadN(rRegN dst, memory mem) %{ + predicate(n->as_Load()->barrier_data() == 0); match(Set dst (LoadN mem)); ins_cost(125); // XXX @@ -5126,6 +5127,7 @@ instruct storeImmP(memory mem, immP31 src) // Store Compressed Pointer instruct storeN(memory mem, rRegN src) %{ + predicate(n->as_Store()->barrier_data() == 0); match(Set mem (StoreN mem src)); ins_cost(125); // XXX @@ -5150,7 +5152,7 @@ instruct storeNKlass(memory mem, rRegN src) instruct storeImmN0(memory mem, immN0 zero) %{ - predicate(CompressedOops::base() == nullptr); + predicate(CompressedOops::base() == nullptr && n->as_Store()->barrier_data() == 0); match(Set mem (StoreN mem zero)); ins_cost(125); // XXX @@ -5163,6 +5165,7 @@ instruct storeImmN0(memory mem, immN0 zero) instruct storeImmN(memory mem, immN src) %{ + predicate(n->as_Store()->barrier_data() == 0); match(Set mem (StoreN mem src)); ins_cost(150); // XXX @@ -7162,6 +7165,7 @@ instruct compareAndSwapN(rRegI res, memory mem_ptr, rax_RegN oldval, rRegN newval, rFlagsReg cr) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); match(Set res (CompareAndSwapN mem_ptr (Binary oldval newval))); match(Set res (WeakCompareAndSwapN mem_ptr (Binary oldval newval))); effect(KILL cr, KILL oldval); @@ -7249,6 +7253,7 @@ instruct compareAndExchangeN( memory mem_ptr, rax_RegN oldval, rRegN newval, rFlagsReg cr) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); match(Set oldval (CompareAndExchangeN mem_ptr (Binary oldval newval))); effect(KILL cr); @@ -7470,6 +7475,7 @@ instruct xchgP( memory mem, rRegP newval) %{ %} instruct xchgN( memory mem, rRegN newval) %{ + predicate(n->as_LoadStore()->barrier_data() == 0); match(Set newval (GetAndSetN mem newval)); format %{ "XCHGL $newval,$mem]" %} ins_encode %{ @@ -11659,6 +11665,7 @@ instruct compN_rReg(rFlagsRegU cr, rRegN op1, rRegN op2) instruct compN_rReg_mem(rFlagsRegU cr, rRegN src, memory mem) %{ + predicate(n->in(2)->as_Load()->barrier_data() == 0); match(Set cr (CmpN src (LoadN mem))); format %{ "cmpl $src, $mem\t# compressed ptr" %} @@ -11680,6 +11687,7 @@ instruct compN_rReg_imm(rFlagsRegU cr, rRegN op1, immN op2) %{ instruct compN_mem_imm(rFlagsRegU cr, memory mem, immN src) %{ + predicate(n->in(2)->as_Load()->barrier_data() == 0); match(Set cr (CmpN src (LoadN mem))); format %{ "cmpl $mem, $src\t# compressed ptr" %} @@ -11720,7 +11728,8 @@ instruct testN_reg(rFlagsReg cr, rRegN src, immN0 zero) %{ instruct testN_mem(rFlagsReg cr, memory mem, immN0 zero) %{ - predicate(CompressedOops::base() != nullptr); + predicate(CompressedOops::base() != nullptr && + n->in(1)->as_Load()->barrier_data() == 0); match(Set cr (CmpN (LoadN mem) zero)); ins_cost(500); // XXX @@ -11733,7 +11742,8 @@ instruct testN_mem(rFlagsReg cr, memory mem, immN0 zero) instruct testN_mem_reg0(rFlagsReg cr, memory mem, immN0 zero) %{ - predicate(CompressedOops::base() == nullptr); + predicate(CompressedOops::base() == nullptr && + n->in(1)->as_Load()->barrier_data() == 0); match(Set cr (CmpN (LoadN mem) zero)); format %{ "cmpl R12, $mem\t# compressed ptr (R12_heapbase==0)" %} diff --git a/src/hotspot/cpu/zero/vm_version_zero.cpp b/src/hotspot/cpu/zero/vm_version_zero.cpp index 1fcf4b10862..7312dd11646 100644 --- a/src/hotspot/cpu/zero/vm_version_zero.cpp +++ b/src/hotspot/cpu/zero/vm_version_zero.cpp @@ -116,11 +116,6 @@ void VM_Version::initialize() { FLAG_SET_DEFAULT(UseVectorizedMismatchIntrinsic, false); } - if ((LockingMode != LM_LEGACY) && (LockingMode != LM_MONITOR)) { - warning("Unsupported locking mode for this CPU."); - FLAG_SET_DEFAULT(LockingMode, LM_LEGACY); - } - // Enable error context decoding on known platforms #if defined(IA32) || defined(AMD64) || defined(ARM) || \ defined(AARCH64) || defined(PPC) || defined(RISCV) || \ diff --git a/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp b/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp index 2b53042ef10..aab43e73396 100644 --- a/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp +++ b/src/hotspot/cpu/zero/zeroInterpreter_zero.cpp @@ -485,26 +485,30 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { // Unlock if necessary if (monitor) { - BasicLock *lock = monitor->lock(); - markWord header = lock->displaced_header(); - oop rcvr = monitor->obj(); - monitor->set_obj(nullptr); - - bool dec_monitor_count = true; - if (header.to_pointer() != nullptr) { - markWord old_header = markWord::encode(lock); - if (rcvr->cas_set_mark(header, old_header) != old_header) { - monitor->set_obj(rcvr); - dec_monitor_count = false; - InterpreterRuntime::monitorexit(monitor); + bool success = false; + if (LockingMode == LM_LEGACY) { + BasicLock* lock = monitor->lock(); + oop rcvr = monitor->obj(); + monitor->set_obj(nullptr); + success = true; + markWord header = lock->displaced_header(); + if (header.to_pointer() != nullptr) { // Check for recursive lock + markWord old_header = markWord::encode(lock); + if (rcvr->cas_set_mark(header, old_header) != old_header) { + monitor->set_obj(rcvr); + success = false; + } + } + if (success) { + THREAD->dec_held_monitor_count(); } } - if (dec_monitor_count) { - THREAD->dec_held_monitor_count(); + if (!success) { + InterpreterRuntime::monitorexit(monitor); } } - unwind_and_return: + unwind_and_return: // Unwind the current activation thread->pop_zero_frame(); diff --git a/src/hotspot/os/bsd/gc/z/zPhysicalMemoryBacking_bsd.cpp b/src/hotspot/os/bsd/gc/z/zPhysicalMemoryBacking_bsd.cpp index 29825a9eab2..2e56c092a79 100644 --- a/src/hotspot/os/bsd/gc/z/zPhysicalMemoryBacking_bsd.cpp +++ b/src/hotspot/os/bsd/gc/z/zPhysicalMemoryBacking_bsd.cpp @@ -22,10 +22,10 @@ */ #include "precompiled.hpp" -#include "gc/shared/gcLogPrecious.hpp" #include "gc/z/zAddress.inline.hpp" #include "gc/z/zErrno.hpp" #include "gc/z/zGlobals.hpp" +#include "gc/z/zInitialize.hpp" #include "gc/z/zLargePages.inline.hpp" #include "gc/z/zPhysicalMemory.inline.hpp" #include "gc/z/zPhysicalMemoryBacking_bsd.hpp" @@ -82,7 +82,7 @@ ZPhysicalMemoryBacking::ZPhysicalMemoryBacking(size_t max_capacity) _base = (uintptr_t)os::reserve_memory(max_capacity); if (_base == 0) { // Failed - log_error_pd(gc)("Failed to reserve address space for backing memory"); + ZInitialize::error("Failed to reserve address space for backing memory"); return; } diff --git a/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp b/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp index f967fee9305..b648876ac60 100644 --- a/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp +++ b/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp @@ -27,6 +27,7 @@ #include "gc/z/zArray.inline.hpp" #include "gc/z/zErrno.hpp" #include "gc/z/zGlobals.hpp" +#include "gc/z/zInitialize.hpp" #include "gc/z/zLargePages.inline.hpp" #include "gc/z/zMountPoint_linux.hpp" #include "gc/z/zNUMA.inline.hpp" @@ -129,6 +130,7 @@ ZPhysicalMemoryBacking::ZPhysicalMemoryBacking(size_t max_capacity) // Create backing file _fd = create_fd(ZFILENAME_HEAP); if (_fd == -1) { + ZInitialize::error("Failed to create heap backing file"); return; } @@ -136,7 +138,7 @@ ZPhysicalMemoryBacking::ZPhysicalMemoryBacking(size_t max_capacity) while (ftruncate(_fd, max_capacity) == -1) { if (errno != EINTR) { ZErrno err; - log_error_p(gc)("Failed to truncate backing file (%s)", err.to_string()); + ZInitialize::error("Failed to truncate backing file (%s)", err.to_string()); return; } } @@ -145,7 +147,7 @@ ZPhysicalMemoryBacking::ZPhysicalMemoryBacking(size_t max_capacity) struct statfs buf; if (fstatfs(_fd, &buf) == -1) { ZErrno err; - log_error_p(gc)("Failed to determine filesystem type for backing file (%s)", err.to_string()); + ZInitialize::error("Failed to determine filesystem type for backing file (%s)", err.to_string()); return; } @@ -158,39 +160,39 @@ ZPhysicalMemoryBacking::ZPhysicalMemoryBacking(size_t max_capacity) // Make sure the filesystem type matches requested large page type if (ZLargePages::is_transparent() && !is_tmpfs()) { - log_error_p(gc)("-XX:+UseTransparentHugePages can only be enabled when using a %s filesystem", - ZFILESYSTEM_TMPFS); + ZInitialize::error("-XX:+UseTransparentHugePages can only be enabled when using a %s filesystem", + ZFILESYSTEM_TMPFS); return; } if (ZLargePages::is_transparent() && !tmpfs_supports_transparent_huge_pages()) { - log_error_p(gc)("-XX:+UseTransparentHugePages on a %s filesystem not supported by kernel", - ZFILESYSTEM_TMPFS); + ZInitialize::error("-XX:+UseTransparentHugePages on a %s filesystem not supported by kernel", + ZFILESYSTEM_TMPFS); return; } if (ZLargePages::is_explicit() && !is_hugetlbfs()) { - log_error_p(gc)("-XX:+UseLargePages (without -XX:+UseTransparentHugePages) can only be enabled " - "when using a %s filesystem", ZFILESYSTEM_HUGETLBFS); + ZInitialize::error("-XX:+UseLargePages (without -XX:+UseTransparentHugePages) can only be enabled " + "when using a %s filesystem", ZFILESYSTEM_HUGETLBFS); return; } if (!ZLargePages::is_explicit() && is_hugetlbfs()) { - log_error_p(gc)("-XX:+UseLargePages must be enabled when using a %s filesystem", - ZFILESYSTEM_HUGETLBFS); + ZInitialize::error("-XX:+UseLargePages must be enabled when using a %s filesystem", + ZFILESYSTEM_HUGETLBFS); return; } // Make sure the filesystem block size is compatible if (ZGranuleSize % _block_size != 0) { - log_error_p(gc)("Filesystem backing the heap has incompatible block size (" SIZE_FORMAT ")", - _block_size); + ZInitialize::error("Filesystem backing the heap has incompatible block size (" SIZE_FORMAT ")", + _block_size); return; } if (is_hugetlbfs() && _block_size != ZGranuleSize) { - log_error_p(gc)("%s filesystem has unexpected block size " SIZE_FORMAT " (expected " SIZE_FORMAT ")", - ZFILESYSTEM_HUGETLBFS, _block_size, ZGranuleSize); + ZInitialize::error("%s filesystem has unexpected block size " SIZE_FORMAT " (expected " SIZE_FORMAT ")", + ZFILESYSTEM_HUGETLBFS, _block_size, ZGranuleSize); return; } diff --git a/src/hotspot/share/adlc/adlArena.cpp b/src/hotspot/share/adlc/adlArena.cpp index d5a1dd500fa..ebd1f74911d 100644 --- a/src/hotspot/share/adlc/adlArena.cpp +++ b/src/hotspot/share/adlc/adlArena.cpp @@ -63,8 +63,6 @@ void AdlChunk::chop() { AdlChunk *k = this; while( k ) { AdlChunk *tmp = k->_next; - // clear out this chunk (to detect allocation bugs) - memset(k, 0xBE, k->_len); free(k); // Free chunk (was malloc'd) k = tmp; } diff --git a/src/hotspot/share/adlc/formssel.cpp b/src/hotspot/share/adlc/formssel.cpp index e7df38ff221..15bc7ddc67d 100644 --- a/src/hotspot/share/adlc/formssel.cpp +++ b/src/hotspot/share/adlc/formssel.cpp @@ -4357,7 +4357,7 @@ bool MatchRule::is_vector() const { "RoundDoubleModeV","RotateLeftV" , "RotateRightV", "LoadVector","StoreVector", "LoadVectorGather", "StoreVectorScatter", "LoadVectorGatherMasked", "StoreVectorScatterMasked", "VectorTest", "VectorLoadMask", "VectorStoreMask", "VectorBlend", "VectorInsert", - "VectorRearrange","VectorLoadShuffle", "VectorLoadConst", + "VectorRearrange", "VectorLoadShuffle", "VectorLoadConst", "VectorCastB2X", "VectorCastS2X", "VectorCastI2X", "VectorCastL2X", "VectorCastF2X", "VectorCastD2X", "VectorCastF2HF", "VectorCastHF2F", "VectorUCastB2X", "VectorUCastS2X", "VectorUCastI2X", diff --git a/src/hotspot/share/c1/c1_LIR.hpp b/src/hotspot/share/c1/c1_LIR.hpp index d9c3e9d3cb6..c568caeca4b 100644 --- a/src/hotspot/share/c1/c1_LIR.hpp +++ b/src/hotspot/share/c1/c1_LIR.hpp @@ -29,6 +29,7 @@ #include "c1/c1_ValueType.hpp" #include "oops/method.hpp" #include "utilities/globalDefinitions.hpp" +#include "utilities/macros.hpp" class BlockBegin; class BlockList; @@ -1122,7 +1123,7 @@ class LIR_Op: public CompilationResourceObj { } #endif - virtual const char * name() const PRODUCT_RETURN0; + virtual const char * name() const PRODUCT_RETURN_NULL; virtual void visit(LIR_OpVisitState* state); int id() const { return _id; } @@ -1400,7 +1401,7 @@ class LIR_Op1: public LIR_Op { virtual bool is_patching() { return _patch != lir_patch_none; } virtual void emit_code(LIR_Assembler* masm); virtual LIR_Op1* as_Op1() { return this; } - virtual const char * name() const PRODUCT_RETURN0; + virtual const char * name() const PRODUCT_RETURN_NULL; void set_in_opr(LIR_Opr opr) { _opr = opr; } diff --git a/src/hotspot/share/cds/archiveHeapLoader.cpp b/src/hotspot/share/cds/archiveHeapLoader.cpp index 6325fb6f49d..0e7ef08064c 100644 --- a/src/hotspot/share/cds/archiveHeapLoader.cpp +++ b/src/hotspot/share/cds/archiveHeapLoader.cpp @@ -376,13 +376,12 @@ void ArchiveHeapLoader::finish_initialization() { intptr_t bottom = is_loaded() ? _loaded_heap_bottom : _mapped_heap_bottom; // The heap roots are stored in one or more segments that are laid out consecutively. - // The byte size of each segment (except for the last one) is max_size. + // The size of each segment (except for the last one) is max_size_in_{elems,bytes}. HeapRootSegments segments = FileMapInfo::current_info()->heap_root_segments(); - int max_size = segments.max_size_in_bytes(); - HeapShared::init_root_segment_sizes(max_size); + HeapShared::init_root_segment_sizes(segments.max_size_in_elems()); intptr_t first_segment_addr = bottom + segments.base_offset(); for (size_t c = 0; c < segments.count(); c++) { - oop segment_oop = cast_to_oop(first_segment_addr + (c * max_size)); + oop segment_oop = cast_to_oop(first_segment_addr + (c * segments.max_size_in_bytes())); assert(segment_oop->is_objArray(), "Must be"); HeapShared::add_root_segment((objArrayOop)segment_oop); } diff --git a/src/hotspot/share/cds/archiveHeapWriter.cpp b/src/hotspot/share/cds/archiveHeapWriter.cpp index 853d459c691..710e693bfdb 100644 --- a/src/hotspot/share/cds/archiveHeapWriter.cpp +++ b/src/hotspot/share/cds/archiveHeapWriter.cpp @@ -223,6 +223,7 @@ void ArchiveHeapWriter::copy_roots_to_buffer(GrowableArrayCHeapat(root_index++)); @@ -245,6 +245,8 @@ void ArchiveHeapWriter::copy_roots_to_buffer(GrowableArrayCHeaplength(), "Post-condition: All roots are handled"); + _heap_root_segments = segments; } diff --git a/src/hotspot/share/cds/archiveUtils.hpp b/src/hotspot/share/cds/archiveUtils.hpp index 2e361ab0c46..5a78bc26ee6 100644 --- a/src/hotspot/share/cds/archiveUtils.hpp +++ b/src/hotspot/share/cds/archiveUtils.hpp @@ -277,7 +277,6 @@ class HeapRootSegments { memset(this, 0, sizeof(*this)); } HeapRootSegments(size_t base_offset, int roots_count, int max_size_in_bytes, int max_size_in_elems) { - assert(is_power_of_2(max_size_in_bytes), "must be"); memset(this, 0, sizeof(*this)); _base_offset = base_offset; _count = (roots_count + max_size_in_elems - 1) / max_size_in_elems; diff --git a/src/hotspot/share/cds/cdsConfig.cpp b/src/hotspot/share/cds/cdsConfig.cpp index a0a562eca21..5915424c4fe 100644 --- a/src/hotspot/share/cds/cdsConfig.cpp +++ b/src/hotspot/share/cds/cdsConfig.cpp @@ -236,7 +236,7 @@ void CDSConfig::init_shared_archive_paths() { } void CDSConfig::check_internal_module_property(const char* key, const char* value) { - if (Arguments::is_internal_module_property(key)) { + if (Arguments::is_internal_module_property(key) && !Arguments::is_module_path_property(key)) { stop_using_optimized_module_handling(); log_info(cds)("optimized module handling: disabled due to incompatible property: %s=%s", key, value); } diff --git a/src/hotspot/share/cds/classListParser.cpp b/src/hotspot/share/cds/classListParser.cpp index f8d24295a12..694a179d7ee 100644 --- a/src/hotspot/share/cds/classListParser.cpp +++ b/src/hotspot/share/cds/classListParser.cpp @@ -508,7 +508,9 @@ InstanceKlass* ClassListParser::load_class_from_source(Symbol* class_name, TRAPS THROW_NULL(vmSymbols::java_lang_ClassNotFoundException()); } - InstanceKlass* k = UnregisteredClasses::load_class(class_name, _source, CHECK_NULL); + ResourceMark rm; + char * source_path = os::strdup_check_oom(ClassLoader::uri_to_path(_source)); + InstanceKlass* k = UnregisteredClasses::load_class(class_name, source_path, CHECK_NULL); if (k->local_interfaces()->length() != _interfaces->length()) { print_specified_interfaces(); print_actual_interfaces(k); diff --git a/src/hotspot/share/cds/classListWriter.cpp b/src/hotspot/share/cds/classListWriter.cpp index 78cd092445b..1b9f589f1c5 100644 --- a/src/hotspot/share/cds/classListWriter.cpp +++ b/src/hotspot/share/cds/classListWriter.cpp @@ -174,6 +174,8 @@ void ClassListWriter::write_to_stream(const InstanceKlass* k, outputStream* stre } } + // NB: the string following "source: " is not really a proper file name, but rather + // a truncated URI referring to a file. It must be decoded after reading. #ifdef _WINDOWS // "file:/C:/dir/foo.jar" -> "C:/dir/foo.jar" stream->print(" source: %s", cfs->source() + 6); diff --git a/src/hotspot/share/cds/filemap.cpp b/src/hotspot/share/cds/filemap.cpp index c935541d7cf..715fce5f3fc 100644 --- a/src/hotspot/share/cds/filemap.cpp +++ b/src/hotspot/share/cds/filemap.cpp @@ -581,7 +581,7 @@ int FileMapInfo::get_module_shared_path_index(Symbol* location) { // skip_uri_protocol was also called during dump time -- see ClassLoaderExt::process_module_table() ResourceMark rm; - const char* file = ClassLoader::skip_uri_protocol(location->as_C_string()); + const char* file = ClassLoader::uri_to_path(location->as_C_string()); for (int i = ClassLoaderExt::app_module_paths_start_index(); i < get_number_of_shared_paths(); i++) { SharedClassPathEntry* ent = shared_path(i); if (!ent->is_non_existent()) { @@ -781,12 +781,12 @@ bool FileMapInfo::check_paths(int shared_path_start_idx, int num_paths, Growable assert(strlen(rp_array->at(i)) > (size_t)runtime_prefix_len, "sanity"); const char* runtime_path = rp_array->at(i) + runtime_prefix_len; if (!os::same_files(dumptime_path, runtime_path)) { - return true; + return false; } i++; j++; } - return false; + return true; } bool FileMapInfo::validate_boot_class_paths() { @@ -810,7 +810,7 @@ bool FileMapInfo::validate_boot_class_paths() { char* rp = skip_first_path_entry(runtime_boot_path); assert(shared_path(0)->is_modules_image(), "first shared_path must be the modules image"); int dp_len = header()->app_class_paths_start_index() - 1; // ignore the first path to the module image - bool mismatch = false; + bool match = true; bool relaxed_check = !header()->has_platform_or_app_classes(); if (dp_len == 0 && rp == nullptr) { @@ -823,7 +823,7 @@ bool FileMapInfo::validate_boot_class_paths() { if (check_paths_existence(rp)) { // If a path exists in the runtime boot paths, it is considered a mismatch // since there's no boot path specified during dump time. - mismatch = true; + match = false; } } } else if (dp_len > 0 && rp != nullptr) { @@ -840,16 +840,16 @@ bool FileMapInfo::validate_boot_class_paths() { // check the full runtime boot path, must match with dump time num = rp_len; } - mismatch = check_paths(1, num, rp_array, 0, 0); + match = check_paths(1, num, rp_array, 0, 0); } else { // create_path_array() ignores non-existing paths. Although the dump time and runtime boot classpath lengths // are the same initially, after the call to create_path_array(), the runtime boot classpath length could become // shorter. We consider boot classpath mismatch in this case. - mismatch = true; + match = false; } } - if (mismatch) { + if (!match) { // The paths are different return classpath_failure("[BOOT classpath mismatch, actual =", runtime_boot_path); } @@ -860,7 +860,7 @@ bool FileMapInfo::validate_app_class_paths(int shared_app_paths_len) { const char *appcp = Arguments::get_appclasspath(); assert(appcp != nullptr, "null app classpath"); int rp_len = num_paths(appcp); - bool mismatch = false; + bool match = false; if (rp_len < shared_app_paths_len) { return classpath_failure("Run time APP classpath is shorter than the one at dump time: ", appcp); } @@ -889,8 +889,8 @@ bool FileMapInfo::validate_app_class_paths(int shared_app_paths_len) { // run 2: -cp x.jar:NE4:b.jar -> x.jar:b.jar -> mismatched int j = header()->app_class_paths_start_index(); - mismatch = check_paths(j, shared_app_paths_len, rp_array, 0, 0); - if (mismatch) { + match = check_paths(j, shared_app_paths_len, rp_array, 0, 0); + if (!match) { // To facilitate app deployment, we allow the JAR files to be moved *together* to // a different location, as long as they are still stored under the same directory // structure. E.g., the following is OK. @@ -901,10 +901,10 @@ bool FileMapInfo::validate_app_class_paths(int shared_app_paths_len) { if (dumptime_prefix_len != 0 || runtime_prefix_len != 0) { log_info(class, path)("LCP length for app classpath (dumptime: %u, runtime: %u)", dumptime_prefix_len, runtime_prefix_len); - mismatch = check_paths(j, shared_app_paths_len, rp_array, + match = check_paths(j, shared_app_paths_len, rp_array, dumptime_prefix_len, runtime_prefix_len); } - if (mismatch) { + if (!match) { return classpath_failure("[APP classpath mismatch, actual: -Djava.class.path=", appcp); } } @@ -926,15 +926,35 @@ void FileMapInfo::log_paths(const char* msg, int start_idx, int end_idx) { } } +void FileMapInfo::extract_module_paths(const char* runtime_path, GrowableArray* module_paths) { + GrowableArray* path_array = create_path_array(runtime_path); + int num_paths = path_array->length(); + for (int i = 0; i < num_paths; i++) { + const char* name = path_array->at(i); + ClassLoaderExt::extract_jar_files_from_path(name, module_paths); + } + // module paths are stored in sorted order in the CDS archive. + module_paths->sort(ClassLoaderExt::compare_module_path_by_name); +} + bool FileMapInfo::check_module_paths() { - const char* rp = Arguments::get_property("jdk.module.path"); - int num_paths = CDSConfig::num_archives(rp); - if (num_paths != header()->num_module_paths()) { + const char* runtime_path = Arguments::get_property("jdk.module.path"); + int archived_num_module_paths = header()->num_module_paths(); + if (runtime_path == nullptr && archived_num_module_paths == 0) { + return true; + } + if ((runtime_path == nullptr && archived_num_module_paths > 0) || + (runtime_path != nullptr && archived_num_module_paths == 0)) { return false; } ResourceMark rm; - GrowableArray* rp_array = create_path_array(rp); - return check_paths(header()->app_module_paths_start_index(), num_paths, rp_array, 0, 0); + GrowableArray* module_paths = new GrowableArray(3); + extract_module_paths(runtime_path, module_paths); + int num_paths = module_paths->length(); + if (num_paths != archived_num_module_paths) { + return false; + } + return check_paths(header()->app_module_paths_start_index(), num_paths, module_paths, 0, 0); } bool FileMapInfo::validate_shared_path_table() { @@ -944,6 +964,16 @@ bool FileMapInfo::validate_shared_path_table() { // Load the shared path table info from the archive header _shared_path_table = header()->shared_path_table(); + + bool matched_module_paths = true; + if (CDSConfig::is_dumping_dynamic_archive() || header()->has_full_module_graph()) { + matched_module_paths = check_module_paths(); + } + if (header()->has_full_module_graph() && !matched_module_paths) { + CDSConfig::stop_using_optimized_module_handling(); + log_info(cds)("optimized module handling: disabled because of mismatched module paths"); + } + if (CDSConfig::is_dumping_dynamic_archive()) { // Only support dynamic dumping with the usage of the default CDS archive // or a simple base archive. @@ -959,7 +989,7 @@ bool FileMapInfo::validate_shared_path_table() { "Dynamic archiving is disabled because base layer archive has appended boot classpath"); } if (header()->num_module_paths() > 0) { - if (!check_module_paths()) { + if (!matched_module_paths) { CDSConfig::disable_dumping_dynamic_archive(); log_warning(cds)( "Dynamic archiving is disabled because base layer archive has a different module path"); diff --git a/src/hotspot/share/cds/filemap.hpp b/src/hotspot/share/cds/filemap.hpp index 1bf2510a335..6650f524408 100644 --- a/src/hotspot/share/cds/filemap.hpp +++ b/src/hotspot/share/cds/filemap.hpp @@ -271,6 +271,7 @@ class FileMapHeader: private CDSFileMapHeaderBase { bool compressed_oops() const { return _compressed_oops; } bool compressed_class_pointers() const { return _compressed_class_ptrs; } HeapRootSegments heap_root_segments() const { return _heap_root_segments; } + bool has_full_module_graph() const { return _has_full_module_graph; } size_t heap_oopmap_start_pos() const { return _heap_oopmap_start_pos; } size_t heap_ptrmap_start_pos() const { return _heap_ptrmap_start_pos; } size_t rw_ptrmap_start_pos() const { return _rw_ptrmap_start_pos; } @@ -554,6 +555,7 @@ class FileMapInfo : public CHeapObj { GrowableArray* rp_array, unsigned int dumptime_prefix_len, unsigned int runtime_prefix_len) NOT_CDS_RETURN_(false); + void extract_module_paths(const char* runtime_path, GrowableArray* module_paths); bool validate_boot_class_paths() NOT_CDS_RETURN_(false); bool validate_app_class_paths(int shared_app_paths_len) NOT_CDS_RETURN_(false); bool map_heap_region_impl() NOT_CDS_JAVA_HEAP_RETURN_(false); diff --git a/src/hotspot/share/cds/heapShared.cpp b/src/hotspot/share/cds/heapShared.cpp index 1fddcb0d81f..81aa7ac94dc 100644 --- a/src/hotspot/share/cds/heapShared.cpp +++ b/src/hotspot/share/cds/heapShared.cpp @@ -33,6 +33,7 @@ #include "cds/heapShared.hpp" #include "cds/metaspaceShared.hpp" #include "classfile/classLoaderData.hpp" +#include "classfile/classLoaderExt.hpp" #include "classfile/javaClasses.inline.hpp" #include "classfile/modules.hpp" #include "classfile/stringTable.hpp" @@ -55,6 +56,7 @@ #include "oops/oop.inline.hpp" #include "oops/typeArrayOop.inline.hpp" #include "prims/jvmtiExport.hpp" +#include "runtime/arguments.hpp" #include "runtime/fieldDescriptor.inline.hpp" #include "runtime/init.hpp" #include "runtime/javaCalls.hpp" @@ -134,8 +136,7 @@ static ArchivableStaticFieldInfo fmg_archive_subgraph_entry_fields[] = { KlassSubGraphInfo* HeapShared::_default_subgraph_info; GrowableArrayCHeap* HeapShared::_pending_roots = nullptr; GrowableArrayCHeap* HeapShared::_root_segments; -int HeapShared::_root_segment_max_size_shift; -int HeapShared::_root_segment_max_size_mask; +int HeapShared::_root_segment_max_size_elems; OopHandle HeapShared::_scratch_basic_type_mirrors[T_VOID+1]; MetaspaceObjToOopHandleTable* HeapShared::_scratch_java_mirror_table = nullptr; MetaspaceObjToOopHandleTable* HeapShared::_scratch_references_table = nullptr; @@ -242,15 +243,29 @@ objArrayOop HeapShared::root_segment(int segment_idx) { return segment; } +void HeapShared::get_segment_indexes(int idx, int& seg_idx, int& int_idx) { + assert(_root_segment_max_size_elems > 0, "sanity"); + + // Try to avoid divisions for the common case. + if (idx < _root_segment_max_size_elems) { + seg_idx = 0; + int_idx = idx; + } else { + seg_idx = idx / _root_segment_max_size_elems; + int_idx = idx % _root_segment_max_size_elems; + } + + assert(idx == seg_idx * _root_segment_max_size_elems + int_idx, + "sanity: %d index maps to %d segment and %d internal", idx, seg_idx, int_idx); +} + // Returns an objArray that contains all the roots of the archived objects oop HeapShared::get_root(int index, bool clear) { - assert(_root_segment_max_size_shift > 0, "sanity"); - assert(_root_segment_max_size_mask > 0, "sanity"); assert(index >= 0, "sanity"); assert(!CDSConfig::is_dumping_heap() && CDSConfig::is_using_archive(), "runtime only"); assert(!_root_segments->is_empty(), "must have loaded shared heap"); - int seg_idx = index >> _root_segment_max_size_shift; - int int_idx = index & _root_segment_max_size_mask; + int seg_idx, int_idx; + get_segment_indexes(index, seg_idx, int_idx); oop result = root_segment(seg_idx)->obj_at(int_idx); if (clear) { clear_root(index); @@ -262,10 +277,8 @@ void HeapShared::clear_root(int index) { assert(index >= 0, "sanity"); assert(CDSConfig::is_using_archive(), "must be"); if (ArchiveHeapLoader::is_in_use()) { - assert(_root_segment_max_size_shift > 0, "sanity"); - assert(_root_segment_max_size_mask > 0, "sanity"); - int seg_idx = index >> _root_segment_max_size_shift; - int int_idx = index & _root_segment_max_size_mask; + int seg_idx, int_idx; + get_segment_indexes(index, seg_idx, int_idx); if (log_is_enabled(Debug, cds, heap)) { oop old = root_segment(seg_idx)->obj_at(int_idx); log_debug(cds, heap)("Clearing root %d: was " PTR_FORMAT, index, p2i(old)); @@ -785,10 +798,8 @@ void HeapShared::add_root_segment(objArrayOop segment_oop) { _root_segments->push(OopHandle(Universe::vm_global(), segment_oop)); } -void HeapShared::init_root_segment_sizes(int max_size) { - assert(is_power_of_2(max_size), "must be"); - _root_segment_max_size_shift = log2i_exact(max_size); - _root_segment_max_size_mask = max_size - 1; +void HeapShared::init_root_segment_sizes(int max_size_elems) { + _root_segment_max_size_elems = max_size_elems; } void HeapShared::serialize_tables(SerializeClosure* soc) { @@ -875,6 +886,17 @@ void HeapShared::initialize_from_archived_subgraph(JavaThread* current, Klass* k return; // nothing to do } + if (k->name()->equals("jdk/internal/module/ArchivedModuleGraph") && + !CDSConfig::is_using_optimized_module_handling() && + // archive was created with --module-path + ClassLoaderExt::num_module_paths() > 0) { + // ArchivedModuleGraph was created with a --module-path that's different than the runtime --module-path. + // Thus, it might contain references to modules that do not exist at runtime. We cannot use it. + log_info(cds, heap)("Skip initializing ArchivedModuleGraph subgraph: is_using_optimized_module_handling=%s num_module_paths=%d", + BOOL_TO_STR(CDSConfig::is_using_optimized_module_handling()), ClassLoaderExt::num_module_paths()); + return; + } + ExceptionMark em(THREAD); const ArchivedKlassSubGraphInfoRecord* record = resolve_or_init_classes_for_subgraph_of(k, /*do_init=*/true, THREAD); @@ -1123,6 +1145,13 @@ bool HeapShared::archive_reachable_objects_from(int level, // these objects that are referenced (directly or indirectly) by static fields. ResourceMark rm; log_error(cds, heap)("Cannot archive object of class %s", orig_obj->klass()->external_name()); + if (log_is_enabled(Trace, cds, heap)) { + WalkOopAndArchiveClosure* walker = WalkOopAndArchiveClosure::current(); + if (walker != nullptr) { + LogStream ls(Log(cds, heap)::trace()); + CDSHeapVerifier::trace_to_root(&ls, walker->referencing_obj()); + } + } MetaspaceShared::unrecoverable_writing_error(); } diff --git a/src/hotspot/share/cds/heapShared.hpp b/src/hotspot/share/cds/heapShared.hpp index 01610ebe64e..01d664945ee 100644 --- a/src/hotspot/share/cds/heapShared.hpp +++ b/src/hotspot/share/cds/heapShared.hpp @@ -291,8 +291,7 @@ class HeapShared: AllStatic { static GrowableArrayCHeap* _pending_roots; static GrowableArrayCHeap* _root_segments; - static int _root_segment_max_size_shift; - static int _root_segment_max_size_mask; + static int _root_segment_max_size_elems; static OopHandle _scratch_basic_type_mirrors[T_VOID+1]; static MetaspaceObjToOopHandleTable* _scratch_java_mirror_table; static MetaspaceObjToOopHandleTable* _scratch_references_table; @@ -407,6 +406,8 @@ class HeapShared: AllStatic { // Run-time only static void clear_root(int index); + static void get_segment_indexes(int index, int& segment_index, int& internal_index); + static void setup_test_class(const char* test_class_name) PRODUCT_RETURN; #endif // INCLUDE_CDS_JAVA_HEAP @@ -425,7 +426,7 @@ class HeapShared: AllStatic { static void init_for_dumping(TRAPS) NOT_CDS_JAVA_HEAP_RETURN; static void write_subgraph_info_table() NOT_CDS_JAVA_HEAP_RETURN; static void add_root_segment(objArrayOop segment_oop) NOT_CDS_JAVA_HEAP_RETURN; - static void init_root_segment_sizes(int max_size) NOT_CDS_JAVA_HEAP_RETURN; + static void init_root_segment_sizes(int max_size_elems) NOT_CDS_JAVA_HEAP_RETURN; static void serialize_tables(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN; #ifndef PRODUCT diff --git a/src/hotspot/share/cds/metaspaceShared.cpp b/src/hotspot/share/cds/metaspaceShared.cpp index c66398cefac..6f646e162ec 100644 --- a/src/hotspot/share/cds/metaspaceShared.cpp +++ b/src/hotspot/share/cds/metaspaceShared.cpp @@ -77,6 +77,7 @@ #include "runtime/globals.hpp" #include "runtime/globals_extension.hpp" #include "runtime/handles.inline.hpp" +#include "runtime/javaCalls.hpp" #include "runtime/os.inline.hpp" #include "runtime/safepointVerifiers.hpp" #include "runtime/sharedRuntime.hpp" @@ -300,6 +301,7 @@ void MetaspaceShared::post_initialize(TRAPS) { } ClassLoaderExt::init_paths_start_index(info->app_class_paths_start_index()); ClassLoaderExt::init_app_module_paths_start_index(info->app_module_paths_start_index()); + ClassLoaderExt::init_num_module_paths(info->header()->num_module_paths()); } } } @@ -791,9 +793,22 @@ void MetaspaceShared::preload_and_dump_impl(StaticArchiveBuilder& builder, TRAPS // Do this at the very end, when no Java code will be executed. Otherwise // some new strings may be added to the intern table. StringTable::allocate_shared_strings_array(CHECK); + } else { + log_info(cds)("Not dumping heap, reset CDSConfig::_is_using_optimized_module_handling"); + CDSConfig::stop_using_optimized_module_handling(); } #endif + // Dummy call to load classes used at CDS runtime + JavaValue result(T_OBJECT); + Handle path_string = java_lang_String::create_from_str("dummy.jar", CHECK); + JavaCalls::call_static(&result, + vmClasses::jdk_internal_loader_ClassLoaders_klass(), + vmSymbols::toFileURL_name(), + vmSymbols::toFileURL_signature(), + path_string, + CHECK); + VM_PopulateDumpSharedSpace op(builder); VMThread::execute(&op); diff --git a/src/hotspot/share/ci/ciEnv.cpp b/src/hotspot/share/ci/ciEnv.cpp index 9caf89628cc..155ce032400 100644 --- a/src/hotspot/share/ci/ciEnv.cpp +++ b/src/hotspot/share/ci/ciEnv.cpp @@ -1616,7 +1616,10 @@ void ciEnv::dump_replay_data_helper(outputStream* out) { for (int i = 0; i < objects->length(); i++) { objects->at(i)->dump_replay_data(out); } - dump_compile_data(out); + + if (this->task() != nullptr) { + dump_compile_data(out); + } out->flush(); } diff --git a/src/hotspot/share/classfile/classLoader.cpp b/src/hotspot/share/classfile/classLoader.cpp index 5309fcd20a8..9a68e264044 100644 --- a/src/hotspot/share/classfile/classLoader.cpp +++ b/src/hotspot/share/classfile/classLoader.cpp @@ -81,6 +81,9 @@ #include "utilities/ostream.hpp" #include "utilities/utf8.hpp" +#include +#include + // Entry point in java.dll for path canonicalization typedef int (*canonicalize_fn_t)(const char *orig, char *out, int len); @@ -579,6 +582,8 @@ void ClassLoader::setup_module_search_path(JavaThread* current, const char* path new_entry = create_class_path_entry(current, path, &st, false /*is_boot_append */, false /* from_class_path_attr */); if (new_entry != nullptr) { + // ClassLoaderExt::process_module_table() filters out non-jar entries before calling this function. + assert(new_entry->is_jar_file(), "module path entry %s is not a jar file", new_entry->name()); add_to_module_path_entries(path, new_entry); } } @@ -1209,7 +1214,7 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, PackageEntry* pkg_entry, bo } #if INCLUDE_CDS -char* ClassLoader::skip_uri_protocol(char* source) { +static const char* skip_uri_protocol(const char* source) { if (strncmp(source, "file:", 5) == 0) { // file: protocol path could start with file:/ or file:/// // locate the char after all the forward slashes @@ -1228,6 +1233,47 @@ char* ClassLoader::skip_uri_protocol(char* source) { return source; } +static char decode_percent_encoded(const char *str, size_t& index) { + if (str[index] == '%' + && isxdigit(str[index + 1]) + && isxdigit(str[index + 2])) { + char hex[3]; + hex[0] = str[index + 1]; + hex[1] = str[index + 2]; + hex[2] = '\0'; + index += 2; + return (char) strtol(hex, NULL, 16); + } + return str[index]; +} + +char* ClassLoader::uri_to_path(const char* uri) { + const size_t len = strlen(uri) + 1; + char* path = NEW_RESOURCE_ARRAY(char, len); + + uri = skip_uri_protocol(uri); + + if (strncmp(uri, "//", 2) == 0) { + // Skip the empty "authority" part + uri += 2; + } + +#ifdef _WINDOWS + if (uri[0] == '/') { + // Absolute path name on Windows does not begin with a slash + uri += 1; + } +#endif + + size_t path_index = 0; + for (size_t i = 0; i < strlen(uri); ++i) { + char decoded = decode_percent_encoded(uri, i); + path[path_index++] = decoded; + } + path[path_index] = '\0'; + return path; +} + // Record the shared classpath index and loader type for classes loaded // by the builtin loaders at dump time. void ClassLoader::record_result(JavaThread* current, InstanceKlass* ik, @@ -1261,7 +1307,7 @@ void ClassLoader::record_result(JavaThread* current, InstanceKlass* ik, // Save the path from the file: protocol or the module name from the jrt: protocol // if no protocol prefix is found, path is the same as stream->source(). This path // must be valid since the class has been successfully parsed. - char* path = skip_uri_protocol(src); + const char* path = ClassLoader::uri_to_path(src); assert(path != nullptr, "sanity"); for (int i = 0; i < FileMapInfo::get_number_of_shared_paths(); i++) { SharedClassPathEntry* ent = FileMapInfo::shared_path(i); diff --git a/src/hotspot/share/classfile/classLoader.hpp b/src/hotspot/share/classfile/classLoader.hpp index af625082dda..e44059b7247 100644 --- a/src/hotspot/share/classfile/classLoader.hpp +++ b/src/hotspot/share/classfile/classLoader.hpp @@ -382,7 +382,7 @@ class ClassLoader: AllStatic { // entries during shared classpath setup time. static int num_module_path_entries(); static void exit_with_path_failure(const char* error, const char* message); - static char* skip_uri_protocol(char* source); + static char* uri_to_path(const char* uri); static void record_result(JavaThread* current, InstanceKlass* ik, const ClassFileStream* stream, bool redefined); #endif diff --git a/src/hotspot/share/classfile/classLoaderExt.cpp b/src/hotspot/share/classfile/classLoaderExt.cpp index 3cd7dd7cd3b..16981669deb 100644 --- a/src/hotspot/share/classfile/classLoaderExt.cpp +++ b/src/hotspot/share/classfile/classLoaderExt.cpp @@ -55,6 +55,7 @@ jshort ClassLoaderExt::_app_class_paths_start_index = ClassLoaderExt::max_classpath_index; jshort ClassLoaderExt::_app_module_paths_start_index = ClassLoaderExt::max_classpath_index; jshort ClassLoaderExt::_max_used_path_index = 0; +int ClassLoaderExt::_num_module_paths = 0; bool ClassLoaderExt::_has_app_classes = false; bool ClassLoaderExt::_has_platform_classes = false; bool ClassLoaderExt::_has_non_jar_in_classpath = false; @@ -89,23 +90,25 @@ void ClassLoaderExt::setup_app_search_path(JavaThread* current) { os::free(app_class_path); } +int ClassLoaderExt::compare_module_path_by_name(const char** p1, const char** p2) { + return strcmp(*p1, *p2); +} + void ClassLoaderExt::process_module_table(JavaThread* current, ModuleEntryTable* met) { ResourceMark rm(current); - GrowableArray* module_paths = new GrowableArray(5); + GrowableArray* module_paths = new GrowableArray(5); class ModulePathsGatherer : public ModuleClosure { JavaThread* _current; - GrowableArray* _module_paths; + GrowableArray* _module_paths; public: - ModulePathsGatherer(JavaThread* current, GrowableArray* module_paths) : + ModulePathsGatherer(JavaThread* current, GrowableArray* module_paths) : _current(current), _module_paths(module_paths) {} void do_module(ModuleEntry* m) { - char* path = m->location()->as_C_string(); - if (strncmp(path, "file:", 5) == 0) { - path = ClassLoader::skip_uri_protocol(path); - char* path_copy = NEW_RESOURCE_ARRAY(char, strlen(path) + 1); - strcpy(path_copy, path); - _module_paths->append(path_copy); + char* uri = m->location()->as_C_string(); + if (strncmp(uri, "file:", 5) == 0) { + char* path = ClassLoader::uri_to_path(uri); + extract_jar_files_from_path(path, _module_paths); } } }; @@ -116,6 +119,10 @@ void ClassLoaderExt::process_module_table(JavaThread* current, ModuleEntryTable* met->modules_do(&gatherer); } + // Sort the module paths before storing into CDS archive for simpler + // checking at runtime. + module_paths->sort(compare_module_path_by_name); + for (int i = 0; i < module_paths->length(); i++) { ClassLoader::setup_module_search_path(current, module_paths->at(i)); } @@ -131,6 +138,38 @@ void ClassLoaderExt::setup_module_paths(JavaThread* current) { process_module_table(current, met); } +bool ClassLoaderExt::has_jar_suffix(const char* filename) { + // In jdk.internal.module.ModulePath.readModule(), it checks for the ".jar" suffix. + // Performing the same check here. + const char* dot = strrchr(filename, '.'); + if (dot != nullptr && strcmp(dot + 1, "jar") == 0) { + return true; + } + return false; +} + +void ClassLoaderExt::extract_jar_files_from_path(const char* path, GrowableArray* module_paths) { + DIR* dirp = os::opendir(path); + if (dirp == nullptr && errno == ENOTDIR && has_jar_suffix(path)) { + module_paths->append(path); + } else { + if (dirp != nullptr) { + struct dirent* dentry; + while ((dentry = os::readdir(dirp)) != nullptr) { + const char* file_name = dentry->d_name; + if (has_jar_suffix(file_name)) { + size_t full_name_len = strlen(path) + strlen(file_name) + strlen(os::file_separator()) + 1; + char* full_name = NEW_RESOURCE_ARRAY(char, full_name_len); + int n = os::snprintf(full_name, full_name_len, "%s%s%s", path, os::file_separator(), file_name); + assert((size_t)n == full_name_len - 1, "Unexpected number of characters in string"); + module_paths->append(full_name); + } + } + os::closedir(dirp); + } + } +} + char* ClassLoaderExt::read_manifest(JavaThread* current, ClassPathEntry* entry, jint *manifest_size, bool clean_text) { const char* name = "META-INF/MANIFEST.MF"; diff --git a/src/hotspot/share/classfile/classLoaderExt.hpp b/src/hotspot/share/classfile/classLoaderExt.hpp index b76ce3ff33a..c3c0b00d55e 100644 --- a/src/hotspot/share/classfile/classLoaderExt.hpp +++ b/src/hotspot/share/classfile/classLoaderExt.hpp @@ -53,12 +53,15 @@ class ClassLoaderExt: public ClassLoader { // AllStatic static jshort _app_module_paths_start_index; // the largest path index being used during CDS dump time static jshort _max_used_path_index; + // number of module paths + static int _num_module_paths; static bool _has_app_classes; static bool _has_platform_classes; static bool _has_non_jar_in_classpath; static char* read_manifest(JavaThread* current, ClassPathEntry* entry, jint *manifest_size, bool clean_text); + static bool has_jar_suffix(const char* filename); public: static void process_jar_manifest(JavaThread* current, ClassPathEntry* entry); @@ -68,6 +71,8 @@ class ClassLoaderExt: public ClassLoader { // AllStatic static void setup_search_paths(JavaThread* current); static void setup_module_paths(JavaThread* current); + static void extract_jar_files_from_path(const char* path, GrowableArray* module_paths); + static int compare_module_path_by_name(const char** p1, const char** p2); static char* read_manifest(JavaThread* current, ClassPathEntry* entry, jint *manifest_size) { // Remove all the new-line continuations (which wrap long lines at 72 characters, see @@ -87,6 +92,8 @@ class ClassLoaderExt: public ClassLoader { // AllStatic static jshort max_used_path_index() { return _max_used_path_index; } + static int num_module_paths() { return _num_module_paths; } + static void set_max_used_path_index(jshort used_index) { _max_used_path_index = used_index; } @@ -99,6 +106,10 @@ class ClassLoaderExt: public ClassLoader { // AllStatic _app_module_paths_start_index = module_start; } + static void init_num_module_paths(int num_module_paths) { + _num_module_paths = num_module_paths; + } + static bool is_boot_classpath(int classpath_index) { return classpath_index < _app_class_paths_start_index; } diff --git a/src/hotspot/share/classfile/javaClasses.cpp b/src/hotspot/share/classfile/javaClasses.cpp index b6ef682ae09..0ad36cd21db 100644 --- a/src/hotspot/share/classfile/javaClasses.cpp +++ b/src/hotspot/share/classfile/javaClasses.cpp @@ -3052,9 +3052,10 @@ void java_lang_ClassFrameInfo::serialize_offsets(SerializeClosure* f) { static int get_flags(const methodHandle& m) { int flags = (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS ); - if (m->is_initializer()) { + if (m->is_object_initializer()) { flags |= java_lang_invoke_MemberName::MN_IS_CONSTRUCTOR; } else { + // Note: Static initializers can be here. Record them as plain methods. flags |= java_lang_invoke_MemberName::MN_IS_METHOD; } if (m->caller_sensitive()) { diff --git a/src/hotspot/share/classfile/systemDictionary.cpp b/src/hotspot/share/classfile/systemDictionary.cpp index bcddddc0c7c..7b307a0b8a3 100644 --- a/src/hotspot/share/classfile/systemDictionary.cpp +++ b/src/hotspot/share/classfile/systemDictionary.cpp @@ -1069,7 +1069,7 @@ bool SystemDictionary::check_shared_class_super_type(InstanceKlass* klass, Insta } Klass *found = resolve_with_circularity_detection(klass->name(), super_type->name(), - class_loader, protection_domain, is_superclass, CHECK_0); + class_loader, protection_domain, is_superclass, CHECK_false); if (found == super_type) { return true; } else { @@ -1088,16 +1088,21 @@ bool SystemDictionary::check_shared_class_super_types(InstanceKlass* ik, Handle // If unexpected superclass or interfaces are found, we cannot // load from the shared archive. - if (ik->super() != nullptr && - !check_shared_class_super_type(ik, InstanceKlass::cast(ik->super()), - class_loader, protection_domain, true, THREAD)) { - return false; + if (ik->super() != nullptr) { + bool check_super = check_shared_class_super_type(ik, InstanceKlass::cast(ik->super()), + class_loader, protection_domain, true, + CHECK_false); + if (!check_super) { + return false; + } } Array* interfaces = ik->local_interfaces(); int num_interfaces = interfaces->length(); for (int index = 0; index < num_interfaces; index++) { - if (!check_shared_class_super_type(ik, interfaces->at(index), class_loader, protection_domain, false, THREAD)) { + bool check_interface = check_shared_class_super_type(ik, interfaces->at(index), class_loader, protection_domain, false, + CHECK_false); + if (!check_interface) { return false; } } @@ -1153,7 +1158,8 @@ InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik, return nullptr; } - if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) { + bool check = check_shared_class_super_types(ik, class_loader, protection_domain, CHECK_NULL); + if (!check) { ik->set_shared_loading_failed(); return nullptr; } diff --git a/src/hotspot/share/classfile/vmIntrinsics.hpp b/src/hotspot/share/classfile/vmIntrinsics.hpp index af1c2b31a98..b6ce21797a6 100644 --- a/src/hotspot/share/classfile/vmIntrinsics.hpp +++ b/src/hotspot/share/classfile/vmIntrinsics.hpp @@ -1008,6 +1008,15 @@ class methodHandle; "Ljdk/internal/vm/vector/VectorSupport$Vector;") \ do_name(vector_shuffle_to_vector_name, "shuffleToVector") \ \ + do_intrinsic(_VectorWrapShuffleIndexes, jdk_internal_vm_vector_VectorSupport, vector_wrap_shuffle_indexes_name, \ + vector_wrap_shuffle_indexes_sig, F_S) \ + do_signature(vector_wrap_shuffle_indexes_sig, "(Ljava/lang/Class;" \ + "Ljava/lang/Class;" \ + "Ljdk/internal/vm/vector/VectorSupport$VectorShuffle;" \ + "ILjdk/internal/vm/vector/VectorSupport$WrapShuffleIndexesOperation;)" \ + "Ljdk/internal/vm/vector/VectorSupport$VectorShuffle;") \ + do_name(vector_wrap_shuffle_indexes_name, "wrapShuffleIndexes") \ + \ do_intrinsic(_VectorLoadOp, jdk_internal_vm_vector_VectorSupport, vector_load_op_name, vector_load_op_sig, F_S) \ do_signature(vector_load_op_sig, "(Ljava/lang/Class;" \ "Ljava/lang/Class;" \ @@ -1129,6 +1138,18 @@ class methodHandle; "Ljdk/internal/vm/vector/VectorSupport$Vector;") \ do_name(vector_rearrange_name, "rearrangeOp") \ \ + do_intrinsic(_VectorSelectFrom, jdk_internal_vm_vector_VectorSupport, vector_select_from_name, vector_select_from_sig, F_S) \ + do_signature(vector_select_from_sig, "(Ljava/lang/Class;" \ + "Ljava/lang/Class;" \ + "Ljava/lang/Class;" \ + "I" \ + "Ljdk/internal/vm/vector/VectorSupport$Vector;" \ + "Ljdk/internal/vm/vector/VectorSupport$Vector;" \ + "Ljdk/internal/vm/vector/VectorSupport$VectorMask;" \ + "Ljdk/internal/vm/vector/VectorSupport$VectorSelectFromOp;)" \ + "Ljdk/internal/vm/vector/VectorSupport$Vector;") \ + do_name(vector_select_from_name, "selectFromOp") \ + \ do_intrinsic(_VectorExtract, jdk_internal_vm_vector_VectorSupport, vector_extract_name, vector_extract_sig, F_S) \ do_signature(vector_extract_sig, "(Ljava/lang/Class;" \ "Ljava/lang/Class;" \ diff --git a/src/hotspot/share/code/compiledIC.cpp b/src/hotspot/share/code/compiledIC.cpp index f142e306a6b..684aee509ee 100644 --- a/src/hotspot/share/code/compiledIC.cpp +++ b/src/hotspot/share/code/compiledIC.cpp @@ -293,7 +293,7 @@ bool CompiledIC::is_monomorphic() const { } bool CompiledIC::is_megamorphic() const { - return VtableStubs::entry_point(destination()) != nullptr;; + return VtableStubs::entry_point(destination()) != nullptr; } bool CompiledIC::is_speculated_klass(Klass* receiver_klass) { diff --git a/src/hotspot/share/code/dependencyContext.cpp b/src/hotspot/share/code/dependencyContext.cpp index d7ce8e92acf..0e6b99d172d 100644 --- a/src/hotspot/share/code/dependencyContext.cpp +++ b/src/hotspot/share/code/dependencyContext.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -227,6 +227,10 @@ void DependencyContext::remove_and_mark_for_deoptimization_all_dependents(Deopti } #ifndef PRODUCT +bool DependencyContext::is_empty() { + return dependencies() == nullptr; +} + void DependencyContext::print_dependent_nmethods(bool verbose) { int idx = 0; for (nmethodBucket* b = dependencies_not_unloading(); b != nullptr; b = b->next_not_unloading()) { diff --git a/src/hotspot/share/code/dependencyContext.hpp b/src/hotspot/share/code/dependencyContext.hpp index e8d2ac41d0d..13b845cb59d 100644 --- a/src/hotspot/share/code/dependencyContext.hpp +++ b/src/hotspot/share/code/dependencyContext.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -124,6 +124,7 @@ class DependencyContext : public StackObj { #ifndef PRODUCT void print_dependent_nmethods(bool verbose); + bool is_empty(); #endif //PRODUCT bool is_dependent_nmethod(nmethod* nm); }; diff --git a/src/hotspot/share/compiler/compilerDefinitions.cpp b/src/hotspot/share/compiler/compilerDefinitions.cpp index ee0c73254f1..7b091d8ade5 100644 --- a/src/hotspot/share/compiler/compilerDefinitions.cpp +++ b/src/hotspot/share/compiler/compilerDefinitions.cpp @@ -497,11 +497,6 @@ bool CompilerConfig::check_args_consistency(bool status) { "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K, min_code_cache_size/K); status = false; - } else if (InlineCacheBufferSize > NonNMethodCodeHeapSize / 2) { - jio_fprintf(defaultStream::error_stream(), - "Invalid InlineCacheBufferSize=" SIZE_FORMAT "K. Must be less than or equal to " SIZE_FORMAT "K.\n", - InlineCacheBufferSize/K, NonNMethodCodeHeapSize/2/K); - status = false; } #ifdef _LP64 diff --git a/src/hotspot/share/compiler/oopMap.inline.hpp b/src/hotspot/share/compiler/oopMap.inline.hpp index f2a3b3ba834..05ef53f8231 100644 --- a/src/hotspot/share/compiler/oopMap.inline.hpp +++ b/src/hotspot/share/compiler/oopMap.inline.hpp @@ -66,12 +66,10 @@ void OopMapDo::iterate_oops_do(const frame continue; #ifndef COMPILER2 - COMPILER1_PRESENT(ShouldNotReachHere();) #if INCLUDE_JVMCI - if (UseJVMCICompiler) { - ShouldNotReachHere(); - } + if (!EnableJVMCI) #endif + ShouldNotReachHere(); #endif // !COMPILER2 address loc = fr->oopmapreg_to_location(omv.reg(), reg_map); diff --git a/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp b/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp index 13b993546cd..8e17d1d2a7a 100644 --- a/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp +++ b/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.cpp @@ -24,49 +24,32 @@ #include "precompiled.hpp" #include "classfile/javaClasses.hpp" +#include "code/vmreg.inline.hpp" #include "gc/g1/c2/g1BarrierSetC2.hpp" #include "gc/g1/g1BarrierSet.hpp" +#include "gc/g1/g1BarrierSetAssembler.hpp" #include "gc/g1/g1BarrierSetRuntime.hpp" #include "gc/g1/g1CardTable.hpp" #include "gc/g1/g1ThreadLocalData.hpp" #include "gc/g1/g1HeapRegion.hpp" #include "opto/arraycopynode.hpp" +#include "opto/block.hpp" #include "opto/compile.hpp" #include "opto/escape.hpp" #include "opto/graphKit.hpp" #include "opto/idealKit.hpp" +#include "opto/machnode.hpp" #include "opto/macro.hpp" +#include "opto/memnode.hpp" +#include "opto/node.hpp" +#include "opto/output.hpp" +#include "opto/regalloc.hpp" #include "opto/rootnode.hpp" +#include "opto/runtime.hpp" #include "opto/type.hpp" +#include "utilities/growableArray.hpp" #include "utilities/macros.hpp" -const TypeFunc *G1BarrierSetC2::write_ref_field_pre_entry_Type() { - const Type **fields = TypeTuple::fields(2); - fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value - fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread - const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); - - // create result type (range) - fields = TypeTuple::fields(0); - const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields); - - return TypeFunc::make(domain, range); -} - -const TypeFunc *G1BarrierSetC2::write_ref_field_post_entry_Type() { - const Type **fields = TypeTuple::fields(2); - fields[TypeFunc::Parms+0] = TypeRawPtr::NOTNULL; // Card addr - fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread - const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields); - - // create result type (range) - fields = TypeTuple::fields(0); - const TypeTuple *range = TypeTuple::make(TypeFunc::Parms, fields); - - return TypeFunc::make(domain, range); -} - -#define __ ideal. /* * Determine if the G1 pre-barrier can be removed. The pre-barrier is * required by SATB to make sure all objects live at the start of the @@ -84,8 +67,6 @@ const TypeFunc *G1BarrierSetC2::write_ref_field_post_entry_Type() { * The compiler needs to determine that the object in which a field is about * to be written is newly allocated, and that no prior store to the same field * has happened since the allocation. - * - * Returns true if the pre-barrier can be removed */ bool G1BarrierSetC2::g1_can_remove_pre_barrier(GraphKit* kit, PhaseValues* phase, @@ -97,34 +78,28 @@ bool G1BarrierSetC2::g1_can_remove_pre_barrier(GraphKit* kit, AllocateNode* alloc = AllocateNode::Ideal_allocation(base); if (offset == Type::OffsetBot) { - return false; // cannot unalias unless there are precise offsets + return false; // Cannot unalias unless there are precise offsets. } - if (alloc == nullptr) { - return false; // No allocation found + return false; // No allocation found. } intptr_t size_in_bytes = type2aelembytes(bt); - - Node* mem = kit->memory(adr_idx); // start searching here... + Node* mem = kit->memory(adr_idx); // Start searching here. for (int cnt = 0; cnt < 50; cnt++) { - if (mem->is_Store()) { - Node* st_adr = mem->in(MemNode::Address); intptr_t st_offset = 0; Node* st_base = AddPNode::Ideal_base_and_offset(st_adr, phase, st_offset); if (st_base == nullptr) { - break; // inscrutable pointer + break; // Inscrutable pointer. } - - // Break we have found a store with same base and offset as ours so break if (st_base == base && st_offset == offset) { + // We have found a store with same base and offset as ours. break; } - if (st_offset != offset && st_offset != Type::OffsetBot) { const int MAX_STORE = BytesPerLong; if (st_offset >= offset + size_in_bytes || @@ -136,20 +111,18 @@ bool G1BarrierSetC2::g1_can_remove_pre_barrier(GraphKit* kit, // in the same sequence of RawMem effects. We sometimes initialize // a whole 'tile' of array elements with a single jint or jlong.) mem = mem->in(MemNode::Memory); - continue; // advance through independent store memory + continue; // Advance through independent store memory. } } - if (st_base != base && MemNode::detect_ptr_independence(base, alloc, st_base, AllocateNode::Ideal_allocation(st_base), phase)) { - // Success: The bases are provably independent. + // Success: the bases are provably independent. mem = mem->in(MemNode::Memory); - continue; // advance through independent store memory + continue; // Advance through independent store memory. } } else if (mem->is_Proj() && mem->in(0)->is_Initialize()) { - InitializeNode* st_init = mem->in(0)->as_Initialize(); AllocateNode* st_alloc = st_init->allocation(); @@ -157,7 +130,7 @@ bool G1BarrierSetC2::g1_can_remove_pre_barrier(GraphKit* kit, // The alloc variable is guaranteed to not be null here from earlier check. if (alloc == st_alloc) { // Check that the initialization is storing null so that no previous store - // has been moved up and directly write a reference + // has been moved up and directly write a reference. Node* captured_store = st_init->find_captured_store(offset, type2aelembytes(T_OBJECT), phase); @@ -166,164 +139,55 @@ bool G1BarrierSetC2::g1_can_remove_pre_barrier(GraphKit* kit, } } } - // Unless there is an explicit 'continue', we must bail out here, // because 'mem' is an inscrutable memory state (e.g., a call). break; } - return false; } -// G1 pre/post barriers -void G1BarrierSetC2::pre_barrier(GraphKit* kit, - bool do_load, - Node* ctl, - Node* obj, - Node* adr, - uint alias_idx, - Node* val, - const TypeOopPtr* val_type, - Node* pre_val, - BasicType bt) const { - // Some sanity checks - // Note: val is unused in this routine. - - if (do_load) { - // We need to generate the load of the previous value - assert(obj != nullptr, "must have a base"); - assert(adr != nullptr, "where are loading from?"); - assert(pre_val == nullptr, "loaded already?"); - assert(val_type != nullptr, "need a type"); - - if (use_ReduceInitialCardMarks() - && g1_can_remove_pre_barrier(kit, &kit->gvn(), adr, bt, alias_idx)) { - return; - } - - } else { - // In this case both val_type and alias_idx are unused. - assert(pre_val != nullptr, "must be loaded already"); - // Nothing to be done if pre_val is null. - if (pre_val->bottom_type() == TypePtr::NULL_PTR) return; - assert(pre_val->bottom_type()->basic_type() == T_OBJECT, "or we shouldn't be here"); - } - assert(bt == T_OBJECT, "or we shouldn't be here"); - - IdealKit ideal(kit, true); - - Node* tls = __ thread(); // ThreadLocalStorage - - Node* no_base = __ top(); - Node* zero = __ ConI(0); - Node* zeroX = __ ConX(0); - - float likely = PROB_LIKELY(0.999); - float unlikely = PROB_UNLIKELY(0.999); - - BasicType active_type = in_bytes(SATBMarkQueue::byte_width_of_active()) == 4 ? T_INT : T_BYTE; - assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 4 || in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "flag width"); - - // Offsets into the thread - const int marking_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()); - const int index_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_index_offset()); - const int buffer_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_buffer_offset()); - - // Now the actual pointers into the thread - Node* marking_adr = __ AddP(no_base, tls, __ ConX(marking_offset)); - Node* buffer_adr = __ AddP(no_base, tls, __ ConX(buffer_offset)); - Node* index_adr = __ AddP(no_base, tls, __ ConX(index_offset)); - - // Now some of the values - Node* marking = __ load(__ ctrl(), marking_adr, TypeInt::INT, active_type, Compile::AliasIdxRaw); - - // if (!marking) - __ if_then(marking, BoolTest::ne, zero, unlikely); { - BasicType index_bt = TypeX_X->basic_type(); - assert(sizeof(size_t) == type2aelembytes(index_bt), "Loading G1 SATBMarkQueue::_index with wrong size."); - Node* index = __ load(__ ctrl(), index_adr, TypeX_X, index_bt, Compile::AliasIdxRaw); - - if (do_load) { - // load original value - pre_val = __ load(__ ctrl(), adr, val_type, bt, alias_idx, false, MemNode::unordered, LoadNode::Pinned); - } - - // if (pre_val != nullptr) - __ if_then(pre_val, BoolTest::ne, kit->null()); { - Node* buffer = __ load(__ ctrl(), buffer_adr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw); - - // is the queue for this thread full? - __ if_then(index, BoolTest::ne, zeroX, likely); { - - // decrement the index - Node* next_index = kit->gvn().transform(new SubXNode(index, __ ConX(sizeof(intptr_t)))); - - // Now get the buffer location we will log the previous value into and store it - Node *log_addr = __ AddP(no_base, buffer, next_index); - __ store(__ ctrl(), log_addr, pre_val, T_OBJECT, Compile::AliasIdxRaw, MemNode::unordered); - // update the index - __ store(__ ctrl(), index_adr, next_index, index_bt, Compile::AliasIdxRaw, MemNode::unordered); - - } __ else_(); { - - // logging buffer is full, call the runtime - const TypeFunc *tf = write_ref_field_pre_entry_Type(); - __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_pre_entry), "write_ref_field_pre_entry", pre_val, tls); - } __ end_if(); // (!index) - } __ end_if(); // (pre_val != nullptr) - } __ end_if(); // (!marking) - - // Final sync IdealKit and GraphKit. - kit->final_sync(ideal); -} - /* - * G1 similar to any GC with a Young Generation requires a way to keep track of - * references from Old Generation to Young Generation to make sure all live + * G1, similar to any GC with a Young Generation, requires a way to keep track + * of references from Old Generation to Young Generation to make sure all live * objects are found. G1 also requires to keep track of object references * between different regions to enable evacuation of old regions, which is done - * as part of mixed collections. References are tracked in remembered sets and - * is continuously updated as reference are written to with the help of the - * post-barrier. + * as part of mixed collections. References are tracked in remembered sets, + * which are continuously updated as references are written to with the help of + * the post-barrier. * - * To reduce the number of updates to the remembered set the post-barrier - * filters updates to fields in objects located in the Young Generation, - * the same region as the reference, when the null is being written or - * if the card is already marked as dirty by an earlier write. + * To reduce the number of updates to the remembered set, the post-barrier + * filters out updates to fields in objects located in the Young Generation, the + * same region as the reference, when null is being written, or if the card is + * already marked as dirty by an earlier write. * * Under certain circumstances it is possible to avoid generating the - * post-barrier completely if it is possible during compile time to prove - * the object is newly allocated and that no safepoint exists between the - * allocation and the store. - * - * In the case of slow allocation the allocation code must handle the barrier - * as part of the allocation in the case the allocated object is not located - * in the nursery; this would happen for humongous objects. + * post-barrier completely, if it is possible during compile time to prove the + * object is newly allocated and that no safepoint exists between the allocation + * and the store. This can be seen as a compile-time version of the + * above-mentioned Young Generation filter. * - * Returns true if the post barrier can be removed + * In the case of a slow allocation, the allocation code must handle the barrier + * as part of the allocation if the allocated object is not located in the + * nursery; this would happen for humongous objects. */ bool G1BarrierSetC2::g1_can_remove_post_barrier(GraphKit* kit, - PhaseValues* phase, Node* store, + PhaseValues* phase, Node* store_ctrl, Node* adr) const { intptr_t offset = 0; Node* base = AddPNode::Ideal_base_and_offset(adr, phase, offset); AllocateNode* alloc = AllocateNode::Ideal_allocation(base); if (offset == Type::OffsetBot) { - return false; // cannot unalias unless there are precise offsets + return false; // Cannot unalias unless there are precise offsets. } - if (alloc == nullptr) { - return false; // No allocation found + return false; // No allocation found. } - // Start search from Store node - Node* mem = store->in(MemNode::Control); + Node* mem = store_ctrl; // Start search from Store node. if (mem->is_Proj() && mem->in(0)->is_Initialize()) { - InitializeNode* st_init = mem->in(0)->as_Initialize(); AllocateNode* st_alloc = st_init->allocation(); - // Make sure we are looking at the same allocation if (alloc == st_alloc) { return true; @@ -333,725 +197,361 @@ bool G1BarrierSetC2::g1_can_remove_post_barrier(GraphKit* kit, return false; } -// -// Update the card table and add card address to the queue -// -void G1BarrierSetC2::g1_mark_card(GraphKit* kit, - IdealKit& ideal, - Node* card_adr, - Node* oop_store, - uint oop_alias_idx, - Node* index, - Node* index_adr, - Node* buffer, - const TypeFunc* tf) const { - Node* zero = __ ConI(0); - Node* zeroX = __ ConX(0); - Node* no_base = __ top(); - BasicType card_bt = T_BYTE; - // Smash zero into card. MUST BE ORDERED WRT TO STORE - __ storeCM(__ ctrl(), card_adr, zero, oop_store, oop_alias_idx, card_bt, Compile::AliasIdxRaw); - - // Now do the queue work - __ if_then(index, BoolTest::ne, zeroX); { - - Node* next_index = kit->gvn().transform(new SubXNode(index, __ ConX(sizeof(intptr_t)))); - Node* log_addr = __ AddP(no_base, buffer, next_index); - - // Order, see storeCM. - __ store(__ ctrl(), log_addr, card_adr, T_ADDRESS, Compile::AliasIdxRaw, MemNode::unordered); - __ store(__ ctrl(), index_adr, next_index, TypeX_X->basic_type(), Compile::AliasIdxRaw, MemNode::unordered); - - } __ else_(); { - __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry), "write_ref_field_post_entry", card_adr, __ thread()); - } __ end_if(); - +Node* G1BarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const { + DecoratorSet decorators = access.decorators(); + bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0; + bool on_phantom = (decorators & ON_PHANTOM_OOP_REF) != 0; + bool no_keepalive = (decorators & AS_NO_KEEPALIVE) != 0; + // If we are reading the value of the referent field of a Reference object, we + // need to record the referent in an SATB log buffer using the pre-barrier + // mechanism. Also we need to add a memory barrier to prevent commoning reads + // from this field across safepoints, since GC can change its value. + bool need_read_barrier = ((on_weak || on_phantom) && !no_keepalive); + if (access.is_oop() && need_read_barrier) { + access.set_barrier_data(G1C2BarrierPre); + } + return CardTableBarrierSetC2::load_at_resolved(access, val_type); } -void G1BarrierSetC2::post_barrier(GraphKit* kit, - Node* ctl, - Node* oop_store, - Node* obj, - Node* adr, - uint alias_idx, - Node* val, - BasicType bt, - bool use_precise) const { - // If we are writing a null then we need no post barrier +void G1BarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const { + eliminate_gc_barrier_data(node); +} - if (val != nullptr && val->is_Con() && val->bottom_type() == TypePtr::NULL_PTR) { - // Must be null - const Type* t = val->bottom_type(); - assert(t == Type::TOP || t == TypePtr::NULL_PTR, "must be null"); - // No post barrier if writing null - return; +void G1BarrierSetC2::eliminate_gc_barrier_data(Node* node) const { + if (node->is_LoadStore()) { + LoadStoreNode* loadstore = node->as_LoadStore(); + loadstore->set_barrier_data(0); + } else if (node->is_Mem()) { + MemNode* mem = node->as_Mem(); + mem->set_barrier_data(0); } +} - if (use_ReduceInitialCardMarks() && obj == kit->just_allocated_object(kit->control())) { - // We can skip marks on a freshly-allocated object in Eden. - // Keep this code in sync with CardTableBarrierSet::on_slowpath_allocation_exit. - // That routine informs GC to take appropriate compensating steps, - // upon a slow-path allocation, so as to make this card-mark - // elision safe. +static void refine_barrier_by_new_val_type(const Node* n) { + if (n->Opcode() != Op_StoreP && + n->Opcode() != Op_StoreN) { return; } - - if (use_ReduceInitialCardMarks() - && g1_can_remove_post_barrier(kit, &kit->gvn(), oop_store, adr)) { + MemNode* store = n->as_Mem(); + const Node* newval = n->in(MemNode::ValueIn); + assert(newval != nullptr, ""); + const Type* newval_bottom = newval->bottom_type(); + TypePtr::PTR newval_type = newval_bottom->make_ptr()->ptr(); + uint8_t barrier_data = store->barrier_data(); + if (!newval_bottom->isa_oopptr() && + !newval_bottom->isa_narrowoop() && + newval_type != TypePtr::Null) { + // newval is neither an OOP nor null, so there is no barrier to refine. + assert(barrier_data == 0, "non-OOP stores should have no barrier data"); return; } - - if (!use_precise) { - // All card marks for a (non-array) instance are in one place: - adr = obj; + if (barrier_data == 0) { + // No barrier to refine. + return; } - // (Else it's an array (or unknown), and we want more precise card marks.) - assert(adr != nullptr, ""); - - IdealKit ideal(kit, true); - - Node* tls = __ thread(); // ThreadLocalStorage - - Node* no_base = __ top(); - float likely = PROB_LIKELY_MAG(3); - float unlikely = PROB_UNLIKELY_MAG(3); - Node* young_card = __ ConI((jint)G1CardTable::g1_young_card_val()); - Node* dirty_card = __ ConI((jint)G1CardTable::dirty_card_val()); - Node* zeroX = __ ConX(0); - - const TypeFunc *tf = write_ref_field_post_entry_Type(); - - // Offsets into the thread - const int index_offset = in_bytes(G1ThreadLocalData::dirty_card_queue_index_offset()); - const int buffer_offset = in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset()); - - // Pointers into the thread - - Node* buffer_adr = __ AddP(no_base, tls, __ ConX(buffer_offset)); - Node* index_adr = __ AddP(no_base, tls, __ ConX(index_offset)); - - // Now some values - // Use ctrl to avoid hoisting these values past a safepoint, which could - // potentially reset these fields in the JavaThread. - Node* index = __ load(__ ctrl(), index_adr, TypeX_X, TypeX_X->basic_type(), Compile::AliasIdxRaw); - Node* buffer = __ load(__ ctrl(), buffer_adr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw); - - // Convert the store obj pointer to an int prior to doing math on it - // Must use ctrl to prevent "integerized oop" existing across safepoint - Node* cast = __ CastPX(__ ctrl(), adr); - - // Divide pointer by card size - Node* card_offset = __ URShiftX( cast, __ ConI(CardTable::card_shift()) ); - - // Combine card table base and card offset - Node* card_adr = __ AddP(no_base, byte_map_base_node(kit), card_offset ); - - // If we know the value being stored does it cross regions? - - if (val != nullptr) { - // Does the store cause us to cross regions? - - // Should be able to do an unsigned compare of region_size instead of - // and extra shift. Do we have an unsigned compare?? - // Node* region_size = __ ConI(1 << G1HeapRegion::LogOfHRGrainBytes); - Node* xor_res = __ URShiftX ( __ XorX( cast, __ CastPX(__ ctrl(), val)), __ ConI(checked_cast(G1HeapRegion::LogOfHRGrainBytes))); - - // if (xor_res == 0) same region so skip - __ if_then(xor_res, BoolTest::ne, zeroX, likely); { - - // No barrier if we are storing a null. - __ if_then(val, BoolTest::ne, kit->null(), likely); { - - // Ok must mark the card if not already dirty - - // load the original value of the card - Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw); - - __ if_then(card_val, BoolTest::ne, young_card, unlikely); { - kit->sync_kit(ideal); - kit->insert_mem_bar(Op_MemBarVolatile, oop_store); - __ sync_kit(kit); - - Node* card_val_reload = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw); - __ if_then(card_val_reload, BoolTest::ne, dirty_card); { - g1_mark_card(kit, ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf); - } __ end_if(); - } __ end_if(); - } __ end_if(); - } __ end_if(); - } else { - // The Object.clone() intrinsic uses this path if !ReduceInitialCardMarks. - // We don't need a barrier here if the destination is a newly allocated object - // in Eden. Otherwise, GC verification breaks because we assume that cards in Eden - // are set to 'g1_young_gen' (see G1CardTable::verify_g1_young_region()). - assert(!use_ReduceInitialCardMarks(), "can only happen with card marking"); - Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw); - __ if_then(card_val, BoolTest::ne, young_card); { - g1_mark_card(kit, ideal, card_adr, oop_store, alias_idx, index, index_adr, buffer, tf); - } __ end_if(); + if (newval_type == TypePtr::Null) { + // Simply elide post-barrier if writing null. + barrier_data &= ~G1C2BarrierPost; + barrier_data &= ~G1C2BarrierPostNotNull; + } else if (((barrier_data & G1C2BarrierPost) != 0) && + newval_type == TypePtr::NotNull) { + // If the post-barrier has not been elided yet (e.g. due to newval being + // freshly allocated), mark it as not-null (simplifies barrier tests and + // compressed OOPs logic). + barrier_data |= G1C2BarrierPostNotNull; } - - // Final sync IdealKit and GraphKit. - kit->final_sync(ideal); + store->set_barrier_data(barrier_data); + return; } -// Helper that guards and inserts a pre-barrier. -void G1BarrierSetC2::insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset, - Node* pre_val, bool need_mem_bar) const { - // We could be accessing the referent field of a reference object. If so, when G1 - // is enabled, we need to log the value in the referent field in an SATB buffer. - // This routine performs some compile time filters and generates suitable - // runtime filters that guard the pre-barrier code. - // Also add memory barrier for non volatile load from the referent field - // to prevent commoning of loads across safepoint. - - // Some compile time checks. - - // If offset is a constant, is it java_lang_ref_Reference::_reference_offset? - const TypeX* otype = offset->find_intptr_t_type(); - if (otype != nullptr && otype->is_con() && - otype->get_con() != java_lang_ref_Reference::referent_offset()) { - // Constant offset but not the reference_offset so just return - return; - } - - // We only need to generate the runtime guards for instances. - const TypeOopPtr* btype = base_oop->bottom_type()->isa_oopptr(); - if (btype != nullptr) { - if (btype->isa_aryptr()) { - // Array type so nothing to do - return; +// Refine (not really expand) G1 barriers by looking at the new value type +// (whether it is necessarily null or necessarily non-null). +bool G1BarrierSetC2::expand_barriers(Compile* C, PhaseIterGVN& igvn) const { + ResourceMark rm; + VectorSet visited; + Node_List worklist; + worklist.push(C->root()); + while (worklist.size() > 0) { + Node* n = worklist.pop(); + if (visited.test_set(n->_idx)) { + continue; } - - const TypeInstPtr* itype = btype->isa_instptr(); - if (itype != nullptr) { - // Can the klass of base_oop be statically determined to be - // _not_ a sub-class of Reference and _not_ Object? - ciKlass* klass = itype->instance_klass(); - if (klass->is_loaded() && - !klass->is_subtype_of(kit->env()->Reference_klass()) && - !kit->env()->Object_klass()->is_subtype_of(klass)) { - return; + refine_barrier_by_new_val_type(n); + for (uint j = 0; j < n->req(); j++) { + Node* in = n->in(j); + if (in != nullptr) { + worklist.push(in); } } } + return false; +} - // The compile time filters did not reject base_oop/offset so - // we need to generate the following runtime filters - // - // if (offset == java_lang_ref_Reference::_reference_offset) { - // if (instance_of(base, java.lang.ref.Reference)) { - // pre_barrier(_, pre_val, ...); +uint G1BarrierSetC2::estimated_barrier_size(const Node* node) const { + // These Ideal node counts are extracted from the pre-matching Ideal graph + // generated when compiling the following method with early barrier expansion: + // static void write(MyObject obj1, Object o) { + // obj1.o1 = o; // } - // } - - float likely = PROB_LIKELY( 0.999); - float unlikely = PROB_UNLIKELY(0.999); - - IdealKit ideal(kit); - - Node* referent_off = __ ConX(java_lang_ref_Reference::referent_offset()); - - __ if_then(offset, BoolTest::eq, referent_off, unlikely); { - // Update graphKit memory and control from IdealKit. - kit->sync_kit(ideal); - - Node* ref_klass_con = kit->makecon(TypeKlassPtr::make(kit->env()->Reference_klass())); - Node* is_instof = kit->gen_instanceof(base_oop, ref_klass_con); - - // Update IdealKit memory and control from graphKit. - __ sync_kit(kit); - - Node* one = __ ConI(1); - // is_instof == 0 if base_oop == nullptr - __ if_then(is_instof, BoolTest::eq, one, unlikely); { - - // Update graphKit from IdeakKit. - kit->sync_kit(ideal); - - // Use the pre-barrier to record the value in the referent field - pre_barrier(kit, false /* do_load */, - __ ctrl(), - nullptr /* obj */, nullptr /* adr */, max_juint /* alias_idx */, nullptr /* val */, nullptr /* val_type */, - pre_val /* pre_val */, - T_OBJECT); - if (need_mem_bar) { - // Add memory barrier to prevent commoning reads from this field - // across safepoint since GC can change its value. - kit->insert_mem_bar(Op_MemBarCPUOrder); - } - // Update IdealKit from graphKit. - __ sync_kit(kit); - - } __ end_if(); // _ref_type != ref_none - } __ end_if(); // offset == referent_offset + uint8_t barrier_data = MemNode::barrier_data(node); + uint nodes = 0; + if ((barrier_data & G1C2BarrierPre) != 0) { + nodes += 50; + } + if ((barrier_data & G1C2BarrierPost) != 0) { + nodes += 60; + } + return nodes; +} - // Final sync IdealKit and GraphKit. - kit->final_sync(ideal); +bool G1BarrierSetC2::can_initialize_object(const StoreNode* store) const { + assert(store->Opcode() == Op_StoreP || store->Opcode() == Op_StoreN, "OOP store expected"); + // It is OK to move the store across the object initialization boundary only + // if it does not have any barrier, or if it has barriers that can be safely + // elided (because of the compensation steps taken on the allocation slow path + // when ReduceInitialCardMarks is enabled). + return (MemNode::barrier_data(store) == 0) || use_ReduceInitialCardMarks(); } -#undef __ +void G1BarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const { + if (ac->is_clone_inst() && !use_ReduceInitialCardMarks()) { + clone_in_runtime(phase, ac, G1BarrierSetRuntime::clone_addr(), "G1BarrierSetRuntime::clone"); + return; + } + BarrierSetC2::clone_at_expansion(phase, ac); +} -Node* G1BarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const { +Node* G1BarrierSetC2::store_at_resolved(C2Access& access, C2AccessValue& val) const { DecoratorSet decorators = access.decorators(); - Node* adr = access.addr().node(); - Node* obj = access.base(); - - bool anonymous = (decorators & C2_UNSAFE_ACCESS) != 0; - bool mismatched = (decorators & C2_MISMATCHED) != 0; - bool unknown = (decorators & ON_UNKNOWN_OOP_REF) != 0; + bool anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0; bool in_heap = (decorators & IN_HEAP) != 0; - bool in_native = (decorators & IN_NATIVE) != 0; - bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0; - bool on_phantom = (decorators & ON_PHANTOM_OOP_REF) != 0; - bool is_unordered = (decorators & MO_UNORDERED) != 0; - bool no_keepalive = (decorators & AS_NO_KEEPALIVE) != 0; - bool is_mixed = !in_heap && !in_native; - bool need_cpu_mem_bar = !is_unordered || mismatched || is_mixed; - - Node* top = Compile::current()->top(); - Node* offset = adr->is_AddP() ? adr->in(AddPNode::Offset) : top; - - // If we are reading the value of the referent field of a Reference - // object (either by using Unsafe directly or through reflection) - // then, if G1 is enabled, we need to record the referent in an - // SATB log buffer using the pre-barrier mechanism. - // Also we need to add memory barrier to prevent commoning reads - // from this field across safepoint since GC can change its value. - bool need_read_barrier = (((on_weak || on_phantom) && !no_keepalive) || - (in_heap && unknown && offset != top && obj != top)); + bool tightly_coupled_alloc = (decorators & C2_TIGHTLY_COUPLED_ALLOC) != 0; + bool need_store_barrier = !(tightly_coupled_alloc && use_ReduceInitialCardMarks()) && (in_heap || anonymous); + if (access.is_oop() && need_store_barrier) { + access.set_barrier_data(get_store_barrier(access)); + if (tightly_coupled_alloc) { + assert(!use_ReduceInitialCardMarks(), + "post-barriers are only needed for tightly-coupled initialization stores when ReduceInitialCardMarks is disabled"); + access.set_barrier_data(access.barrier_data() ^ G1C2BarrierPre); + } + } + return BarrierSetC2::store_at_resolved(access, val); +} - if (!access.is_oop() || !need_read_barrier) { - return CardTableBarrierSetC2::load_at_resolved(access, val_type); +Node* G1BarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val, + Node* new_val, const Type* value_type) const { + GraphKit* kit = access.kit(); + if (!access.is_oop()) { + return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type); } + access.set_barrier_data(G1C2BarrierPre | G1C2BarrierPost); + return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type); +} - assert(access.is_parse_access(), "entry not supported at optimization time"); +Node* G1BarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val, + Node* new_val, const Type* value_type) const { + GraphKit* kit = access.kit(); + if (!access.is_oop()) { + return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type); + } + access.set_barrier_data(G1C2BarrierPre | G1C2BarrierPost); + return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type); +} - C2ParseAccess& parse_access = static_cast(access); - GraphKit* kit = parse_access.kit(); - Node* load; +Node* G1BarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const { + GraphKit* kit = access.kit(); + if (!access.is_oop()) { + return BarrierSetC2::atomic_xchg_at_resolved(access, new_val, value_type); + } + access.set_barrier_data(G1C2BarrierPre | G1C2BarrierPost); + return BarrierSetC2::atomic_xchg_at_resolved(access, new_val, value_type); +} - Node* control = kit->control(); - const TypePtr* adr_type = access.addr().type(); - MemNode::MemOrd mo = access.mem_node_mo(); - bool requires_atomic_access = (decorators & MO_UNORDERED) == 0; - bool unaligned = (decorators & C2_UNALIGNED) != 0; - bool unsafe = (decorators & C2_UNSAFE_ACCESS) != 0; - // Pinned control dependency is the strictest. So it's ok to substitute it for any other. - load = kit->make_load(control, adr, val_type, access.type(), adr_type, mo, - LoadNode::Pinned, requires_atomic_access, unaligned, mismatched, unsafe, - access.barrier_data()); +class G1BarrierSetC2State : public BarrierSetC2State { +private: + GrowableArray* _stubs; +public: + G1BarrierSetC2State(Arena* arena) + : BarrierSetC2State(arena), + _stubs(new (arena) GrowableArray(arena, 8, 0, nullptr)) {} - if (on_weak || on_phantom) { - // Use the pre-barrier to record the value in the referent field - pre_barrier(kit, false /* do_load */, - kit->control(), - nullptr /* obj */, nullptr /* adr */, max_juint /* alias_idx */, nullptr /* val */, nullptr /* val_type */, - load /* pre_val */, T_OBJECT); - // Add memory barrier to prevent commoning reads from this field - // across safepoint since GC can change its value. - kit->insert_mem_bar(Op_MemBarCPUOrder); - } else if (unknown) { - // We do not require a mem bar inside pre_barrier if need_mem_bar - // is set: the barriers would be emitted by us. - insert_pre_barrier(kit, obj, offset, load, !need_cpu_mem_bar); + GrowableArray* stubs() { + return _stubs; } - return load; -} - -bool G1BarrierSetC2::is_gc_barrier_node(Node* node) const { - if (CardTableBarrierSetC2::is_gc_barrier_node(node)) { - return true; + bool needs_liveness_data(const MachNode* mach) const { + return G1PreBarrierStubC2::needs_barrier(mach) || + G1PostBarrierStubC2::needs_barrier(mach); } - if (node->Opcode() != Op_CallLeaf) { - return false; - } - CallLeafNode *call = node->as_CallLeaf(); - if (call->_name == nullptr) { + + bool needs_livein_data() const { return false; } +}; - return strcmp(call->_name, "write_ref_field_pre_entry") == 0 || strcmp(call->_name, "write_ref_field_post_entry") == 0; +static G1BarrierSetC2State* barrier_set_state() { + return reinterpret_cast(Compile::current()->barrier_set_state()); } -bool G1BarrierSetC2::is_g1_pre_val_load(Node* n) { - if (n->is_Load() && n->as_Load()->has_pinned_control_dependency()) { - // Make sure the only users of it are: CmpP, StoreP, and a call to write_ref_field_pre_entry +G1BarrierStubC2::G1BarrierStubC2(const MachNode* node) : BarrierStubC2(node) {} - // Skip possible decode - if (n->outcnt() == 1 && n->unique_out()->is_DecodeN()) { - n = n->unique_out(); - } +G1PreBarrierStubC2::G1PreBarrierStubC2(const MachNode* node) : G1BarrierStubC2(node) {} - if (n->outcnt() == 3) { - int found = 0; - for (SimpleDUIterator iter(n); iter.has_next(); iter.next()) { - Node* use = iter.get(); - if (use->is_Cmp() || use->is_Store()) { - ++found; - } else if (use->is_CallLeaf()) { - CallLeafNode* call = use->as_CallLeaf(); - if (strcmp(call->_name, "write_ref_field_pre_entry") == 0) { - ++found; - } - } - } - if (found == 3) { - return true; - } - } +bool G1PreBarrierStubC2::needs_barrier(const MachNode* node) { + return (node->barrier_data() & G1C2BarrierPre) != 0; +} + +G1PreBarrierStubC2* G1PreBarrierStubC2::create(const MachNode* node) { + G1PreBarrierStubC2* const stub = new (Compile::current()->comp_arena()) G1PreBarrierStubC2(node); + if (!Compile::current()->output()->in_scratch_emit_size()) { + barrier_set_state()->stubs()->append(stub); } - return false; + return stub; } -bool G1BarrierSetC2::is_gc_pre_barrier_node(Node *node) const { - return is_g1_pre_val_load(node); +void G1PreBarrierStubC2::initialize_registers(Register obj, Register pre_val, Register thread, Register tmp1, Register tmp2) { + _obj = obj; + _pre_val = pre_val; + _thread = thread; + _tmp1 = tmp1; + _tmp2 = tmp2; } -void G1BarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const { - if (is_g1_pre_val_load(node)) { - macro->replace_node(node, macro->zerocon(node->as_Load()->bottom_type()->basic_type())); - } else { - assert(node->Opcode() == Op_CastP2X, "ConvP2XNode required"); - assert(node->outcnt() <= 2, "expects 1 or 2 users: Xor and URShift nodes"); - // It could be only one user, URShift node, in Object.clone() intrinsic - // but the new allocation is passed to arraycopy stub and it could not - // be scalar replaced. So we don't check the case. +Register G1PreBarrierStubC2::obj() const { + return _obj; +} - // An other case of only one user (Xor) is when the value check for null - // in G1 post barrier is folded after CCP so the code which used URShift - // is removed. +Register G1PreBarrierStubC2::pre_val() const { + return _pre_val; +} - // Take Region node before eliminating post barrier since it also - // eliminates CastP2X node when it has only one user. - Node* this_region = node->in(0); - assert(this_region != nullptr, ""); +Register G1PreBarrierStubC2::thread() const { + return _thread; +} - // Remove G1 post barrier. +Register G1PreBarrierStubC2::tmp1() const { + return _tmp1; +} + +Register G1PreBarrierStubC2::tmp2() const { + return _tmp2; +} - // Search for CastP2X->Xor->URShift->Cmp path which - // checks if the store done to a different from the value's region. - // And replace Cmp with #0 (false) to collapse G1 post barrier. - Node* xorx = node->find_out_with(Op_XorX); - if (xorx != nullptr) { - Node* shift = xorx->unique_out(); - Node* cmpx = shift->unique_out(); - assert(cmpx->is_Cmp() && cmpx->unique_out()->is_Bool() && - cmpx->unique_out()->as_Bool()->_test._test == BoolTest::ne, - "missing region check in G1 post barrier"); - macro->replace_node(cmpx, macro->makecon(TypeInt::CC_EQ)); +void G1PreBarrierStubC2::emit_code(MacroAssembler& masm) { + G1BarrierSetAssembler* bs = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + bs->generate_c2_pre_barrier_stub(&masm, this); +} - // Remove G1 pre barrier. +G1PostBarrierStubC2::G1PostBarrierStubC2(const MachNode* node) : G1BarrierStubC2(node) {} - // Search "if (marking != 0)" check and set it to "false". - // There is no G1 pre barrier if previous stored value is null - // (for example, after initialization). - if (this_region->is_Region() && this_region->req() == 3) { - int ind = 1; - if (!this_region->in(ind)->is_IfFalse()) { - ind = 2; - } - if (this_region->in(ind)->is_IfFalse() && - this_region->in(ind)->in(0)->Opcode() == Op_If) { - Node* bol = this_region->in(ind)->in(0)->in(1); - assert(bol->is_Bool(), ""); - cmpx = bol->in(1); - if (bol->as_Bool()->_test._test == BoolTest::ne && - cmpx->is_Cmp() && cmpx->in(2) == macro->intcon(0) && - cmpx->in(1)->is_Load()) { - Node* adr = cmpx->in(1)->as_Load()->in(MemNode::Address); - const int marking_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()); - if (adr->is_AddP() && adr->in(AddPNode::Base) == macro->top() && - adr->in(AddPNode::Address)->Opcode() == Op_ThreadLocal && - adr->in(AddPNode::Offset) == macro->MakeConX(marking_offset)) { - macro->replace_node(cmpx, macro->makecon(TypeInt::CC_EQ)); - } - } - } - } - } else { - assert(!use_ReduceInitialCardMarks(), "can only happen with card marking"); - // This is a G1 post barrier emitted by the Object.clone() intrinsic. - // Search for the CastP2X->URShiftX->AddP->LoadB->Cmp path which checks if the card - // is marked as young_gen and replace the Cmp with 0 (false) to collapse the barrier. - Node* shift = node->find_out_with(Op_URShiftX); - assert(shift != nullptr, "missing G1 post barrier"); - Node* addp = shift->unique_out(); - Node* load = addp->find_out_with(Op_LoadB); - assert(load != nullptr, "missing G1 post barrier"); - Node* cmpx = load->unique_out(); - assert(cmpx->is_Cmp() && cmpx->unique_out()->is_Bool() && - cmpx->unique_out()->as_Bool()->_test._test == BoolTest::ne, - "missing card value check in G1 post barrier"); - macro->replace_node(cmpx, macro->makecon(TypeInt::CC_EQ)); - // There is no G1 pre barrier in this case - } - // Now CastP2X can be removed since it is used only on dead path - // which currently still alive until igvn optimize it. - assert(node->outcnt() == 0 || node->unique_out()->Opcode() == Op_URShiftX, ""); - macro->replace_node(node, macro->top()); - } +bool G1PostBarrierStubC2::needs_barrier(const MachNode* node) { + return (node->barrier_data() & G1C2BarrierPost) != 0; } -Node* G1BarrierSetC2::step_over_gc_barrier(Node* c) const { - if (!use_ReduceInitialCardMarks() && - c != nullptr && c->is_Region() && c->req() == 3) { - for (uint i = 1; i < c->req(); i++) { - if (c->in(i) != nullptr && c->in(i)->is_Region() && - c->in(i)->req() == 3) { - Node* r = c->in(i); - for (uint j = 1; j < r->req(); j++) { - if (r->in(j) != nullptr && r->in(j)->is_Proj() && - r->in(j)->in(0) != nullptr && - r->in(j)->in(0)->Opcode() == Op_CallLeaf && - r->in(j)->in(0)->as_Call()->entry_point() == CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_field_post_entry)) { - Node* call = r->in(j)->in(0); - c = c->in(i == 1 ? 2 : 1); - if (c != nullptr && c->Opcode() != Op_Parm) { - c = c->in(0); - if (c != nullptr) { - c = c->in(0); - assert(call->in(0) == nullptr || - call->in(0)->in(0) == nullptr || - call->in(0)->in(0)->in(0) == nullptr || - call->in(0)->in(0)->in(0)->in(0) == nullptr || - call->in(0)->in(0)->in(0)->in(0)->in(0) == nullptr || - c == call->in(0)->in(0)->in(0)->in(0)->in(0), "bad barrier shape"); - return c; - } - } - } - } - } - } +G1PostBarrierStubC2* G1PostBarrierStubC2::create(const MachNode* node) { + G1PostBarrierStubC2* const stub = new (Compile::current()->comp_arena()) G1PostBarrierStubC2(node); + if (!Compile::current()->output()->in_scratch_emit_size()) { + barrier_set_state()->stubs()->append(stub); } - return c; + return stub; } -#ifdef ASSERT -bool G1BarrierSetC2::has_cas_in_use_chain(Node *n) const { - Unique_Node_List visited; - Node_List worklist; - worklist.push(n); - while (worklist.size() > 0) { - Node* x = worklist.pop(); - if (visited.member(x)) { - continue; - } else { - visited.push(x); - } +void G1PostBarrierStubC2::initialize_registers(Register thread, Register tmp1, Register tmp2, Register tmp3) { + _thread = thread; + _tmp1 = tmp1; + _tmp2 = tmp2; + _tmp3 = tmp3; +} - if (x->is_LoadStore()) { - int op = x->Opcode(); - if (op == Op_CompareAndExchangeP || op == Op_CompareAndExchangeN || - op == Op_CompareAndSwapP || op == Op_CompareAndSwapN || - op == Op_WeakCompareAndSwapP || op == Op_WeakCompareAndSwapN) { - return true; - } - } - if (!x->is_CFG()) { - for (SimpleDUIterator iter(x); iter.has_next(); iter.next()) { - Node* use = iter.get(); - worklist.push(use); - } - } - } - return false; +Register G1PostBarrierStubC2::thread() const { + return _thread; } -void G1BarrierSetC2::verify_pre_load(Node* marking_if, Unique_Node_List& loads /*output*/) const { - assert(loads.size() == 0, "Loads list should be empty"); - Node* pre_val_if = marking_if->find_out_with(Op_IfTrue)->find_out_with(Op_If); - if (pre_val_if != nullptr) { - Unique_Node_List visited; - Node_List worklist; - Node* pre_val = pre_val_if->in(1)->in(1)->in(1); +Register G1PostBarrierStubC2::tmp1() const { + return _tmp1; +} - worklist.push(pre_val); - while (worklist.size() > 0) { - Node* x = worklist.pop(); - if (visited.member(x)) { - continue; - } else { - visited.push(x); - } +Register G1PostBarrierStubC2::tmp2() const { + return _tmp2; +} - if (has_cas_in_use_chain(x)) { - loads.clear(); - return; - } +Register G1PostBarrierStubC2::tmp3() const { + return _tmp3; +} - if (x->is_Con()) { - continue; - } - if (x->is_EncodeP() || x->is_DecodeN()) { - worklist.push(x->in(1)); - continue; - } - if (x->is_Load() || x->is_LoadStore()) { - assert(x->in(0) != nullptr, "Pre-val load has to have a control"); - loads.push(x); - continue; - } - if (x->is_Phi()) { - for (uint i = 1; i < x->req(); i++) { - worklist.push(x->in(i)); - } - continue; - } - assert(false, "Pre-val anomaly"); - } - } +void G1PostBarrierStubC2::emit_code(MacroAssembler& masm) { + G1BarrierSetAssembler* bs = static_cast(BarrierSet::barrier_set()->barrier_set_assembler()); + bs->generate_c2_post_barrier_stub(&masm, this); } -void G1BarrierSetC2::verify_no_safepoints(Compile* compile, Node* marking_check_if, const Unique_Node_List& loads) const { - if (loads.size() == 0) { - return; - } +void* G1BarrierSetC2::create_barrier_state(Arena* comp_arena) const { + return new (comp_arena) G1BarrierSetC2State(comp_arena); +} - if (loads.size() == 1) { // Handle the typical situation when there a single pre-value load - // that is dominated by the marking_check_if, that's true when the - // barrier itself does the pre-val load. - Node *pre_val = loads.at(0); - if (pre_val->in(0)->in(0) == marking_check_if) { // IfTrue->If - return; - } +int G1BarrierSetC2::get_store_barrier(C2Access& access) const { + if (!access.is_parse_access()) { + // Only support for eliding barriers at parse time for now. + return G1C2BarrierPre | G1C2BarrierPost; } - - // All other cases are when pre-value loads dominate the marking check. - Unique_Node_List controls; - for (uint i = 0; i < loads.size(); i++) { - Node *c = loads.at(i)->in(0); - controls.push(c); + GraphKit* kit = (static_cast(access)).kit(); + Node* ctl = kit->control(); + Node* adr = access.addr().node(); + uint adr_idx = kit->C->get_alias_index(access.addr().type()); + assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory"); + + bool can_remove_pre_barrier = g1_can_remove_pre_barrier(kit, &kit->gvn(), adr, access.type(), adr_idx); + + // We can skip marks on a freshly-allocated object in Eden. Keep this code in + // sync with CardTableBarrierSet::on_slowpath_allocation_exit. That routine + // informs GC to take appropriate compensating steps, upon a slow-path + // allocation, so as to make this card-mark elision safe. + // The post-barrier can also be removed if null is written. This case is + // handled by G1BarrierSetC2::expand_barriers, which runs at the end of C2's + // platform-independent optimizations to exploit stronger type information. + bool can_remove_post_barrier = use_ReduceInitialCardMarks() && + ((access.base() == kit->just_allocated_object(ctl)) || + g1_can_remove_post_barrier(kit, &kit->gvn(), ctl, adr)); + + int barriers = 0; + if (!can_remove_pre_barrier) { + barriers |= G1C2BarrierPre; + } + if (!can_remove_post_barrier) { + barriers |= G1C2BarrierPost; } - Unique_Node_List visited; - Unique_Node_List safepoints; - Node_List worklist; - uint found = 0; + return barriers; +} - worklist.push(marking_check_if); - while (worklist.size() > 0 && found < controls.size()) { - Node* x = worklist.pop(); - if (x == nullptr || x == compile->top()) continue; - if (visited.member(x)) { - continue; - } else { - visited.push(x); - } +void G1BarrierSetC2::late_barrier_analysis() const { + compute_liveness_at_stubs(); +} - if (controls.member(x)) { - found++; - } - if (x->is_Region()) { - for (uint i = 1; i < x->req(); i++) { - worklist.push(x->in(i)); - } - } else { - if (!x->is_SafePoint()) { - worklist.push(x->in(0)); - } else { - safepoints.push(x); - } +void G1BarrierSetC2::emit_stubs(CodeBuffer& cb) const { + MacroAssembler masm(&cb); + GrowableArray* const stubs = barrier_set_state()->stubs(); + for (int i = 0; i < stubs->length(); i++) { + // Make sure there is enough space in the code buffer + if (cb.insts()->maybe_expand_to_ensure_remaining(PhaseOutput::MAX_inst_size) && cb.blob() == nullptr) { + ciEnv::current()->record_failure("CodeCache is full"); + return; } + stubs->at(i)->emit_code(masm); } - assert(found == controls.size(), "Pre-barrier structure anomaly or possible safepoint"); + masm.flush(); } -void G1BarrierSetC2::verify_gc_barriers(Compile* compile, CompilePhase phase) const { - if (phase != BarrierSetC2::BeforeCodeGen) { - return; +#ifndef PRODUCT +void G1BarrierSetC2::dump_barrier_data(const MachNode* mach, outputStream* st) const { + if ((mach->barrier_data() & G1C2BarrierPre) != 0) { + st->print("pre "); } - // Verify G1 pre-barriers - const int marking_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_active_offset()); - - Unique_Node_List visited; - Node_List worklist; - // We're going to walk control flow backwards starting from the Root - worklist.push(compile->root()); - while (worklist.size() > 0) { - Node* x = worklist.pop(); - if (x == nullptr || x == compile->top()) continue; - if (visited.member(x)) { - continue; - } else { - visited.push(x); - } - - if (x->is_Region()) { - for (uint i = 1; i < x->req(); i++) { - worklist.push(x->in(i)); - } - } else { - worklist.push(x->in(0)); - // We are looking for the pattern: - // /->ThreadLocal - // If->Bool->CmpI->LoadB->AddP->ConL(marking_offset) - // \->ConI(0) - // We want to verify that the If and the LoadB have the same control - // See GraphKit::g1_write_barrier_pre() - if (x->is_If()) { - IfNode *iff = x->as_If(); - if (iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp()) { - CmpNode *cmp = iff->in(1)->in(1)->as_Cmp(); - if (cmp->Opcode() == Op_CmpI && cmp->in(2)->is_Con() && cmp->in(2)->bottom_type()->is_int()->get_con() == 0 - && cmp->in(1)->is_Load()) { - LoadNode* load = cmp->in(1)->as_Load(); - if (load->Opcode() == Op_LoadB && load->in(2)->is_AddP() && load->in(2)->in(2)->Opcode() == Op_ThreadLocal - && load->in(2)->in(3)->is_Con() - && load->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == marking_offset) { - - Node* if_ctrl = iff->in(0); - Node* load_ctrl = load->in(0); - - if (if_ctrl != load_ctrl) { - // Skip possible CProj->NeverBranch in infinite loops - if ((if_ctrl->is_Proj() && if_ctrl->Opcode() == Op_CProj) - && if_ctrl->in(0)->is_NeverBranch()) { - if_ctrl = if_ctrl->in(0)->in(0); - } - } - assert(load_ctrl != nullptr && if_ctrl == load_ctrl, "controls must match"); - - Unique_Node_List loads; - verify_pre_load(iff, loads); - verify_no_safepoints(compile, iff, loads); - } - } - } - } - } + if ((mach->barrier_data() & G1C2BarrierPost) != 0) { + st->print("post "); } -} -#endif - -bool G1BarrierSetC2::escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const { - if (opcode == Op_StoreP) { - Node* adr = n->in(MemNode::Address); - const Type* adr_type = gvn->type(adr); - // Pointer stores in G1 barriers looks like unsafe access. - // Ignore such stores to be able scalar replace non-escaping - // allocations. - if (adr_type->isa_rawptr() && adr->is_AddP()) { - Node* base = conn_graph->get_addp_base(adr); - if (base->Opcode() == Op_LoadP && - base->in(MemNode::Address)->is_AddP()) { - adr = base->in(MemNode::Address); - Node* tls = conn_graph->get_addp_base(adr); - if (tls->Opcode() == Op_ThreadLocal) { - int offs = (int) gvn->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot); - const int buf_offset = in_bytes(G1ThreadLocalData::satb_mark_queue_buffer_offset()); - if (offs == buf_offset) { - return true; // G1 pre barrier previous oop value store. - } - if (offs == in_bytes(G1ThreadLocalData::dirty_card_queue_buffer_offset())) { - return true; // G1 post barrier card address store. - } - } - } - } + if ((mach->barrier_data() & G1C2BarrierPostNotNull) != 0) { + st->print("notnull "); } - return false; } +#endif // !PRODUCT diff --git a/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.hpp b/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.hpp index c445a87d2e4..dc333d8c331 100644 --- a/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.hpp +++ b/src/hotspot/share/gc/g1/c2/g1BarrierSetC2.hpp @@ -31,29 +31,62 @@ class PhaseTransform; class Type; class TypeFunc; -class G1BarrierSetC2: public CardTableBarrierSetC2 { +const int G1C2BarrierPre = 1; +const int G1C2BarrierPost = 2; +const int G1C2BarrierPostNotNull = 4; + +class G1BarrierStubC2 : public BarrierStubC2 { +public: + G1BarrierStubC2(const MachNode* node); + virtual void emit_code(MacroAssembler& masm) = 0; +}; + +class G1PreBarrierStubC2 : public G1BarrierStubC2 { +private: + Register _obj; + Register _pre_val; + Register _thread; + Register _tmp1; + Register _tmp2; + +protected: + G1PreBarrierStubC2(const MachNode* node); + +public: + static bool needs_barrier(const MachNode* node); + static G1PreBarrierStubC2* create(const MachNode* node); + void initialize_registers(Register obj, Register pre_val, Register thread, Register tmp1 = noreg, Register tmp2 = noreg); + Register obj() const; + Register pre_val() const; + Register thread() const; + Register tmp1() const; + Register tmp2() const; + virtual void emit_code(MacroAssembler& masm); +}; + +class G1PostBarrierStubC2 : public G1BarrierStubC2 { +private: + Register _thread; + Register _tmp1; + Register _tmp2; + Register _tmp3; + protected: - virtual void pre_barrier(GraphKit* kit, - bool do_load, - Node* ctl, - Node* obj, - Node* adr, - uint adr_idx, - Node* val, - const TypeOopPtr* val_type, - Node* pre_val, - BasicType bt) const; - - virtual void post_barrier(GraphKit* kit, - Node* ctl, - Node* store, - Node* obj, - Node* adr, - uint adr_idx, - Node* val, - BasicType bt, - bool use_precise) const; + G1PostBarrierStubC2(const MachNode* node); +public: + static bool needs_barrier(const MachNode* node); + static G1PostBarrierStubC2* create(const MachNode* node); + void initialize_registers(Register thread, Register tmp1 = noreg, Register tmp2 = noreg, Register tmp3 = noreg); + Register thread() const; + Register tmp1() const; + Register tmp2() const; + Register tmp3() const; + virtual void emit_code(MacroAssembler& masm); +}; + +class G1BarrierSetC2: public CardTableBarrierSetC2 { +protected: bool g1_can_remove_pre_barrier(GraphKit* kit, PhaseValues* phase, Node* adr, @@ -64,44 +97,31 @@ class G1BarrierSetC2: public CardTableBarrierSetC2 { PhaseValues* phase, Node* store, Node* adr) const; - void g1_mark_card(GraphKit* kit, - IdealKit& ideal, - Node* card_adr, - Node* oop_store, - uint oop_alias_idx, - Node* index, - Node* index_adr, - Node* buffer, - const TypeFunc* tf) const; - - // Helper for unsafe accesses, that may or may not be on the referent field. - // Generates the guards that check whether the result of - // Unsafe.getReference should be recorded in an SATB log buffer. - void insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset, Node* pre_val, bool need_mem_bar) const; - - static const TypeFunc* write_ref_field_pre_entry_Type(); - static const TypeFunc* write_ref_field_post_entry_Type(); + int get_store_barrier(C2Access& access) const; virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const; + virtual Node* store_at_resolved(C2Access& access, C2AccessValue& val) const; + virtual Node* atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val, + Node* new_val, const Type* value_type) const; + virtual Node* atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val, + Node* new_val, const Type* value_type) const; + virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const; -#ifdef ASSERT - bool has_cas_in_use_chain(Node* x) const; - void verify_pre_load(Node* marking_check_if, Unique_Node_List& loads /*output*/) const; - void verify_no_safepoints(Compile* compile, Node* marking_load, const Unique_Node_List& loads) const; -#endif - - static bool is_g1_pre_val_load(Node* n); public: - virtual bool is_gc_pre_barrier_node(Node* node) const; - virtual bool is_gc_barrier_node(Node* node) const; virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const; - virtual Node* step_over_gc_barrier(Node* c) const; - -#ifdef ASSERT - virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const; + virtual void eliminate_gc_barrier_data(Node* node) const; + virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const; + virtual uint estimated_barrier_size(const Node* node) const; + virtual bool can_initialize_object(const StoreNode* store) const; + virtual void clone_at_expansion(PhaseMacroExpand* phase, + ArrayCopyNode* ac) const; + virtual void* create_barrier_state(Arena* comp_arena) const; + virtual void emit_stubs(CodeBuffer& cb) const; + virtual void late_barrier_analysis() const; + +#ifndef PRODUCT + virtual void dump_barrier_data(const MachNode* mach, outputStream* st) const; #endif - - virtual bool escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const; }; #endif // SHARE_GC_G1_C2_G1BARRIERSETC2_HPP diff --git a/src/hotspot/share/gc/g1/g1BarrierSetRuntime.cpp b/src/hotspot/share/gc/g1/g1BarrierSetRuntime.cpp index a0fce437807..2e247f46c93 100644 --- a/src/hotspot/share/gc/g1/g1BarrierSetRuntime.cpp +++ b/src/hotspot/share/gc/g1/g1BarrierSetRuntime.cpp @@ -61,3 +61,11 @@ JRT_LEAF(void, G1BarrierSetRuntime::write_ref_field_post_entry(volatile G1CardTa G1DirtyCardQueue& queue = G1ThreadLocalData::dirty_card_queue(thread); G1BarrierSet::dirty_card_queue_set().enqueue(queue, card_addr); JRT_END + +JRT_LEAF(void, G1BarrierSetRuntime::clone(oopDesc* src, oopDesc* dst, size_t size)) + HeapAccess<>::clone(src, dst, size); +JRT_END + +address G1BarrierSetRuntime::clone_addr() { + return reinterpret_cast
(clone); +} diff --git a/src/hotspot/share/gc/g1/g1BarrierSetRuntime.hpp b/src/hotspot/share/gc/g1/g1BarrierSetRuntime.hpp index 366679f032b..f98e94096e7 100644 --- a/src/hotspot/share/gc/g1/g1BarrierSetRuntime.hpp +++ b/src/hotspot/share/gc/g1/g1BarrierSetRuntime.hpp @@ -35,6 +35,8 @@ class oopDesc; class JavaThread; class G1BarrierSetRuntime: public AllStatic { +private: + static void clone(oopDesc* src, oopDesc* dst, size_t size); public: using CardValue = G1CardTable::CardValue; @@ -46,6 +48,8 @@ class G1BarrierSetRuntime: public AllStatic { // C2 slow-path runtime calls. static void write_ref_field_pre_entry(oopDesc* orig, JavaThread *thread); static void write_ref_field_post_entry(volatile CardValue* card_addr, JavaThread* thread); + + static address clone_addr(); }; #endif // SHARE_GC_G1_G1BARRIERSETRUNTIME_HPP diff --git a/src/hotspot/share/gc/parallel/psScavenge.hpp b/src/hotspot/share/gc/parallel/psScavenge.hpp index 99d0487760b..55abdfd3cf3 100644 --- a/src/hotspot/share/gc/parallel/psScavenge.hpp +++ b/src/hotspot/share/gc/parallel/psScavenge.hpp @@ -34,9 +34,7 @@ #include "oops/oop.hpp" #include "utilities/stack.hpp" -class ReferenceProcessor; class ParallelScavengeHeap; -class ParallelScavengeTracer; class PSIsAliveClosure; class STWGCTimer; diff --git a/src/hotspot/share/gc/shared/c2/barrierSetC2.cpp b/src/hotspot/share/gc/shared/c2/barrierSetC2.cpp index 59e02452044..643a7936b9b 100644 --- a/src/hotspot/share/gc/shared/c2/barrierSetC2.cpp +++ b/src/hotspot/share/gc/shared/c2/barrierSetC2.cpp @@ -109,6 +109,10 @@ Label* BarrierStubC2::continuation() { return &_continuation; } +uint8_t BarrierStubC2::barrier_data() const { + return _node->barrier_data(); +} + void BarrierStubC2::preserve(Register r) { const VMReg vm_reg = r->as_VMReg(); assert(vm_reg->is_Register(), "r must be a general-purpose register"); diff --git a/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp b/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp index c1485c069c8..00fbf1f2c9f 100644 --- a/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp +++ b/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp @@ -254,6 +254,8 @@ class BarrierStubC2 : public ArenaObj { Label* entry(); // Return point from the stub (typically end of barrier). Label* continuation(); + // High-level, GC-specific barrier flags. + uint8_t barrier_data() const; // Preserve the value in reg across runtime calls in this barrier. void preserve(Register reg); @@ -340,6 +342,8 @@ class BarrierSetC2: public CHeapObj { // Estimated size of the node barrier in number of C2 Ideal nodes. // This is used to guide heuristics in C2, e.g. whether to unroll a loop. virtual uint estimated_barrier_size(const Node* node) const { return 0; } + // Whether the given store can be used to initialize a newly allocated object. + virtual bool can_initialize_object(const StoreNode* store) const { return true; } enum CompilePhase { BeforeOptimize, diff --git a/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.cpp b/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.cpp index 87bb9f3cd51..11b742156a8 100644 --- a/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.cpp +++ b/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.cpp @@ -125,39 +125,10 @@ void CardTableBarrierSetC2::post_barrier(GraphKit* kit, kit->final_sync(ideal); } -void CardTableBarrierSetC2::clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const { - BarrierSetC2::clone(kit, src, dst, size, is_array); - const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; - - // If necessary, emit some card marks afterwards. (Non-arrays only.) - bool card_mark = !is_array && !use_ReduceInitialCardMarks(); - if (card_mark) { - assert(!is_array, ""); - // Put in store barrier for any and all oops we are sticking - // into this object. (We could avoid this if we could prove - // that the object type contains no oop fields at all.) - Node* no_particular_value = nullptr; - Node* no_particular_field = nullptr; - int raw_adr_idx = Compile::AliasIdxRaw; - post_barrier(kit, kit->control(), - kit->memory(raw_adr_type), - dst, - no_particular_field, - raw_adr_idx, - no_particular_value, - T_OBJECT, - false); - } -} - bool CardTableBarrierSetC2::use_ReduceInitialCardMarks() const { return ReduceInitialCardMarks; } -bool CardTableBarrierSetC2::is_gc_barrier_node(Node* node) const { - return ModRefBarrierSetC2::is_gc_barrier_node(node) || node->Opcode() == Op_StoreCM; -} - void CardTableBarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const { assert(node->Opcode() == Op_CastP2X, "ConvP2XNode required"); Node *shift = node->unique_out(); diff --git a/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.hpp b/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.hpp index 9512f09ff8a..3bbf14892d3 100644 --- a/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.hpp +++ b/src/hotspot/share/gc/shared/c2/cardTableBarrierSetC2.hpp @@ -42,8 +42,6 @@ class CardTableBarrierSetC2: public ModRefBarrierSetC2 { Node* byte_map_base_node(GraphKit* kit) const; public: - virtual void clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const; - virtual bool is_gc_barrier_node(Node* node) const; virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const; virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const; diff --git a/src/hotspot/share/gc/shared/oopStorageSet.cpp b/src/hotspot/share/gc/shared/oopStorageSet.cpp index c6947590d96..e3a9fccbad3 100644 --- a/src/hotspot/share/gc/shared/oopStorageSet.cpp +++ b/src/hotspot/share/gc/shared/oopStorageSet.cpp @@ -86,7 +86,9 @@ bool OopStorageSet::print_containing(const void* addr, outputStream* st) { if (addr != nullptr) { const void* aligned_addr = align_down(addr, alignof(oop)); for (OopStorage* storage : Range()) { - if (storage->print_containing((oop*) aligned_addr, st)) { + // Check for null for extra safety: might get here while handling error + // before storage initialization. + if ((storage != nullptr) && storage->print_containing((oop*) aligned_addr, st)) { if (aligned_addr != addr) { st->print_cr(" (unaligned)"); } else { diff --git a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp index 71174d11a62..7ac9dcc2e81 100644 --- a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp +++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp @@ -249,8 +249,9 @@ void ShenandoahBarrierSetC2::satb_write_barrier_pre(GraphKit* kit, } __ else_(); { // logging buffer is full, call the runtime - const TypeFunc *tf = ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type(); - __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), "shenandoah_wb_pre", pre_val, tls); + const TypeFunc *tf = ShenandoahBarrierSetC2::write_ref_field_pre_Type(); + __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre), "shenandoah_wb_pre", + pre_val, tls); } __ end_if(); // (!index) } __ end_if(); // (pre_val != nullptr) } __ end_if(); // (!marking) @@ -268,12 +269,12 @@ void ShenandoahBarrierSetC2::satb_write_barrier_pre(GraphKit* kit, bool ShenandoahBarrierSetC2::is_shenandoah_wb_pre_call(Node* call) { return call->is_CallLeaf() && - call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry); + call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre); } bool ShenandoahBarrierSetC2::is_shenandoah_clone_call(Node* call) { return call->is_CallLeaf() && - call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::shenandoah_clone_barrier); + call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::clone_barrier); } bool ShenandoahBarrierSetC2::is_shenandoah_lrb_call(Node* call) { @@ -433,7 +434,7 @@ void ShenandoahBarrierSetC2::insert_pre_barrier(GraphKit* kit, Node* base_oop, N #undef __ -const TypeFunc* ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type() { +const TypeFunc* ShenandoahBarrierSetC2::write_ref_field_pre_Type() { const Type **fields = TypeTuple::fields(2); fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread @@ -446,7 +447,7 @@ const TypeFunc* ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type() { return TypeFunc::make(domain, range); } -const TypeFunc* ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type() { +const TypeFunc* ShenandoahBarrierSetC2::clone_barrier_Type() { const Type **fields = TypeTuple::fields(1); fields[TypeFunc::Parms+0] = TypeOopPtr::NOTNULL; // src oop const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields); @@ -458,7 +459,7 @@ const TypeFunc* ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type() { return TypeFunc::make(domain, range); } -const TypeFunc* ShenandoahBarrierSetC2::shenandoah_load_reference_barrier_Type() { +const TypeFunc* ShenandoahBarrierSetC2::load_reference_barrier_Type() { const Type **fields = TypeTuple::fields(2); fields[TypeFunc::Parms+0] = TypeOopPtr::BOTTOM; // original field value fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // original load address @@ -681,7 +682,8 @@ bool ShenandoahBarrierSetC2::is_gc_pre_barrier_node(Node* node) const { } bool ShenandoahBarrierSetC2::is_gc_barrier_node(Node* node) const { - return is_shenandoah_lrb_call(node) || + return (node->Opcode() == Op_ShenandoahLoadReferenceBarrier) || + is_shenandoah_lrb_call(node) || is_shenandoah_wb_pre_call(node) || is_shenandoah_clone_call(node); } @@ -797,11 +799,11 @@ void ShenandoahBarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCo // Heap is unstable, call into clone barrier stub Node* call = phase->make_leaf_call(unstable_ctrl, mem, - ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type(), - CAST_FROM_FN_PTR(address, ShenandoahRuntime::shenandoah_clone_barrier), - "shenandoah_clone", - TypeRawPtr::BOTTOM, - src_base); + ShenandoahBarrierSetC2::clone_barrier_Type(), + CAST_FROM_FN_PTR(address, ShenandoahRuntime::clone_barrier), + "shenandoah_clone", + TypeRawPtr::BOTTOM, + src_base); call = phase->transform_later(call); ctrl = phase->transform_later(new ProjNode(call, TypeFunc::Control)); @@ -976,7 +978,7 @@ void ShenandoahBarrierSetC2::verify_gc_barriers(Compile* compile, CompilePhase p Node* ShenandoahBarrierSetC2::ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const { if (is_shenandoah_wb_pre_call(n)) { - uint cnt = ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type()->domain()->cnt(); + uint cnt = ShenandoahBarrierSetC2::write_ref_field_pre_Type()->domain()->cnt(); if (n->req() > cnt) { Node* addp = n->in(cnt); if (has_only_shenandoah_wb_pre_uses(addp)) { @@ -1062,7 +1064,7 @@ bool ShenandoahBarrierSetC2::final_graph_reshaping(Compile* compile, Node* n, ui assert (n->is_Call(), ""); CallNode *call = n->as_Call(); if (ShenandoahBarrierSetC2::is_shenandoah_wb_pre_call(call)) { - uint cnt = ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type()->domain()->cnt(); + uint cnt = ShenandoahBarrierSetC2::write_ref_field_pre_Type()->domain()->cnt(); if (call->req() > cnt) { assert(call->req() == cnt + 1, "only one extra input"); Node *addp = call->in(cnt); diff --git a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp index cbfacea31ab..6e241b39ce9 100644 --- a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp +++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp @@ -93,9 +93,9 @@ class ShenandoahBarrierSetC2 : public BarrierSetC2 { ShenandoahBarrierSetC2State* state() const; - static const TypeFunc* write_ref_field_pre_entry_Type(); - static const TypeFunc* shenandoah_clone_barrier_Type(); - static const TypeFunc* shenandoah_load_reference_barrier_Type(); + static const TypeFunc* write_ref_field_pre_Type(); + static const TypeFunc* clone_barrier_Type(); + static const TypeFunc* load_reference_barrier_Type(); virtual bool has_load_barrier_nodes() const { return true; } // This is the entry-point for the backend to perform accesses through the Access API. diff --git a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp b/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp index 7526f895f2f..efa0ced603c 100644 --- a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp +++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp @@ -995,7 +995,7 @@ void ShenandoahBarrierC2Support::call_lrb_stub(Node*& ctrl, Node*& val, Node* lo name = "load_reference_barrier_phantom"; } } - Node* call = new CallLeafNode(ShenandoahBarrierSetC2::shenandoah_load_reference_barrier_Type(), calladdr, name, TypeRawPtr::BOTTOM); + Node* call = new CallLeafNode(ShenandoahBarrierSetC2::load_reference_barrier_Type(), calladdr, name, TypeRawPtr::BOTTOM); call->init_req(TypeFunc::Control, ctrl); call->init_req(TypeFunc::I_O, phase->C->top()); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp index 4ab17aabcc5..7ae4a1cf8b3 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp @@ -693,7 +693,7 @@ void ShenandoahHeap::notify_mutator_alloc_words(size_t words, bool waste) { if (ShenandoahPacing) { control_thread()->pacing_notify_alloc(words); if (waste) { - pacer()->claim_for_alloc(words, true); + pacer()->claim_for_alloc(words); } } } diff --git a/src/hotspot/share/gc/shenandoah/shenandoahPacer.cpp b/src/hotspot/share/gc/shenandoah/shenandoahPacer.cpp index 0fc6744c15a..e67d3d197d4 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahPacer.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahPacer.cpp @@ -189,7 +189,8 @@ void ShenandoahPacer::restart_with(size_t non_taxable_bytes, double tax_rate) { _need_notify_waiters.try_set(); } -bool ShenandoahPacer::claim_for_alloc(size_t words, bool force) { +template +bool ShenandoahPacer::claim_for_alloc(size_t words) { assert(ShenandoahPacing, "Only be here when pacing is enabled"); intptr_t tax = MAX2(1, words * Atomic::load(&_tax_rate)); @@ -198,7 +199,7 @@ bool ShenandoahPacer::claim_for_alloc(size_t words, bool force) { intptr_t new_val = 0; do { cur = Atomic::load(&_budget); - if (cur < tax && !force) { + if (cur < tax && !FORCE) { // Progress depleted, alas. return false; } @@ -207,6 +208,9 @@ bool ShenandoahPacer::claim_for_alloc(size_t words, bool force) { return true; } +template bool ShenandoahPacer::claim_for_alloc(size_t words); +template bool ShenandoahPacer::claim_for_alloc(size_t words); + void ShenandoahPacer::unpace_for_alloc(intptr_t epoch, size_t words) { assert(ShenandoahPacing, "Only be here when pacing is enabled"); @@ -227,18 +231,11 @@ void ShenandoahPacer::pace_for_alloc(size_t words) { assert(ShenandoahPacing, "Only be here when pacing is enabled"); // Fast path: try to allocate right away - bool claimed = claim_for_alloc(words, false); + bool claimed = claim_for_alloc(words); if (claimed) { return; } - // Forcefully claim the budget: it may go negative at this point, and - // GC should replenish for this and subsequent allocations. After this claim, - // we would wait a bit until our claim is matched by additional progress, - // or the time budget depletes. - claimed = claim_for_alloc(words, true); - assert(claimed, "Should always succeed"); - // Threads that are attaching should not block at all: they are not // fully initialized yet. Blocking them would be awkward. // This is probably the path that allocates the thread oop itself. @@ -249,32 +246,25 @@ void ShenandoahPacer::pace_for_alloc(size_t words) { JavaThread* current = JavaThread::current(); if (current->is_attaching_via_jni() || !current->is_active_Java_thread()) { + claim_for_alloc(words); return; } - double start = os::elapsedTime(); - - size_t max_ms = ShenandoahPacingMaxDelay; - size_t total_ms = 0; - - while (true) { + jlong const max_delay = ShenandoahPacingMaxDelay * NANOSECS_PER_MILLISEC; + jlong const start_time = os::elapsed_counter(); + while (!claimed && (os::elapsed_counter() - start_time) < max_delay) { // We could instead assist GC, but this would suffice for now. - size_t cur_ms = (max_ms > total_ms) ? (max_ms - total_ms) : 1; - wait(cur_ms); - - double end = os::elapsedTime(); - total_ms = (size_t)((end - start) * 1000); - - if (total_ms > max_ms || Atomic::load(&_budget) >= 0) { - // Exiting if either: - // a) Spent local time budget to wait for enough GC progress. - // Breaking out and allocating anyway, which may mean we outpace GC, - // and start Degenerated GC cycle. - // b) The budget had been replenished, which means our claim is satisfied. - ShenandoahThreadLocalData::add_paced_time(JavaThread::current(), end - start); - break; - } + wait(1); + claimed = claim_for_alloc(words); + } + if (!claimed) { + // Spent local time budget to wait for enough GC progress. + // Force allocating anyway, which may mean we outpace GC, + // and start Degenerated GC cycle. + claimed = claim_for_alloc(words); + assert(claimed, "Should always succeed"); } + ShenandoahThreadLocalData::add_paced_time(current, (double)(os::elapsed_counter() - start_time) / NANOSECS_PER_SEC); } void ShenandoahPacer::wait(size_t time_ms) { diff --git a/src/hotspot/share/gc/shenandoah/shenandoahPacer.hpp b/src/hotspot/share/gc/shenandoah/shenandoahPacer.hpp index 1c2bf00eb56..44ad2700f87 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahPacer.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahPacer.hpp @@ -107,7 +107,9 @@ class ShenandoahPacer : public CHeapObj { inline void report_alloc(size_t words); - bool claim_for_alloc(size_t words, bool force); + template + bool claim_for_alloc(size_t words); + void pace_for_alloc(size_t words); void unpace_for_alloc(intptr_t epoch, size_t words); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahRuntime.cpp b/src/hotspot/share/gc/shenandoah/shenandoahRuntime.cpp index 2c727de5857..b217c641824 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahRuntime.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahRuntime.cpp @@ -31,22 +31,19 @@ #include "oops/oop.inline.hpp" #include "utilities/copy.hpp" -void ShenandoahRuntime::arraycopy_barrier_oop_entry(oop* src, oop* dst, size_t length) { - ShenandoahBarrierSet *bs = ShenandoahBarrierSet::barrier_set(); - bs->arraycopy_barrier(src, dst, length); -} +JRT_LEAF(void, ShenandoahRuntime::arraycopy_barrier_oop(oop* src, oop* dst, size_t length)) + ShenandoahBarrierSet::barrier_set()->arraycopy_barrier(src, dst, length); +JRT_END -void ShenandoahRuntime::arraycopy_barrier_narrow_oop_entry(narrowOop* src, narrowOop* dst, size_t length) { - ShenandoahBarrierSet *bs = ShenandoahBarrierSet::barrier_set(); - bs->arraycopy_barrier(src, dst, length); -} +JRT_LEAF(void, ShenandoahRuntime::arraycopy_barrier_narrow_oop(narrowOop* src, narrowOop* dst, size_t length)) + ShenandoahBarrierSet::barrier_set()->arraycopy_barrier(src, dst, length); +JRT_END -// Shenandoah pre write barrier slowpath -JRT_LEAF(void, ShenandoahRuntime::write_ref_field_pre_entry(oopDesc* orig, JavaThread *thread)) +JRT_LEAF(void, ShenandoahRuntime::write_ref_field_pre(oopDesc * orig, JavaThread * thread)) assert(thread == JavaThread::current(), "pre-condition"); assert(orig != nullptr, "should be optimized out"); shenandoah_assert_correct(nullptr, orig); - // store the original value that was in the field reference + // Capture the original value that was in the field reference. assert(ShenandoahThreadLocalData::satb_mark_queue(thread).is_active(), "Shouldn't be here otherwise"); SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread); ShenandoahBarrierSet::satb_mark_queue_set().enqueue_known_active(queue, orig); @@ -60,26 +57,24 @@ JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_strong_narrow(oopDe return ShenandoahBarrierSet::barrier_set()->load_reference_barrier_mutator(src, load_addr); JRT_END -// Shenandoah clone barrier: makes sure that references point to to-space -// in cloned objects. -JRT_LEAF(void, ShenandoahRuntime::shenandoah_clone_barrier(oopDesc* src)) - oop s = oop(src); - shenandoah_assert_correct(nullptr, s); - ShenandoahBarrierSet::barrier_set()->clone_barrier(s); -JRT_END - -JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_weak(oopDesc * src, oop* load_addr)) +JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_weak(oopDesc* src, oop* load_addr)) return (oopDesc*) ShenandoahBarrierSet::barrier_set()->load_reference_barrier(ON_WEAK_OOP_REF, oop(src), load_addr); JRT_END -JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_weak_narrow(oopDesc * src, narrowOop* load_addr)) +JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_weak_narrow(oopDesc* src, narrowOop* load_addr)) return (oopDesc*) ShenandoahBarrierSet::barrier_set()->load_reference_barrier(ON_WEAK_OOP_REF, oop(src), load_addr); JRT_END -JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_phantom(oopDesc * src, oop* load_addr)) +JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_phantom(oopDesc* src, oop* load_addr)) return (oopDesc*) ShenandoahBarrierSet::barrier_set()->load_reference_barrier(ON_PHANTOM_OOP_REF, oop(src), load_addr); JRT_END -JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_phantom_narrow(oopDesc * src, narrowOop* load_addr)) +JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_phantom_narrow(oopDesc* src, narrowOop* load_addr)) return (oopDesc*) ShenandoahBarrierSet::barrier_set()->load_reference_barrier(ON_PHANTOM_OOP_REF, oop(src), load_addr); JRT_END + +JRT_LEAF(void, ShenandoahRuntime::clone_barrier(oopDesc* src)) + oop s = oop(src); + shenandoah_assert_correct(nullptr, s); + ShenandoahBarrierSet::barrier_set()->clone_barrier(s); +JRT_END diff --git a/src/hotspot/share/gc/shenandoah/shenandoahRuntime.hpp b/src/hotspot/share/gc/shenandoah/shenandoahRuntime.hpp index e187e4360b1..4ad8fc997ea 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahRuntime.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahRuntime.hpp @@ -33,10 +33,10 @@ class oopDesc; class ShenandoahRuntime : public AllStatic { public: - static void arraycopy_barrier_oop_entry(oop* src, oop* dst, size_t length); - static void arraycopy_barrier_narrow_oop_entry(narrowOop* src, narrowOop* dst, size_t length); + static void arraycopy_barrier_oop(oop* src, oop* dst, size_t length); + static void arraycopy_barrier_narrow_oop(narrowOop* src, narrowOop* dst, size_t length); - static void write_ref_field_pre_entry(oopDesc* orig, JavaThread* thread); + static void write_ref_field_pre(oopDesc* orig, JavaThread* thread); static oopDesc* load_reference_barrier_strong(oopDesc* src, oop* load_addr); static oopDesc* load_reference_barrier_strong_narrow(oopDesc* src, narrowOop* load_addr); @@ -47,7 +47,7 @@ class ShenandoahRuntime : public AllStatic { static oopDesc* load_reference_barrier_phantom(oopDesc* src, oop* load_addr); static oopDesc* load_reference_barrier_phantom_narrow(oopDesc* src, narrowOop* load_addr); - static void shenandoah_clone_barrier(oopDesc* src); + static void clone_barrier(oopDesc* src); }; #endif // SHARE_GC_SHENANDOAH_SHENANDOAHRUNTIME_HPP diff --git a/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.cpp index c3e8108752f..127e6324fb0 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.cpp @@ -23,7 +23,7 @@ */ #include "precompiled.hpp" -#include "gc/shenandoah/shenandoahSimpleBitMap.hpp" +#include "gc/shenandoah/shenandoahSimpleBitMap.inline.hpp" ShenandoahSimpleBitMap::ShenandoahSimpleBitMap(size_t num_bits) : _num_bits(num_bits), @@ -43,8 +43,8 @@ size_t ShenandoahSimpleBitMap::count_leading_ones(idx_t start_idx) const { assert((start_idx >= 0) && (start_idx < _num_bits), "precondition"); size_t array_idx = start_idx >> LogBitsPerWord; uintx element_bits = _bitmap[array_idx]; - uintx bit_number = start_idx & right_n_bits(LogBitsPerWord); - uintx mask = ~right_n_bits(bit_number); + uintx bit_number = start_idx & (BitsPerWord - 1); + uintx mask = ~tail_mask(bit_number); size_t counted_ones = 0; while ((element_bits & mask) == mask) { // All bits numbered >= bit_number are set @@ -54,7 +54,7 @@ size_t ShenandoahSimpleBitMap::count_leading_ones(idx_t start_idx) const { // Strength reduction: array_idx = (start_idx >> LogBitsPerWord) array_idx++; element_bits = _bitmap[array_idx]; - // Constant folding: bit_number = start_idx & right_n_bits(LogBitsPerWord); + // Constant folding: bit_number = start_idx & (BitsPerWord - 1); bit_number = 0; // Constant folding: mask = ~right_n_bits(bit_number); mask = ~0; @@ -70,9 +70,9 @@ size_t ShenandoahSimpleBitMap::count_trailing_ones(idx_t last_idx) const { assert((last_idx >= 0) && (last_idx < _num_bits), "precondition"); size_t array_idx = last_idx >> LogBitsPerWord; uintx element_bits = _bitmap[array_idx]; - uintx bit_number = last_idx & right_n_bits(LogBitsPerWord); + uintx bit_number = last_idx & (BitsPerWord - 1); // All ones from bit 0 to the_bit - uintx mask = right_n_bits(bit_number + 1); + uintx mask = tail_mask(bit_number + 1); size_t counted_ones = 0; while ((element_bits & mask) == mask) { // All bits numbered <= bit_number are set @@ -81,7 +81,7 @@ size_t ShenandoahSimpleBitMap::count_trailing_ones(idx_t last_idx) const { // Dead code: do not need to compute: last_idx -= found_ones; array_idx--; element_bits = _bitmap[array_idx]; - // Constant folding: bit_number = last_idx & right_n_bits(LogBitsPerWord); + // Constant folding: bit_number = last_idx & (BitsPerWord - 1); bit_number = BitsPerWord - 1; // Constant folding: mask = right_n_bits(bit_number + 1); mask = ~0; @@ -99,7 +99,7 @@ bool ShenandoahSimpleBitMap::is_forward_consecutive_ones(idx_t start_idx, idx_t start_idx, count); assert(start_idx + count <= (idx_t) _num_bits, "precondition"); size_t array_idx = start_idx >> LogBitsPerWord; - uintx bit_number = start_idx & right_n_bits(LogBitsPerWord); + uintx bit_number = start_idx & (BitsPerWord - 1); uintx element_bits = _bitmap[array_idx]; uintx bits_to_examine = BitsPerWord - bit_number; element_bits >>= bit_number; @@ -128,7 +128,7 @@ bool ShenandoahSimpleBitMap::is_backward_consecutive_ones(idx_t last_idx, idx_t assert((last_idx >= 0) && (last_idx < _num_bits), "precondition"); assert(last_idx - count >= -1, "precondition"); size_t array_idx = last_idx >> LogBitsPerWord; - uintx bit_number = last_idx & right_n_bits(LogBitsPerWord); + uintx bit_number = last_idx & (BitsPerWord - 1); uintx element_bits = _bitmap[array_idx]; uintx bits_to_examine = bit_number + 1; element_bits <<= (BitsPerWord - bits_to_examine); @@ -161,10 +161,10 @@ idx_t ShenandoahSimpleBitMap::find_first_consecutive_set_bits(idx_t beg, idx_t e return end; } uintx array_idx = beg >> LogBitsPerWord; - uintx bit_number = beg & right_n_bits(LogBitsPerWord); + uintx bit_number = beg & (BitsPerWord - 1); uintx element_bits = _bitmap[array_idx]; if (bit_number > 0) { - uintx mask_out = right_n_bits(bit_number); + uintx mask_out = tail_mask(bit_number); element_bits &= ~mask_out; } @@ -222,9 +222,9 @@ idx_t ShenandoahSimpleBitMap::find_first_consecutive_set_bits(idx_t beg, idx_t e } array_idx = beg >> LogBitsPerWord; element_bits = _bitmap[array_idx]; - bit_number = beg & right_n_bits(LogBitsPerWord); + bit_number = beg & (BitsPerWord - 1); if (bit_number > 0) { - size_t mask_out = right_n_bits(bit_number); + size_t mask_out = tail_mask(bit_number); element_bits &= ~mask_out; } } @@ -242,10 +242,10 @@ idx_t ShenandoahSimpleBitMap::find_last_consecutive_set_bits(const idx_t beg, id } size_t array_idx = end >> LogBitsPerWord; - uintx bit_number = end & right_n_bits(LogBitsPerWord); + uintx bit_number = end & (BitsPerWord - 1); uintx element_bits = _bitmap[array_idx]; if (bit_number < BitsPerWord - 1) { - uintx mask_in = right_n_bits(bit_number + 1); + uintx mask_in = tail_mask(bit_number + 1); element_bits &= mask_in; } @@ -280,10 +280,10 @@ idx_t ShenandoahSimpleBitMap::find_last_consecutive_set_bits(const idx_t beg, id return beg; } array_idx = end >> LogBitsPerWord; - bit_number = end & right_n_bits(LogBitsPerWord); + bit_number = end & (BitsPerWord - 1); element_bits = _bitmap[array_idx]; if (bit_number < BitsPerWord - 1){ - size_t mask_in = right_n_bits(bit_number + 1); + size_t mask_in = tail_mask(bit_number + 1); element_bits &= mask_in; } } diff --git a/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.hpp b/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.hpp index c22e9527002..6b95303fb33 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.hpp @@ -50,7 +50,7 @@ typedef ssize_t idx_t; // ShenandoahSimpleBitMap resembles CHeapBitMap but adds missing support for find_first_consecutive_set_bits() and // find_last_consecutive_set_bits. An alternative refactoring of code would subclass CHeapBitMap, but this might // break abstraction rules, because efficient implementation requires assumptions about superclass internals that -// might be violatee through future software maintenance. +// might be violated through future software maintenance. class ShenandoahSimpleBitMap { const idx_t _num_bits; const size_t _num_words; @@ -84,7 +84,7 @@ class ShenandoahSimpleBitMap { inline idx_t aligned_index(idx_t idx) const { assert((idx >= 0) && (idx < _num_bits), "precondition"); - idx_t array_idx = idx & ~right_n_bits(LogBitsPerWord); + idx_t array_idx = idx & ~(BitsPerWord - 1); return array_idx; } @@ -107,7 +107,7 @@ class ShenandoahSimpleBitMap { inline void set_bit(idx_t idx) { assert((idx >= 0) && (idx < _num_bits), "precondition"); size_t array_idx = idx >> LogBitsPerWord; - uintx bit_number = idx & right_n_bits(LogBitsPerWord); + uintx bit_number = idx & (BitsPerWord - 1); uintx the_bit = nth_bit(bit_number); _bitmap[array_idx] |= the_bit; } @@ -116,7 +116,7 @@ class ShenandoahSimpleBitMap { assert((idx >= 0) && (idx < _num_bits), "precondition"); assert(idx >= 0, "precondition"); size_t array_idx = idx >> LogBitsPerWord; - uintx bit_number = idx & right_n_bits(LogBitsPerWord); + uintx bit_number = idx & (BitsPerWord - 1); uintx the_bit = nth_bit(bit_number); _bitmap[array_idx] &= ~the_bit; } @@ -125,9 +125,9 @@ class ShenandoahSimpleBitMap { assert((idx >= 0) && (idx < _num_bits), "precondition"); assert(idx >= 0, "precondition"); size_t array_idx = idx >> LogBitsPerWord; - uintx bit_number = idx & right_n_bits(LogBitsPerWord); + uintx bit_number = idx & (BitsPerWord - 1); uintx the_bit = nth_bit(bit_number); - return (_bitmap[array_idx] & the_bit)? true: false; + return (_bitmap[array_idx] & the_bit) != 0; } // Return the index of the first set bit in the range [beg, size()), or size() if none found. diff --git a/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.inline.hpp b/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.inline.hpp index 3e602ed11e0..c047e1ed663 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.inline.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahSimpleBitMap.inline.hpp @@ -27,15 +27,22 @@ #include "gc/shenandoah/shenandoahSimpleBitMap.hpp" +inline uintx tail_mask(uintx bit_number) { + if (bit_number >= BitsPerWord) { + return -1; + } + return (uintx(1) << bit_number) - 1; +} + inline idx_t ShenandoahSimpleBitMap::find_first_set_bit(idx_t beg, idx_t end) const { assert((beg >= 0) && (beg < _num_bits), "precondition"); assert((end > beg) && (end <= _num_bits), "precondition"); do { size_t array_idx = beg >> LogBitsPerWord; - uintx bit_number = beg & right_n_bits(LogBitsPerWord); + uintx bit_number = beg & (BitsPerWord - 1); uintx element_bits = _bitmap[array_idx]; if (bit_number > 0) { - uintx mask_out = right_n_bits(bit_number); + uintx mask_out = tail_mask(bit_number); element_bits &= ~mask_out; } if (element_bits) { @@ -62,10 +69,10 @@ inline idx_t ShenandoahSimpleBitMap::find_last_set_bit(idx_t beg, idx_t end) con assert((beg >= -1) && (beg < end), "precondition"); do { idx_t array_idx = end >> LogBitsPerWord; - uintx bit_number = end & right_n_bits(LogBitsPerWord); + uint8_t bit_number = end & (BitsPerWord - 1); uintx element_bits = _bitmap[array_idx]; if (bit_number < BitsPerWord - 1){ - uintx mask_in = right_n_bits(bit_number + 1); + uintx mask_in = tail_mask(bit_number + 1); element_bits &= mask_in; } if (element_bits) { diff --git a/src/hotspot/share/gc/z/zCollectedHeap.cpp b/src/hotspot/share/gc/z/zCollectedHeap.cpp index ccfa7af6b7d..8afefd5a7cc 100644 --- a/src/hotspot/share/gc/z/zCollectedHeap.cpp +++ b/src/hotspot/share/gc/z/zCollectedHeap.cpp @@ -49,6 +49,7 @@ #include "memory/universe.hpp" #include "oops/stackChunkOop.hpp" #include "runtime/continuationJavaClasses.hpp" +#include "runtime/java.hpp" #include "runtime/jniHandles.inline.hpp" #include "runtime/stackWatermarkSet.hpp" #include "services/memoryUsage.hpp" @@ -60,7 +61,7 @@ ZCollectedHeap* ZCollectedHeap::heap() { ZCollectedHeap::ZCollectedHeap() : _barrier_set(), - _initialize(&_barrier_set), + _initializer(&_barrier_set), _heap(), _driver_minor(new ZDriverMinor()), _driver_major(new ZDriverMajor()), @@ -78,11 +79,14 @@ const char* ZCollectedHeap::name() const { jint ZCollectedHeap::initialize() { if (!_heap.is_initialized()) { + vm_shutdown_during_initialization(ZInitialize::error_message()); return JNI_ENOMEM; } Universe::set_verify_data(~(ZAddressHeapBase - 1) | 0x7, ZAddressHeapBase); + ZInitialize::finish(); + return JNI_OK; } diff --git a/src/hotspot/share/gc/z/zCollectedHeap.hpp b/src/hotspot/share/gc/z/zCollectedHeap.hpp index 528bacd8df8..434204e16b8 100644 --- a/src/hotspot/share/gc/z/zCollectedHeap.hpp +++ b/src/hotspot/share/gc/z/zCollectedHeap.hpp @@ -43,7 +43,7 @@ class ZCollectedHeap : public CollectedHeap { private: ZBarrierSet _barrier_set; - ZInitialize _initialize; + ZInitializer _initializer; ZHeap _heap; ZDriverMinor* _driver_minor; ZDriverMajor* _driver_major; diff --git a/src/hotspot/share/gc/z/zHeap.cpp b/src/hotspot/share/gc/z/zHeap.cpp index dc5f1e3d21d..40aa76867f4 100644 --- a/src/hotspot/share/gc/z/zHeap.cpp +++ b/src/hotspot/share/gc/z/zHeap.cpp @@ -34,6 +34,7 @@ #include "gc/z/zHeap.inline.hpp" #include "gc/z/zHeapIterator.hpp" #include "gc/z/zHeuristics.hpp" +#include "gc/z/zInitialize.hpp" #include "gc/z/zPage.inline.hpp" #include "gc/z/zPageTable.inline.hpp" #include "gc/z/zResurrection.hpp" @@ -74,7 +75,7 @@ ZHeap::ZHeap() // Prime cache if (!_page_allocator.prime_cache(_old.workers(), InitialHeapSize)) { - log_error_p(gc)("Failed to allocate initial Java heap (" SIZE_FORMAT "M)", InitialHeapSize / M); + ZInitialize::error("Failed to allocate initial Java heap (" SIZE_FORMAT "M)", InitialHeapSize / M); return; } diff --git a/src/hotspot/share/gc/z/zInitialize.cpp b/src/hotspot/share/gc/z/zInitialize.cpp index 52229bf2830..e37fc550bfe 100644 --- a/src/hotspot/share/gc/z/zInitialize.cpp +++ b/src/hotspot/share/gc/z/zInitialize.cpp @@ -22,6 +22,7 @@ */ #include "precompiled.hpp" +#include "gc/shared/gcLogPrecious.hpp" #include "gc/z/zAddress.hpp" #include "gc/z/zBarrierSet.hpp" #include "gc/z/zCPU.hpp" @@ -38,9 +39,19 @@ #include "gc/z/zThreadLocalAllocBuffer.hpp" #include "gc/z/zTracer.hpp" #include "logging/log.hpp" +#include "nmt/memTag.hpp" #include "runtime/vm_version.hpp" +#include "utilities/formatBuffer.hpp" -ZInitialize::ZInitialize(ZBarrierSet* barrier_set) { +char ZInitialize::_error_message[ErrorMessageLength] = {}; +bool ZInitialize::_had_error = false; +bool ZInitialize::_finished = false; + +ZInitializer::ZInitializer(ZBarrierSet* barrier_set) { + ZInitialize::initialize(barrier_set); +} + +void ZInitialize::initialize(ZBarrierSet* barrier_set) { log_info(gc, init)("Initializing %s", ZName); log_info(gc, init)("Version: %s (%s)", VM_Version::vm_release(), @@ -62,3 +73,51 @@ ZInitialize::ZInitialize(ZBarrierSet* barrier_set) { pd_initialize(); } + +void ZInitialize::register_error(bool debug, const char *error_msg) { + guarantee(!_finished, "Only register errors during initialization"); + + if (!_had_error) { + strncpy(_error_message, error_msg, ErrorMessageLength - 1); + _had_error = true; + } + + if (debug) { + log_error_pd(gc)("%s", error_msg); + } else { + log_error_p(gc)("%s", error_msg); + } +} + +void ZInitialize::error(const char* msg_format, ...) { + va_list argp; + va_start(argp, msg_format); + const FormatBuffer error_msg(FormatBufferDummy(), msg_format, argp); + va_end(argp); + register_error(false /* debug */, error_msg); +} + +void ZInitialize::error_d(const char* msg_format, ...) { + va_list argp; + va_start(argp, msg_format); + const FormatBuffer error_msg(FormatBufferDummy(), msg_format, argp); + va_end(argp); + register_error(true /* debug */, error_msg); +} + +bool ZInitialize::had_error() { + return _had_error; +} + +const char* ZInitialize::error_message() { + assert(had_error(), "Should have registered an error"); + if (had_error()) { + return _error_message; + } + return "Unknown error, check error GC logs"; +} + +void ZInitialize::finish() { + guarantee(!_finished, "Only finish initialization once"); + _finished = true; +} diff --git a/src/hotspot/share/gc/z/zInitialize.hpp b/src/hotspot/share/gc/z/zInitialize.hpp index 599b6566234..3c551b4c622 100644 --- a/src/hotspot/share/gc/z/zInitialize.hpp +++ b/src/hotspot/share/gc/z/zInitialize.hpp @@ -24,16 +24,39 @@ #ifndef SHARE_GC_Z_ZINITIALIZE_HPP #define SHARE_GC_Z_ZINITIALIZE_HPP -#include "memory/allocation.hpp" +#include "memory/allStatic.hpp" +#include "utilities/compilerWarnings.hpp" + +#include class ZBarrierSet; -class ZInitialize { +class ZInitializer { +public: + ZInitializer(ZBarrierSet* barrier_set); +}; + +class ZInitialize : public AllStatic { private: - void pd_initialize(); + static constexpr size_t ErrorMessageLength = 256; + + static char _error_message[ErrorMessageLength]; + static bool _had_error; + static bool _finished; + + static void register_error(bool debug, const char *error_msg); + + static void pd_initialize(); public: - ZInitialize(ZBarrierSet* barrier_set); + static void error(const char* msg_format, ...) ATTRIBUTE_PRINTF(1, 2); + static void error_d(const char* msg_format, ...) ATTRIBUTE_PRINTF(1, 2); + + static bool had_error(); + static const char* error_message(); + + static void initialize(ZBarrierSet* barrier_set); + static void finish(); }; #endif // SHARE_GC_Z_ZINITIALIZE_HPP diff --git a/src/hotspot/share/gc/z/zMarkStackAllocator.cpp b/src/hotspot/share/gc/z/zMarkStackAllocator.cpp index a9e404a0f55..100036dc3fe 100644 --- a/src/hotspot/share/gc/z/zMarkStackAllocator.cpp +++ b/src/hotspot/share/gc/z/zMarkStackAllocator.cpp @@ -22,8 +22,8 @@ */ #include "precompiled.hpp" -#include "gc/shared/gcLogPrecious.hpp" #include "gc/shared/gc_globals.hpp" +#include "gc/z/zInitialize.hpp" #include "gc/z/zLock.inline.hpp" #include "gc/z/zMarkStack.inline.hpp" #include "gc/z/zMarkStackAllocator.hpp" @@ -43,7 +43,7 @@ ZMarkStackSpace::ZMarkStackSpace() const size_t size = ZMarkStackSpaceLimit; const uintptr_t addr = (uintptr_t)os::reserve_memory(size, !ExecMem, mtGC); if (addr == 0) { - log_error_pd(gc, marking)("Failed to reserve address space for mark stacks"); + ZInitialize::error_d("Failed to reserve address space for mark stacks"); return; } diff --git a/src/hotspot/share/gc/z/zVirtualMemory.cpp b/src/hotspot/share/gc/z/zVirtualMemory.cpp index 6b53b2ba7c8..2160aa38948 100644 --- a/src/hotspot/share/gc/z/zVirtualMemory.cpp +++ b/src/hotspot/share/gc/z/zVirtualMemory.cpp @@ -27,6 +27,7 @@ #include "gc/z/zAddress.inline.hpp" #include "gc/z/zAddressSpaceLimit.hpp" #include "gc/z/zGlobals.hpp" +#include "gc/z/zInitialize.hpp" #include "gc/z/zNMT.hpp" #include "gc/z/zVirtualMemory.inline.hpp" #include "utilities/align.hpp" @@ -44,7 +45,7 @@ ZVirtualMemoryManager::ZVirtualMemoryManager(size_t max_capacity) // Reserve address space if (!reserve(max_capacity)) { - log_error_pd(gc)("Failed to reserve enough address space for Java heap"); + ZInitialize::error_d("Failed to reserve enough address space for Java heap"); return; } diff --git a/src/hotspot/share/interpreter/templateInterpreterGenerator.hpp b/src/hotspot/share/interpreter/templateInterpreterGenerator.hpp index bcccff2fe82..b0afcb52795 100644 --- a/src/hotspot/share/interpreter/templateInterpreterGenerator.hpp +++ b/src/hotspot/share/interpreter/templateInterpreterGenerator.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -74,7 +74,7 @@ class TemplateInterpreterGenerator: public AbstractInterpreterGenerator { void set_safepoints_for_all_bytes(); // Helpers for generate_and_dispatch - address generate_trace_code(TosState state) PRODUCT_RETURN0; + address generate_trace_code(TosState state) PRODUCT_RETURN_NULL; void count_bytecode() PRODUCT_RETURN; void histogram_bytecode(Template* t) PRODUCT_RETURN; void histogram_bytecode_pair(Template* t) PRODUCT_RETURN; diff --git a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp index 279b871d818..a53eaa474f3 100644 --- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp +++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp @@ -484,6 +484,9 @@ static void do_primitives() { static void do_unloading_klass(Klass* klass) { assert(klass != nullptr, "invariant"); assert(_subsystem_callback != nullptr, "invariant"); + if (klass->is_instance_klass() && InstanceKlass::cast(klass)->is_scratch_class()) { + return; + } if (JfrKlassUnloading::on_unload(klass)) { _subsystem_callback->do_artifact(klass); } diff --git a/src/hotspot/share/jvmci/jvmci_globals.cpp b/src/hotspot/share/jvmci/jvmci_globals.cpp index 36740560dd2..2ae38044df0 100644 --- a/src/hotspot/share/jvmci/jvmci_globals.cpp +++ b/src/hotspot/share/jvmci/jvmci_globals.cpp @@ -26,6 +26,7 @@ #include "compiler/compilerDefinitions.hpp" #include "gc/shared/gcConfig.hpp" #include "jvm.h" +#include "jvmci/jvmci.hpp" #include "jvmci/jvmci_globals.hpp" #include "logging/log.hpp" #include "runtime/arguments.hpp" @@ -90,8 +91,7 @@ bool JVMCIGlobals::check_jvmci_flags_are_consistent() { if (EnableJVMCI) { if (FLAG_IS_DEFAULT(UseJVMCINativeLibrary) && !UseJVMCINativeLibrary) { - char path[JVM_MAXPATHLEN]; - if (os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), JVMCI_SHARED_LIBRARY_NAME)) { + if (JVMCI::shared_library_exists()) { // If a JVMCI native library is present, // we enable UseJVMCINativeLibrary by default. FLAG_SET_DEFAULT(UseJVMCINativeLibrary, true); diff --git a/src/hotspot/share/jvmci/jvmci_globals.hpp b/src/hotspot/share/jvmci/jvmci_globals.hpp index 30f2e6c2c73..4da49b24e6e 100644 --- a/src/hotspot/share/jvmci/jvmci_globals.hpp +++ b/src/hotspot/share/jvmci/jvmci_globals.hpp @@ -45,7 +45,7 @@ class fileStream; constraint) \ \ product(bool, EnableJVMCI, false, EXPERIMENTAL, \ - "Enable JVMCI") \ + "Enable JVMCI. Defaults to true if UseJVMCICompiler is true.") \ \ product(bool, UseGraalJIT, false, EXPERIMENTAL, \ "Select the Graal JVMCI compiler. This is an alias for: " \ @@ -140,12 +140,14 @@ class fileStream; product(bool, UseJVMCINativeLibrary, false, EXPERIMENTAL, \ "Execute JVMCI Java code from a shared library (\"libjvmci\") " \ "instead of loading it from class files and executing it " \ - "on the HotSpot heap. Defaults to true if EnableJVMCI is " \ - "true and a JVMCI native library is available.") \ + "on the HotSpot heap. Defaults to true if UseJVMCICompiler or " \ + "EnableJVMCI is true and a JVMCI native library is available.") \ \ - product(double, JVMCINativeLibraryThreadFraction, 0.33, EXPERIMENTAL, \ + product(double, JVMCINativeLibraryThreadFraction, 0.66, EXPERIMENTAL, \ "The fraction of compiler threads used by libjvmci. " \ - "The remaining compiler threads are used by C1.") \ + "The remaining compiler threads are used by C1. " \ + "Reducing this value could reduce the max RSS but " \ + "also increase the warmup time.") \ range(0.0, 1.0) \ \ product(ccstr, JVMCINativeLibraryErrorFile, nullptr, EXPERIMENTAL, \ diff --git a/src/hotspot/share/jvmci/vmStructs_jvmci.cpp b/src/hotspot/share/jvmci/vmStructs_jvmci.cpp index df77e8a2882..13b20893219 100644 --- a/src/hotspot/share/jvmci/vmStructs_jvmci.cpp +++ b/src/hotspot/share/jvmci/vmStructs_jvmci.cpp @@ -246,6 +246,7 @@ nonstatic_field(JavaThread, _lock_stack, LockStack) \ nonstatic_field(JavaThread, _om_cache, OMCache) \ nonstatic_field(JavaThread, _cont_entry, ContinuationEntry*) \ + nonstatic_field(JavaThread, _unlocked_inflated_monitor, ObjectMonitor*) \ JVMTI_ONLY(nonstatic_field(JavaThread, _is_in_VTMS_transition, bool)) \ JVMTI_ONLY(nonstatic_field(JavaThread, _is_in_tmp_VTMS_transition, bool)) \ JVMTI_ONLY(nonstatic_field(JavaThread, _is_disable_suspend, bool)) \ diff --git a/src/hotspot/share/oops/compressedOops.cpp b/src/hotspot/share/oops/compressedOops.cpp index 98a4438383a..ec41dd85219 100644 --- a/src/hotspot/share/oops/compressedOops.cpp +++ b/src/hotspot/share/oops/compressedOops.cpp @@ -61,7 +61,7 @@ void CompressedOops::initialize(const ReservedHeapSpace& heap_space) { } if ((uint64_t)heap_space.end() <= OopEncodingHeapMax) { // Did reserve heap below 32Gb. Can use base == 0; - set_base(0); + set_base(nullptr); } else { set_base((address)heap_space.compressed_oop_base()); } @@ -115,7 +115,7 @@ CompressedOops::Mode CompressedOops::mode() { return DisjointBaseNarrowOop; } - if (base() != 0) { + if (base() != nullptr) { return HeapBasedNarrowOop; } @@ -166,7 +166,7 @@ void CompressedOops::print_mode(outputStream* st) { st->print(", Compressed Oops mode: %s", mode_to_string(mode())); - if (base() != 0) { + if (base() != nullptr) { st->print(": " PTR_FORMAT, p2i(base())); } diff --git a/src/hotspot/share/oops/constantPool.hpp b/src/hotspot/share/oops/constantPool.hpp index 7a17c62ddaf..bcc9a08dd6c 100644 --- a/src/hotspot/share/oops/constantPool.hpp +++ b/src/hotspot/share/oops/constantPool.hpp @@ -37,6 +37,7 @@ #include "utilities/align.hpp" #include "utilities/bytes.hpp" #include "utilities/constantTag.hpp" +#include "utilities/macros.hpp" #include "utilities/resourceHash.hpp" // A ConstantPool is an array containing class constants as described in the @@ -781,7 +782,7 @@ class ConstantPool : public Metadata { int pre_resolve_shared_klasses(TRAPS); // Debugging - const char* printable_name_at(int cp_index) PRODUCT_RETURN0; + const char* printable_name_at(int cp_index) PRODUCT_RETURN_NULL; private: diff --git a/src/hotspot/share/oops/instanceKlass.cpp b/src/hotspot/share/oops/instanceKlass.cpp index fd198f54fc9..5e226a90764 100644 --- a/src/hotspot/share/oops/instanceKlass.cpp +++ b/src/hotspot/share/oops/instanceKlass.cpp @@ -2721,6 +2721,13 @@ static void clear_all_breakpoints(Method* m) { #endif void InstanceKlass::unload_class(InstanceKlass* ik) { + + if (ik->is_scratch_class()) { + assert(ik->dependencies().is_empty(), "dependencies should be empty for scratch classes"); + return; + } + assert(ik->is_loaded(), "class should be loaded " PTR_FORMAT, p2i(ik)); + // Release dependencies. ik->dependencies().remove_all_dependents(); diff --git a/src/hotspot/share/opto/buildOopMap.cpp b/src/hotspot/share/opto/buildOopMap.cpp index 4591e87da2d..b553cc6ea69 100644 --- a/src/hotspot/share/opto/buildOopMap.cpp +++ b/src/hotspot/share/opto/buildOopMap.cpp @@ -235,6 +235,13 @@ OopMap *OopFlow::build_oop_map( Node *n, int max_reg, PhaseRegAlloc *regalloc, i Node *def = _defs[reg]; // Get reaching def assert( def, "since live better have reaching def" ); + if (def->is_MachTemp()) { + assert(!def->bottom_type()->isa_oop_ptr(), + "ADLC only assigns OOP types to MachTemp defs corresponding to xRegN operands"); + // Exclude MachTemp definitions even if they are typed as oops. + continue; + } + // Classify the reaching def as oop, derived, callee-save, dead, or other const Type *t = def->bottom_type(); if( t->isa_oop_ptr() ) { // Oop or derived? diff --git a/src/hotspot/share/opto/c2_CodeStubs.hpp b/src/hotspot/share/opto/c2_CodeStubs.hpp index 5db7596e072..318bc2f45fc 100644 --- a/src/hotspot/share/opto/c2_CodeStubs.hpp +++ b/src/hotspot/share/opto/c2_CodeStubs.hpp @@ -105,7 +105,6 @@ class C2FastUnlockLightweightStub : public C2CodeStub { Register _thread; Label _slow_path; Label _push_and_slow_path; - Label _check_successor; Label _unlocked_continuation; public: C2FastUnlockLightweightStub(Register obj, Register mark, Register t, Register thread) : C2CodeStub(), @@ -114,7 +113,6 @@ class C2FastUnlockLightweightStub : public C2CodeStub { void emit(C2_MacroAssembler& masm); Label& slow_path() { return _slow_path; } Label& push_and_slow_path() { return _push_and_slow_path; } - Label& check_successor() { return _check_successor; } Label& unlocked_continuation() { return _unlocked_continuation; } Label& slow_path_continuation() { return continuation(); } }; diff --git a/src/hotspot/share/opto/c2compiler.cpp b/src/hotspot/share/opto/c2compiler.cpp index 117e06acd6f..151c320cadd 100644 --- a/src/hotspot/share/opto/c2compiler.cpp +++ b/src/hotspot/share/opto/c2compiler.cpp @@ -811,6 +811,7 @@ bool C2Compiler::is_intrinsic_supported(vmIntrinsics::ID id) { case vmIntrinsics::_VectorFromBitsCoerced: case vmIntrinsics::_VectorShuffleIota: case vmIntrinsics::_VectorShuffleToVector: + case vmIntrinsics::_VectorWrapShuffleIndexes: case vmIntrinsics::_VectorLoadOp: case vmIntrinsics::_VectorLoadMaskedOp: case vmIntrinsics::_VectorStoreOp: @@ -821,6 +822,7 @@ bool C2Compiler::is_intrinsic_supported(vmIntrinsics::ID id) { case vmIntrinsics::_VectorTest: case vmIntrinsics::_VectorBlend: case vmIntrinsics::_VectorRearrange: + case vmIntrinsics::_VectorSelectFrom: case vmIntrinsics::_VectorCompare: case vmIntrinsics::_VectorBroadcastInt: case vmIntrinsics::_VectorConvert: diff --git a/src/hotspot/share/opto/lcm.cpp b/src/hotspot/share/opto/lcm.cpp index 9db94748ca2..3c6de96074a 100644 --- a/src/hotspot/share/opto/lcm.cpp +++ b/src/hotspot/share/opto/lcm.cpp @@ -161,6 +161,14 @@ void PhaseCFG::implicit_null_check(Block* block, Node *proj, Node *val, int allo Node *m = val->out(i); if( !m->is_Mach() ) continue; MachNode *mach = m->as_Mach(); + if (mach->barrier_data() != 0) { + // Using memory accesses with barriers to perform implicit null checks is + // not supported. These operations might expand into multiple assembly + // instructions during code emission, including new memory accesses (e.g. + // in G1's pre-barrier), which would invalidate the implicit null + // exception table. + continue; + } was_store = false; int iop = mach->ideal_Opcode(); switch( iop ) { diff --git a/src/hotspot/share/opto/library_call.cpp b/src/hotspot/share/opto/library_call.cpp index 8bbb2f8115e..4d182e06a56 100644 --- a/src/hotspot/share/opto/library_call.cpp +++ b/src/hotspot/share/opto/library_call.cpp @@ -717,6 +717,8 @@ bool LibraryCallKit::try_to_inline(int predicate) { return inline_vector_mask_operation(); case vmIntrinsics::_VectorShuffleToVector: return inline_vector_shuffle_to_vector(); + case vmIntrinsics::_VectorWrapShuffleIndexes: + return inline_vector_wrap_shuffle_indexes(); case vmIntrinsics::_VectorLoadOp: return inline_vector_mem_operation(/*is_store=*/false); case vmIntrinsics::_VectorLoadMaskedOp: @@ -737,6 +739,8 @@ bool LibraryCallKit::try_to_inline(int predicate) { return inline_vector_blend(); case vmIntrinsics::_VectorRearrange: return inline_vector_rearrange(); + case vmIntrinsics::_VectorSelectFrom: + return inline_vector_select_from(); case vmIntrinsics::_VectorCompare: return inline_vector_compare(); case vmIntrinsics::_VectorBroadcastInt: @@ -2048,7 +2052,7 @@ LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset, BasicType type) if (base_type == nullptr) { // Unknown type. return Type::AnyPtr; - } else if (base_type == TypePtr::NULL_PTR) { + } else if (_gvn.type(base->uncast()) == TypePtr::NULL_PTR) { // Since this is a null+long form, we have to switch to a rawptr. base = _gvn.transform(new CastX2PNode(offset)); offset = MakeConX(0); @@ -2366,8 +2370,9 @@ bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, c SafePointNode* old_map = clone_map(); Node* adr = make_unsafe_address(base, offset, type, kind == Relaxed); + assert(!stopped(), "Inlining of unsafe access failed: address construction stopped unexpectedly"); - if (_gvn.type(base)->isa_ptr() == TypePtr::NULL_PTR) { + if (_gvn.type(base->uncast())->isa_ptr() == TypePtr::NULL_PTR) { if (type != T_OBJECT) { decorators |= IN_NATIVE; // off-heap primitive access } else { diff --git a/src/hotspot/share/opto/library_call.hpp b/src/hotspot/share/opto/library_call.hpp index dd74734802f..10375fc23f6 100644 --- a/src/hotspot/share/opto/library_call.hpp +++ b/src/hotspot/share/opto/library_call.hpp @@ -353,6 +353,7 @@ class LibraryCallKit : public GraphKit { bool inline_vector_nary_operation(int n); bool inline_vector_frombits_coerced(); bool inline_vector_shuffle_to_vector(); + bool inline_vector_wrap_shuffle_indexes(); bool inline_vector_shuffle_iota(); Node* partially_wrap_indexes(Node* index_vec, int num_elem, BasicType type_bt); bool inline_vector_mask_operation(); @@ -363,6 +364,7 @@ class LibraryCallKit : public GraphKit { bool inline_vector_test(); bool inline_vector_blend(); bool inline_vector_rearrange(); + bool inline_vector_select_from(); bool inline_vector_compare(); bool inline_vector_broadcast_int(); bool inline_vector_convert(); diff --git a/src/hotspot/share/opto/matcher.cpp b/src/hotspot/share/opto/matcher.cpp index bf773d43d3d..6d96bff1c1c 100644 --- a/src/hotspot/share/opto/matcher.cpp +++ b/src/hotspot/share/opto/matcher.cpp @@ -1594,6 +1594,14 @@ static bool match_into_reg( const Node *n, Node *m, Node *control, int i, bool s // the same register. See find_shared_node. return false; } else { // Not a constant + if (!shared && Matcher::is_encode_and_store_pattern(n, m)) { + // Make it possible to match "encode and store" patterns with non-shared + // encode operations that are pinned to a control node (e.g. by CastPP + // node removal in final graph reshaping). The matched instruction cannot + // float above the encode's control node because it is pinned to the + // store's control node. + return false; + } // Stop recursion if they have different Controls. Node* m_control = m->in(0); // Control of load's memory can post-dominates load's control. @@ -2833,6 +2841,18 @@ bool Matcher::is_non_long_integral_vector(const Node* n) { return is_subword_type(bt) || bt == T_INT; } +bool Matcher::is_encode_and_store_pattern(const Node* n, const Node* m) { + if (n == nullptr || + m == nullptr || + n->Opcode() != Op_StoreN || + !m->is_EncodeP() || + n->as_Store()->barrier_data() == 0) { + return false; + } + assert(m == n->in(MemNode::ValueIn), "m should be input to n"); + return true; +} + #ifdef ASSERT bool Matcher::verify_after_postselect_cleanup() { assert(!C->failing(), "sanity"); diff --git a/src/hotspot/share/opto/matcher.hpp b/src/hotspot/share/opto/matcher.hpp index 84e48086f92..25762835088 100644 --- a/src/hotspot/share/opto/matcher.hpp +++ b/src/hotspot/share/opto/matcher.hpp @@ -385,6 +385,8 @@ class Matcher : public PhaseTransform { return ((bt & BoolTest::unsigned_compare) == BoolTest::unsigned_compare); } + static bool is_encode_and_store_pattern(const Node* n, const Node* m); + // These calls are all generated by the ADLC // Java-Java calling convention diff --git a/src/hotspot/share/opto/memnode.cpp b/src/hotspot/share/opto/memnode.cpp index eee14e5ba03..66139188260 100644 --- a/src/hotspot/share/opto/memnode.cpp +++ b/src/hotspot/share/opto/memnode.cpp @@ -4644,6 +4644,11 @@ intptr_t InitializeNode::can_capture_store(StoreNode* st, PhaseGVN* phase, bool Node* mem = st->in(MemNode::Memory); if (!(mem->is_Proj() && mem->in(0) == this)) return FAIL; // must not be preceded by other stores + BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); + if ((st->Opcode() == Op_StoreP || st->Opcode() == Op_StoreN) && + !bs->can_initialize_object(st)) { + return FAIL; + } Node* adr = st->in(MemNode::Address); intptr_t offset; AllocateNode* alloc = AllocateNode::Ideal_allocation(adr, phase, offset); diff --git a/src/hotspot/share/opto/memnode.hpp b/src/hotspot/share/opto/memnode.hpp index 85d206749f6..323ab3dba7d 100644 --- a/src/hotspot/share/opto/memnode.hpp +++ b/src/hotspot/share/opto/memnode.hpp @@ -124,11 +124,7 @@ class MemNode : public Node { // Raw access function, to allow copying of adr_type efficiently in // product builds and retain the debug info for debug builds. const TypePtr *raw_adr_type() const { -#ifdef ASSERT - return _adr_type; -#else - return 0; -#endif + return DEBUG_ONLY(_adr_type) NOT_DEBUG(nullptr); } // Return the barrier data of n, if available, or 0 otherwise. diff --git a/src/hotspot/share/opto/output.cpp b/src/hotspot/share/opto/output.cpp index b3f251bb361..260f887347f 100644 --- a/src/hotspot/share/opto/output.cpp +++ b/src/hotspot/share/opto/output.cpp @@ -2022,6 +2022,8 @@ void PhaseOutput::FillExceptionTables(uint cnt, uint *call_returns, uint *inct_s // Handle implicit null exception table updates if (n->is_MachNullCheck()) { + assert(n->in(1)->as_Mach()->barrier_data() == 0, + "Implicit null checks on memory accesses with barriers are not yet supported"); uint block_num = block->non_connector_successor(0)->_pre_order; _inc_table.append(inct_starts[inct_cnt++], blk_labels[block_num].loc_pos()); continue; diff --git a/src/hotspot/share/opto/type.cpp b/src/hotspot/share/opto/type.cpp index 967b4a815d0..73f852c0f04 100644 --- a/src/hotspot/share/opto/type.cpp +++ b/src/hotspot/share/opto/type.cpp @@ -3260,23 +3260,28 @@ void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const { // Convenience common pre-built type. const TypeOopPtr *TypeOopPtr::BOTTOM; -TypeInterfaces::TypeInterfaces() - : Type(Interfaces), _list(Compile::current()->type_arena(), 0, 0, nullptr), +TypeInterfaces::TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces) + : Type(Interfaces), _interfaces(interfaces_base, nb_interfaces), _hash(0), _exact_klass(nullptr) { - DEBUG_ONLY(_initialized = true); -} - -TypeInterfaces::TypeInterfaces(GrowableArray* interfaces) - : Type(Interfaces), _list(Compile::current()->type_arena(), interfaces->length(), 0, nullptr), - _hash(0), _exact_klass(nullptr) { - for (int i = 0; i < interfaces->length(); i++) { - add(interfaces->at(i)); - } + _interfaces.sort(compare); initialize(); } const TypeInterfaces* TypeInterfaces::make(GrowableArray* interfaces) { - TypeInterfaces* result = (interfaces == nullptr) ? new TypeInterfaces() : new TypeInterfaces(interfaces); + // hashcons() can only delete the last thing that was allocated: to + // make sure all memory for the newly created TypeInterfaces can be + // freed if an identical one exists, allocate space for the array of + // interfaces right after the TypeInterfaces object so that they + // form a contiguous piece of memory. + int nb_interfaces = interfaces == nullptr ? 0 : interfaces->length(); + size_t total_size = sizeof(TypeInterfaces) + nb_interfaces * sizeof(ciInstanceKlass*); + + void* allocated_mem = operator new(total_size); + ciInstanceKlass** interfaces_base = (ciInstanceKlass**)((char*)allocated_mem + sizeof(TypeInterfaces)); + for (int i = 0; i < nb_interfaces; ++i) { + interfaces_base[i] = interfaces->at(i); + } + TypeInterfaces* result = ::new (allocated_mem) TypeInterfaces(interfaces_base, nb_interfaces); return (const TypeInterfaces*)result->hashcons(); } @@ -3295,20 +3300,18 @@ int TypeInterfaces::compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& return 0; } -void TypeInterfaces::add(ciInstanceKlass* interface) { - assert(interface->is_interface(), "for interfaces only"); - _list.insert_sorted(interface); - verify(); +int TypeInterfaces::compare(ciInstanceKlass** k1, ciInstanceKlass** k2) { + return compare(*k1, *k2); } bool TypeInterfaces::eq(const Type* t) const { const TypeInterfaces* other = (const TypeInterfaces*)t; - if (_list.length() != other->_list.length()) { + if (_interfaces.length() != other->_interfaces.length()) { return false; } - for (int i = 0; i < _list.length(); i++) { - ciKlass* k1 = _list.at(i); - ciKlass* k2 = other->_list.at(i); + for (int i = 0; i < _interfaces.length(); i++) { + ciKlass* k1 = _interfaces.at(i); + ciKlass* k2 = other->_interfaces.at(i); if (!k1->equals(k2)) { return false; } @@ -3319,12 +3322,12 @@ bool TypeInterfaces::eq(const Type* t) const { bool TypeInterfaces::eq(ciInstanceKlass* k) const { assert(k->is_loaded(), "should be loaded"); GrowableArray* interfaces = k->transitive_interfaces(); - if (_list.length() != interfaces->length()) { + if (_interfaces.length() != interfaces->length()) { return false; } for (int i = 0; i < interfaces->length(); i++) { bool found = false; - _list.find_sorted(interfaces->at(i), found); + _interfaces.find_sorted(interfaces->at(i), found); if (!found) { return false; } @@ -3344,8 +3347,8 @@ const Type* TypeInterfaces::xdual() const { void TypeInterfaces::compute_hash() { uint hash = 0; - for (int i = 0; i < _list.length(); i++) { - ciKlass* k = _list.at(i); + for (int i = 0; i < _interfaces.length(); i++) { + ciKlass* k = _interfaces.at(i); hash += k->hash(); } _hash = hash; @@ -3356,13 +3359,13 @@ static int compare_interfaces(ciInstanceKlass** k1, ciInstanceKlass** k2) { } void TypeInterfaces::dump(outputStream* st) const { - if (_list.length() == 0) { + if (_interfaces.length() == 0) { return; } ResourceMark rm; st->print(" ("); GrowableArray interfaces; - interfaces.appendAll(&_list); + interfaces.appendAll(&_interfaces); // Sort the interfaces so they are listed in the same order from one run to the other of the same compilation interfaces.sort(compare_interfaces); for (int i = 0; i < interfaces.length(); i++) { @@ -3377,9 +3380,9 @@ void TypeInterfaces::dump(outputStream* st) const { #ifdef ASSERT void TypeInterfaces::verify() const { - for (int i = 1; i < _list.length(); i++) { - ciInstanceKlass* k1 = _list.at(i-1); - ciInstanceKlass* k2 = _list.at(i); + for (int i = 1; i < _interfaces.length(); i++) { + ciInstanceKlass* k1 = _interfaces.at(i-1); + ciInstanceKlass* k2 = _interfaces.at(i); assert(compare(k2, k1) > 0, "should be ordered"); assert(k1 != k2, "no duplicate"); } @@ -3390,23 +3393,23 @@ const TypeInterfaces* TypeInterfaces::union_with(const TypeInterfaces* other) co GrowableArray result_list; int i = 0; int j = 0; - while (i < _list.length() || j < other->_list.length()) { - while (i < _list.length() && - (j >= other->_list.length() || - compare(_list.at(i), other->_list.at(j)) < 0)) { - result_list.push(_list.at(i)); + while (i < _interfaces.length() || j < other->_interfaces.length()) { + while (i < _interfaces.length() && + (j >= other->_interfaces.length() || + compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) { + result_list.push(_interfaces.at(i)); i++; } - while (j < other->_list.length() && - (i >= _list.length() || - compare(other->_list.at(j), _list.at(i)) < 0)) { - result_list.push(other->_list.at(j)); + while (j < other->_interfaces.length() && + (i >= _interfaces.length() || + compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) { + result_list.push(other->_interfaces.at(j)); j++; } - if (i < _list.length() && - j < other->_list.length() && - _list.at(i) == other->_list.at(j)) { - result_list.push(_list.at(i)); + if (i < _interfaces.length() && + j < other->_interfaces.length() && + _interfaces.at(i) == other->_interfaces.at(j)) { + result_list.push(_interfaces.at(i)); i++; j++; } @@ -3414,14 +3417,14 @@ const TypeInterfaces* TypeInterfaces::union_with(const TypeInterfaces* other) co const TypeInterfaces* result = TypeInterfaces::make(&result_list); #ifdef ASSERT result->verify(); - for (int i = 0; i < _list.length(); i++) { - assert(result->_list.contains(_list.at(i)), "missing"); + for (int i = 0; i < _interfaces.length(); i++) { + assert(result->_interfaces.contains(_interfaces.at(i)), "missing"); } - for (int i = 0; i < other->_list.length(); i++) { - assert(result->_list.contains(other->_list.at(i)), "missing"); + for (int i = 0; i < other->_interfaces.length(); i++) { + assert(result->_interfaces.contains(other->_interfaces.at(i)), "missing"); } - for (int i = 0; i < result->_list.length(); i++) { - assert(_list.contains(result->_list.at(i)) || other->_list.contains(result->_list.at(i)), "missing"); + for (int i = 0; i < result->_interfaces.length(); i++) { + assert(_interfaces.contains(result->_interfaces.at(i)) || other->_interfaces.contains(result->_interfaces.at(i)), "missing"); } #endif return result; @@ -3431,21 +3434,21 @@ const TypeInterfaces* TypeInterfaces::intersection_with(const TypeInterfaces* ot GrowableArray result_list; int i = 0; int j = 0; - while (i < _list.length() || j < other->_list.length()) { - while (i < _list.length() && - (j >= other->_list.length() || - compare(_list.at(i), other->_list.at(j)) < 0)) { + while (i < _interfaces.length() || j < other->_interfaces.length()) { + while (i < _interfaces.length() && + (j >= other->_interfaces.length() || + compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) { i++; } - while (j < other->_list.length() && - (i >= _list.length() || - compare(other->_list.at(j), _list.at(i)) < 0)) { + while (j < other->_interfaces.length() && + (i >= _interfaces.length() || + compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) { j++; } - if (i < _list.length() && - j < other->_list.length() && - _list.at(i) == other->_list.at(j)) { - result_list.push(_list.at(i)); + if (i < _interfaces.length() && + j < other->_interfaces.length() && + _interfaces.at(i) == other->_interfaces.at(j)) { + result_list.push(_interfaces.at(i)); i++; j++; } @@ -3453,14 +3456,14 @@ const TypeInterfaces* TypeInterfaces::intersection_with(const TypeInterfaces* ot const TypeInterfaces* result = TypeInterfaces::make(&result_list); #ifdef ASSERT result->verify(); - for (int i = 0; i < _list.length(); i++) { - assert(!other->_list.contains(_list.at(i)) || result->_list.contains(_list.at(i)), "missing"); + for (int i = 0; i < _interfaces.length(); i++) { + assert(!other->_interfaces.contains(_interfaces.at(i)) || result->_interfaces.contains(_interfaces.at(i)), "missing"); } - for (int i = 0; i < other->_list.length(); i++) { - assert(!_list.contains(other->_list.at(i)) || result->_list.contains(other->_list.at(i)), "missing"); + for (int i = 0; i < other->_interfaces.length(); i++) { + assert(!_interfaces.contains(other->_interfaces.at(i)) || result->_interfaces.contains(other->_interfaces.at(i)), "missing"); } - for (int i = 0; i < result->_list.length(); i++) { - assert(_list.contains(result->_list.at(i)) && other->_list.contains(result->_list.at(i)), "missing"); + for (int i = 0; i < result->_interfaces.length(); i++) { + assert(_interfaces.contains(result->_interfaces.at(i)) && other->_interfaces.contains(result->_interfaces.at(i)), "missing"); } #endif return result; @@ -3473,13 +3476,13 @@ ciInstanceKlass* TypeInterfaces::exact_klass() const { } void TypeInterfaces::compute_exact_klass() { - if (_list.length() == 0) { + if (_interfaces.length() == 0) { _exact_klass = nullptr; return; } ciInstanceKlass* res = nullptr; - for (int i = 0; i < _list.length(); i++) { - ciInstanceKlass* interface = _list.at(i); + for (int i = 0; i < _interfaces.length(); i++) { + ciInstanceKlass* interface = _interfaces.at(i); if (eq(interface)) { assert(res == nullptr, ""); res = interface; @@ -3490,8 +3493,8 @@ void TypeInterfaces::compute_exact_klass() { #ifdef ASSERT void TypeInterfaces::verify_is_loaded() const { - for (int i = 0; i < _list.length(); i++) { - ciKlass* interface = _list.at(i); + for (int i = 0; i < _interfaces.length(); i++) { + ciKlass* interface = _interfaces.at(i); assert(interface->is_loaded(), "Interface not loaded"); } } diff --git a/src/hotspot/share/opto/type.hpp b/src/hotspot/share/opto/type.hpp index b9883d51391..902155e975d 100644 --- a/src/hotspot/share/opto/type.hpp +++ b/src/hotspot/share/opto/type.hpp @@ -877,19 +877,18 @@ class TypeVectMask : public TypeVect { // Set of implemented interfaces. Referenced from TypeOopPtr and TypeKlassPtr. class TypeInterfaces : public Type { private: - GrowableArray _list; + GrowableArrayFromArray _interfaces; uint _hash; ciInstanceKlass* _exact_klass; DEBUG_ONLY(bool _initialized;) void initialize(); - void add(ciInstanceKlass* interface); void verify() const NOT_DEBUG_RETURN; void compute_hash(); void compute_exact_klass(); - TypeInterfaces(); - TypeInterfaces(GrowableArray* interfaces); + + TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces); NONCOPYABLE(TypeInterfaces); public: @@ -904,12 +903,13 @@ class TypeInterfaces : public Type { bool contains(const TypeInterfaces* other) const { return intersection_with(other)->eq(other); } - bool empty() const { return _list.length() == 0; } + bool empty() const { return _interfaces.length() == 0; } ciInstanceKlass* exact_klass() const; void verify_is_loaded() const NOT_DEBUG_RETURN; static int compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2); + static int compare(ciInstanceKlass** k1, ciInstanceKlass** k2); const Type* xmeet(const Type* t) const; diff --git a/src/hotspot/share/opto/vectorIntrinsics.cpp b/src/hotspot/share/opto/vectorIntrinsics.cpp index cfcd903e79d..37536198229 100644 --- a/src/hotspot/share/opto/vectorIntrinsics.cpp +++ b/src/hotspot/share/opto/vectorIntrinsics.cpp @@ -757,6 +757,64 @@ bool LibraryCallKit::inline_vector_shuffle_to_vector() { return true; } +// public static +// > +// SH wrapShuffleIndexes(Class eClass, Class shClass, SH sh, int length, +// ShuffleWrapIndexesOperation defaultImpl) +bool LibraryCallKit::inline_vector_wrap_shuffle_indexes() { + const TypeInstPtr* elem_klass = gvn().type(argument(0))->isa_instptr(); + const TypeInstPtr* shuffle_klass = gvn().type(argument(1))->isa_instptr(); + Node* shuffle = argument(2); + const TypeInt* vlen = gvn().type(argument(3))->isa_int(); + + if (elem_klass == nullptr || shuffle_klass == nullptr || shuffle->is_top() || vlen == nullptr || + !vlen->is_con() || shuffle_klass->const_oop() == nullptr) { + // not enough info for intrinsification + return false; + } + + if (!is_klass_initialized(shuffle_klass)) { + log_if_needed(" ** klass argument not initialized"); + return false; + } + + int num_elem = vlen->get_con(); + if ((num_elem < 4) || !is_power_of_2(num_elem)) { + log_if_needed(" ** vlen < 4 or not power of two=%d", num_elem); + return false; + } + + // Shuffles use byte array based backing storage + BasicType shuffle_bt = T_BYTE; + if (!arch_supports_vector(Op_AndV, num_elem, shuffle_bt, VecMaskNotUsed) || + !arch_supports_vector(Op_Replicate, num_elem, shuffle_bt, VecMaskNotUsed)) { + log_if_needed(" ** not supported: op=wrapShuffleIndexes vlen=%d etype=%s", + num_elem, type2name(shuffle_bt)); + return false; + } + + ciKlass* sbox_klass = shuffle_klass->const_oop()->as_instance()->java_lang_Class_klass(); + const TypeInstPtr* shuffle_box_type = TypeInstPtr::make_exact(TypePtr::NotNull, sbox_klass); + + // Unbox shuffle with true flag to indicate its load shuffle to vector + // shuffle is a byte array + Node* shuffle_vec = unbox_vector(shuffle, shuffle_box_type, shuffle_bt, num_elem, true); + + const TypeVect* vt = TypeVect::make(shuffle_bt, num_elem); + const Type* shuffle_type_bt = Type::get_const_basic_type(shuffle_bt); + Node* mod_mask = gvn().makecon(TypeInt::make(num_elem-1)); + Node* bcast_mod_mask = gvn().transform(VectorNode::scalar2vector(mod_mask, num_elem, shuffle_type_bt)); + // Wrap the indices greater than lane count. + Node* res = gvn().transform(VectorNode::make(Op_AndV, shuffle_vec, bcast_mod_mask, vt)); + + // Wrap it up in VectorBox to keep object type information. + res = box_vector(res, shuffle_box_type, shuffle_bt, num_elem); + set_result(res); + C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(shuffle_bt)))); + return true; +} + // public static // , @@ -2044,6 +2102,150 @@ static address get_svml_address(int vop, int bits, BasicType bt, char* name_ptr, return addr; } +// public static +// , +// M extends VectorMask, +// E> +// V selectFromOp(Class vClass, Class mClass, Class eClass, +// int length, V v1, V v2, M m, +// VectorSelectFromOp defaultImpl) +bool LibraryCallKit::inline_vector_select_from() { + const TypeInstPtr* vector_klass = gvn().type(argument(0))->isa_instptr(); + const TypeInstPtr* mask_klass = gvn().type(argument(1))->isa_instptr(); + const TypeInstPtr* elem_klass = gvn().type(argument(2))->isa_instptr(); + const TypeInt* vlen = gvn().type(argument(3))->isa_int(); + + if (vector_klass == nullptr || elem_klass == nullptr || vlen == nullptr || + vector_klass->const_oop() == nullptr || + elem_klass->const_oop() == nullptr || + !vlen->is_con()) { + log_if_needed(" ** missing constant: vclass=%s etype=%s vlen=%s", + NodeClassNames[argument(0)->Opcode()], + NodeClassNames[argument(2)->Opcode()], + NodeClassNames[argument(3)->Opcode()]); + return false; // not enough info for intrinsification + } + if (!is_klass_initialized(vector_klass)) { + log_if_needed(" ** klass argument not initialized"); + return false; + } + ciType* elem_type = elem_klass->const_oop()->as_instance()->java_mirror_type(); + if (!elem_type->is_primitive_type()) { + log_if_needed(" ** not a primitive bt=%d", elem_type->basic_type()); + return false; // should be primitive type + } + BasicType elem_bt = elem_type->basic_type(); + int num_elem = vlen->get_con(); + if (!is_power_of_2(num_elem)) { + log_if_needed(" ** vlen not power of two=%d", num_elem); + return false; + } + + int cast_vopc = VectorCastNode::opcode(-1, elem_bt); // from vector of type elem_bt + if (!arch_supports_vector(Op_VectorLoadShuffle, num_elem, elem_bt, VecMaskNotUsed)|| + !arch_supports_vector(Op_AndV, num_elem, T_BYTE, VecMaskNotUsed) || + !arch_supports_vector(Op_Replicate, num_elem, T_BYTE, VecMaskNotUsed) || + !arch_supports_vector(cast_vopc, num_elem, T_BYTE, VecMaskNotUsed)) { + log_if_needed(" ** not supported: arity=0 op=selectFrom vlen=%d etype=%s ismask=no", + num_elem, type2name(elem_bt)); + return false; // not supported + } + + bool is_masked_op = argument(6)->bottom_type() != TypePtr::NULL_PTR; + bool use_predicate = is_masked_op; + if (is_masked_op && + (mask_klass == nullptr || + mask_klass->const_oop() == nullptr || + !is_klass_initialized(mask_klass))) { + log_if_needed(" ** mask_klass argument not initialized"); + return false; // not supported + } + VectorMaskUseType checkFlags = (VectorMaskUseType)(is_masked_op ? (VecMaskUseLoad | VecMaskUsePred) : VecMaskNotUsed); + if (!arch_supports_vector(Op_VectorRearrange, num_elem, elem_bt, checkFlags)) { + use_predicate = false; + if(!is_masked_op || + (!arch_supports_vector(Op_VectorRearrange, num_elem, elem_bt, VecMaskNotUsed) || + !arch_supports_vector(Op_VectorBlend, num_elem, elem_bt, VecMaskUseLoad) || + !arch_supports_vector(Op_Replicate, num_elem, elem_bt, VecMaskNotUsed))) { + log_if_needed(" ** not supported: op=selectFrom vlen=%d etype=%s is_masked_op=%d", + num_elem, type2name(elem_bt), is_masked_op); + return false; // not supported + } + } + ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass(); + const TypeInstPtr* vbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_klass); + + // v1 is the index vector + Node* v1 = unbox_vector(argument(4), vbox_type, elem_bt, num_elem); + // v2 is the vector being rearranged + Node* v2 = unbox_vector(argument(5), vbox_type, elem_bt, num_elem); + + if (v1 == nullptr) { + log_if_needed(" ** unbox failed v1=%s", NodeClassNames[argument(4)->Opcode()]); + return false; // operand unboxing failed + } + + if (v2 == nullptr) { + log_if_needed(" ** unbox failed v2=%s", NodeClassNames[argument(5)->Opcode()]); + return false; // operand unboxing failed + } + + Node* mask = nullptr; + if (is_masked_op) { + ciKlass* mbox_klass = mask_klass->const_oop()->as_instance()->java_lang_Class_klass(); + const TypeInstPtr* mbox_type = TypeInstPtr::make_exact(TypePtr::NotNull, mbox_klass); + mask = unbox_vector(argument(6), mbox_type, elem_bt, num_elem); + if (mask == nullptr) { + log_if_needed(" ** unbox failed mask=%s", NodeClassNames[argument(6)->Opcode()]); + return false; + } + } + + // cast index vector from elem_bt vector to byte vector + const Type * byte_bt = Type::get_const_basic_type(T_BYTE); + const TypeVect * byte_vt = TypeVect::make(byte_bt, num_elem); + Node* byte_shuffle = gvn().transform(VectorCastNode::make(cast_vopc, v1, T_BYTE, num_elem)); + + // wrap the byte vector lanes to (num_elem - 1) to form the shuffle vector where num_elem is vector length + // this is a simple AND operation as we come here only for power of two vector length + Node* mod_val = gvn().makecon(TypeInt::make(num_elem-1)); + Node* bcast_mod = gvn().transform(VectorNode::scalar2vector(mod_val, num_elem, byte_bt)); + byte_shuffle = gvn().transform(VectorNode::make(Op_AndV, byte_shuffle, bcast_mod, byte_vt)); + + // load the shuffle to use in rearrange + const TypeVect * shuffle_vt = TypeVect::make(elem_bt, num_elem); + Node* load_shuffle = gvn().transform(new VectorLoadShuffleNode(byte_shuffle, shuffle_vt)); + + // and finally rearrange + Node* rearrange = new VectorRearrangeNode(v2, load_shuffle); + if (is_masked_op) { + if (use_predicate) { + // masked rearrange is supported so use that directly + rearrange->add_req(mask); + rearrange->add_flag(Node::Flag_is_predicated_vector); + } else { + // masked rearrange is not supported so emulate usig blend + const TypeVect* vt = v1->bottom_type()->is_vect(); + rearrange = gvn().transform(rearrange); + + // create a zero vector with each lane element set as zero + Node* zero = gvn().makecon(Type::get_zero_type(elem_bt)); + Node* zerovec = gvn().transform(VectorNode::scalar2vector(zero, num_elem, Type::get_const_basic_type(elem_bt))); + + // For each lane for which mask is set, blend in the rearranged lane into zero vector + rearrange = new VectorBlendNode(zerovec, rearrange, mask); + } + } + rearrange = gvn().transform(rearrange); + + // box the result + Node* box = box_vector(rearrange, vbox_type, elem_bt, num_elem); + set_result(box); + + C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt)))); + return true; +} + Node* LibraryCallKit::gen_call_to_svml(int vector_api_op_id, BasicType bt, int num_elem, Node* opd1, Node* opd2) { assert(UseVectorStubs, "sanity"); assert(vector_api_op_id >= VectorSupport::VECTOR_OP_SVML_START && vector_api_op_id <= VectorSupport::VECTOR_OP_SVML_END, "need valid op id"); diff --git a/src/hotspot/share/prims/jni.cpp b/src/hotspot/share/prims/jni.cpp index 1f115c783e6..a869e9821a0 100644 --- a/src/hotspot/share/prims/jni.cpp +++ b/src/hotspot/share/prims/jni.cpp @@ -444,9 +444,11 @@ JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID meth methodHandle m (THREAD, Method::resolve_jmethod_id(method_id)); assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match"); oop reflection_method; - if (m->is_initializer()) { + if (m->is_object_initializer()) { reflection_method = Reflection::new_constructor(m, CHECK_NULL); } else { + // Note: Static initializers can theoretically be here, if JNI users manage + // to get their jmethodID. Record them as plain methods. reflection_method = Reflection::new_method(m, false, CHECK_NULL); } ret = JNIHandles::make_local(THREAD, reflection_method); diff --git a/src/hotspot/share/prims/jvm.cpp b/src/hotspot/share/prims/jvm.cpp index bf9874956ba..a246c2c50d6 100644 --- a/src/hotspot/share/prims/jvm.cpp +++ b/src/hotspot/share/prims/jvm.cpp @@ -1826,14 +1826,6 @@ JVM_ENTRY(jobjectArray, JVM_GetRecordComponents(JNIEnv* env, jclass ofClass)) } JVM_END -static bool select_method(const methodHandle& method, bool want_constructor) { - if (want_constructor) { - return (method->is_initializer() && !method->is_static()); - } else { - return (!method->is_initializer() && !method->is_overpass()); - } -} - static jobjectArray get_class_declared_methods_helper( JNIEnv *env, jclass ofClass, jboolean publicOnly, @@ -1866,14 +1858,22 @@ static jobjectArray get_class_declared_methods_helper( GrowableArray* idnums = new GrowableArray(methods_length); int num_methods = 0; + // Select methods matching the criteria. for (int i = 0; i < methods_length; i++) { - methodHandle method(THREAD, methods->at(i)); - if (select_method(method, want_constructor)) { - if (!publicOnly || method->is_public()) { - idnums->push(method->method_idnum()); - ++num_methods; - } + Method* method = methods->at(i); + if (want_constructor && !method->is_object_initializer()) { + continue; + } + if (!want_constructor && + (method->is_object_initializer() || method->is_static_initializer() || + method->is_overpass())) { + continue; } + if (publicOnly && !method->is_public()) { + continue; + } + idnums->push(method->method_idnum()); + ++num_methods; } // Allocate result @@ -2175,10 +2175,11 @@ static jobject get_method_at_helper(const constantPoolHandle& cp, jint index, bo THROW_MSG_NULL(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class"); } oop method; - if (!m->is_initializer() || m->is_static()) { - method = Reflection::new_method(m, true, CHECK_NULL); - } else { + if (m->is_object_initializer()) { method = Reflection::new_constructor(m, CHECK_NULL); + } else { + // new_method accepts as Method here + method = Reflection::new_method(m, true, CHECK_NULL); } return JNIHandles::make_local(THREAD, method); } diff --git a/src/hotspot/share/prims/methodHandles.cpp b/src/hotspot/share/prims/methodHandles.cpp index 4f33055d6a3..498da559cf5 100644 --- a/src/hotspot/share/prims/methodHandles.cpp +++ b/src/hotspot/share/prims/methodHandles.cpp @@ -313,8 +313,9 @@ oop MethodHandles::init_method_MemberName(Handle mname, CallInfo& info) { case CallInfo::direct_call: vmindex = Method::nonvirtual_vtable_index; if (m->is_static()) { + assert(!m->is_static_initializer(), "Cannot be static initializer"); flags |= IS_METHOD | (JVM_REF_invokeStatic << REFERENCE_KIND_SHIFT); - } else if (m->is_initializer()) { + } else if (m->is_object_initializer()) { flags |= IS_CONSTRUCTOR | (JVM_REF_invokeSpecial << REFERENCE_KIND_SHIFT); } else { // "special" reflects that this is a direct call, not that it diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 0d0b58412ae..fe9641063b3 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -336,6 +336,11 @@ bool Arguments::is_internal_module_property(const char* property) { return false; } +// Return true if the key matches the --module-path property name ("jdk.module.path"). +bool Arguments::is_module_path_property(const char* key) { + return (strcmp(key, MODULE_PROPERTY_PREFIX PATH) == 0); +} + // Process java launcher properties. void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) { // See if sun.java.launcher or sun.java.launcher.is_altjvm is defined. @@ -1817,17 +1822,6 @@ bool Arguments::check_vm_args_consistency() { } #endif -#if !defined(X86) && !defined(AARCH64) && !defined(RISCV64) && !defined(ARM) && !defined(PPC64) && !defined(S390) - if (LockingMode == LM_LIGHTWEIGHT) { - FLAG_SET_CMDLINE(LockingMode, LM_LEGACY); - warning("New lightweight locking not supported on this platform"); - } - if (UseObjectMonitorTable) { - FLAG_SET_CMDLINE(UseObjectMonitorTable, false); - warning("UseObjectMonitorTable not supported on this platform"); - } -#endif - if (UseObjectMonitorTable && LockingMode != LM_LIGHTWEIGHT) { // ObjectMonitorTable requires lightweight locking. FLAG_SET_CMDLINE(UseObjectMonitorTable, false); diff --git a/src/hotspot/share/runtime/arguments.hpp b/src/hotspot/share/runtime/arguments.hpp index 8251db3d0d5..e1bfc0438dc 100644 --- a/src/hotspot/share/runtime/arguments.hpp +++ b/src/hotspot/share/runtime/arguments.hpp @@ -461,6 +461,7 @@ class Arguments : AllStatic { static int PropertyList_readable_count(SystemProperty* pl); static bool is_internal_module_property(const char* option); + static bool is_module_path_property(const char* key); // Miscellaneous System property value getter and setters. static void set_dll_dir(const char *value) { _sun_boot_library_path->set_value(value); } diff --git a/src/hotspot/share/runtime/basicLock.inline.hpp b/src/hotspot/share/runtime/basicLock.inline.hpp index 30abd575da4..1090241c3e1 100644 --- a/src/hotspot/share/runtime/basicLock.inline.hpp +++ b/src/hotspot/share/runtime/basicLock.inline.hpp @@ -39,7 +39,7 @@ inline void BasicLock::set_displaced_header(markWord header) { inline ObjectMonitor* BasicLock::object_monitor_cache() const { assert(UseObjectMonitorTable, "must be"); -#if defined(X86) || defined(AARCH64) || defined(RISCV64) || defined(PPC64) || defined(S390) +#if !defined(ZERO) && (defined(X86) || defined(AARCH64) || defined(RISCV64) || defined(PPC64) || defined(S390)) return reinterpret_cast(get_metadata()); #else // Other platforms do not make use of the cache yet, diff --git a/src/hotspot/share/runtime/deoptimization.cpp b/src/hotspot/share/runtime/deoptimization.cpp index 7961e56598f..2006f340450 100644 --- a/src/hotspot/share/runtime/deoptimization.cpp +++ b/src/hotspot/share/runtime/deoptimization.cpp @@ -447,7 +447,7 @@ bool Deoptimization::deoptimize_objects_internal(JavaThread* thread, GrowableArr RegisterMap map(chunk->at(0)->register_map()); bool deoptimized_objects = false; - bool const jvmci_enabled = JVMCI_ONLY(UseJVMCICompiler) NOT_JVMCI(false); + bool const jvmci_enabled = JVMCI_ONLY(EnableJVMCI) NOT_JVMCI(false); // Reallocate the non-escaping objects and restore their fields. if (jvmci_enabled COMPILER2_PRESENT(|| (DoEscapeAnalysis && EliminateAllocations) diff --git a/src/hotspot/share/runtime/escapeBarrier.hpp b/src/hotspot/share/runtime/escapeBarrier.hpp index df32deef986..454e0b555e1 100644 --- a/src/hotspot/share/runtime/escapeBarrier.hpp +++ b/src/hotspot/share/runtime/escapeBarrier.hpp @@ -71,7 +71,7 @@ class EscapeBarrier : StackObj { // Revert ea based optimizations for given deoptee thread EscapeBarrier(bool barrier_active, JavaThread* calling_thread, JavaThread* deoptee_thread) : _calling_thread(calling_thread), _deoptee_thread(deoptee_thread), - _barrier_active(barrier_active && (JVMCI_ONLY(UseJVMCICompiler) NOT_JVMCI(false) + _barrier_active(barrier_active && (JVMCI_ONLY(EnableJVMCI) NOT_JVMCI(false) COMPILER2_PRESENT(|| DoEscapeAnalysis))) { if (_barrier_active) sync_and_suspend_one(); @@ -80,7 +80,7 @@ class EscapeBarrier : StackObj { // Revert ea based optimizations for all java threads EscapeBarrier(bool barrier_active, JavaThread* calling_thread) : _calling_thread(calling_thread), _deoptee_thread(nullptr), - _barrier_active(barrier_active && (JVMCI_ONLY(UseJVMCICompiler) NOT_JVMCI(false) + _barrier_active(barrier_active && (JVMCI_ONLY(EnableJVMCI) NOT_JVMCI(false) COMPILER2_PRESENT(|| DoEscapeAnalysis))) { if (_barrier_active) sync_and_suspend_all(); diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index 8dafc9a508d..2bcc26043cd 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -289,9 +289,6 @@ const int ObjectAlignmentInBytes = 8; product(bool, UseInlineCaches, true, \ "Use Inline Caches for virtual calls ") \ \ - product(size_t, InlineCacheBufferSize, 10*K, EXPERIMENTAL, \ - "InlineCacheBuffer size") \ - \ product(bool, InlineArrayCopy, true, DIAGNOSTIC, \ "Inline arraycopy native that is known to be part of " \ "base library DLL") \ diff --git a/src/hotspot/share/runtime/javaThread.cpp b/src/hotspot/share/runtime/javaThread.cpp index 3528fc5b1bc..14528f6d908 100644 --- a/src/hotspot/share/runtime/javaThread.cpp +++ b/src/hotspot/share/runtime/javaThread.cpp @@ -487,6 +487,7 @@ JavaThread::JavaThread(MemTag mem_tag) : _cont_fastpath_thread_state(1), _held_monitor_count(0), _jni_monitor_count(0), + _unlocked_inflated_monitor(nullptr), _handshake(this), diff --git a/src/hotspot/share/runtime/javaThread.hpp b/src/hotspot/share/runtime/javaThread.hpp index e36b7dfe888..20bb08a4acb 100644 --- a/src/hotspot/share/runtime/javaThread.hpp +++ b/src/hotspot/share/runtime/javaThread.hpp @@ -464,6 +464,7 @@ class JavaThread: public Thread { // It's signed for error detection. intx _held_monitor_count; // used by continuations for fast lock detection intx _jni_monitor_count; + ObjectMonitor* _unlocked_inflated_monitor; private: @@ -615,6 +616,12 @@ class JavaThread: public Thread { intx jni_monitor_count() { return _jni_monitor_count; } void clear_jni_monitor_count() { _jni_monitor_count = 0; } + // Support for SharedRuntime::monitor_exit_helper() + ObjectMonitor* unlocked_inflated_monitor() const { return _unlocked_inflated_monitor; } + void clear_unlocked_inflated_monitor() { + _unlocked_inflated_monitor = nullptr; + } + inline bool is_vthread_mounted() const; inline const ContinuationEntry* vthread_continuation() const; @@ -828,6 +835,7 @@ class JavaThread: public Thread { static ByteSize cont_fastpath_offset() { return byte_offset_of(JavaThread, _cont_fastpath); } static ByteSize held_monitor_count_offset() { return byte_offset_of(JavaThread, _held_monitor_count); } static ByteSize jni_monitor_count_offset() { return byte_offset_of(JavaThread, _jni_monitor_count); } + static ByteSize unlocked_inflated_monitor_offset() { return byte_offset_of(JavaThread, _unlocked_inflated_monitor); } #if INCLUDE_JVMTI static ByteSize is_in_VTMS_transition_offset() { return byte_offset_of(JavaThread, _is_in_VTMS_transition); } diff --git a/src/hotspot/share/runtime/mutexLocker.cpp b/src/hotspot/share/runtime/mutexLocker.cpp index f033f426249..a0ba783c364 100644 --- a/src/hotspot/share/runtime/mutexLocker.cpp +++ b/src/hotspot/share/runtime/mutexLocker.cpp @@ -45,7 +45,6 @@ Mutex* SharedDictionary_lock = nullptr; Monitor* ClassInitError_lock = nullptr; Mutex* Module_lock = nullptr; Mutex* CompiledIC_lock = nullptr; -Mutex* InlineCacheBuffer_lock = nullptr; Mutex* VMStatistic_lock = nullptr; Mutex* JmethodIdCreation_lock = nullptr; Mutex* JfieldIdCreation_lock = nullptr; @@ -262,7 +261,7 @@ void mutex_init() { MUTEX_DEFN(JfieldIdCreation_lock , PaddedMutex , safepoint); - MUTEX_DEFN(CompiledIC_lock , PaddedMutex , nosafepoint); // locks VtableStubs_lock, InlineCacheBuffer_lock + MUTEX_DEFN(CompiledIC_lock , PaddedMutex , nosafepoint); // locks VtableStubs_lock MUTEX_DEFN(MethodCompileQueue_lock , PaddedMonitor, safepoint); MUTEX_DEFN(CompileStatistics_lock , PaddedMutex , safepoint); MUTEX_DEFN(DirectivesStack_lock , PaddedMutex , nosafepoint); @@ -319,7 +318,6 @@ void mutex_init() { #endif // These locks have relative rankings, and inherit safepoint checking attributes from that rank. - MUTEX_DEFL(InlineCacheBuffer_lock , PaddedMutex , CompiledIC_lock); MUTEX_DEFL(VtableStubs_lock , PaddedMutex , CompiledIC_lock); // Also holds DumpTimeTable_lock MUTEX_DEFL(CodeCache_lock , PaddedMonitor, VtableStubs_lock); MUTEX_DEFL(NMethodState_lock , PaddedMutex , CodeCache_lock); diff --git a/src/hotspot/share/runtime/mutexLocker.hpp b/src/hotspot/share/runtime/mutexLocker.hpp index 160e6c97db0..3da85958501 100644 --- a/src/hotspot/share/runtime/mutexLocker.hpp +++ b/src/hotspot/share/runtime/mutexLocker.hpp @@ -40,7 +40,6 @@ extern Mutex* SharedDictionary_lock; // a lock on the CDS shared dic extern Monitor* ClassInitError_lock; // a lock on the class initialization error table extern Mutex* Module_lock; // a lock on module and package related data structures extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access -extern Mutex* InlineCacheBuffer_lock; // a lock used to guard the InlineCacheBuffer extern Mutex* VMStatistic_lock; // a lock used to guard statistics count increment extern Mutex* JmethodIdCreation_lock; // a lock on creating JNI method identifiers extern Mutex* JfieldIdCreation_lock; // a lock on creating JNI static field identifiers diff --git a/src/hotspot/share/runtime/objectMonitor.cpp b/src/hotspot/share/runtime/objectMonitor.cpp index 367d79a5283..755d49d2c6c 100644 --- a/src/hotspot/share/runtime/objectMonitor.cpp +++ b/src/hotspot/share/runtime/objectMonitor.cpp @@ -178,7 +178,7 @@ OopStorage* ObjectMonitor::_oop_storage = nullptr; // // Cxq points to the set of Recently Arrived Threads attempting entry. // Because we push threads onto _cxq with CAS, the RATs must take the form of -// a singly-linked LIFO. We drain _cxq into EntryList at unlock-time when +// a singly-linked LIFO. We drain _cxq into EntryList at unlock-time when // the unlocking thread notices that EntryList is null but _cxq is != null. // // The EntryList is ordered by the prevailing queue discipline and @@ -210,19 +210,6 @@ OopStorage* ObjectMonitor::_oop_storage = nullptr; // unpark the notifyee. Unparking a notifee in notify() is inefficient - // it's likely the notifyee would simply impale itself on the lock held // by the notifier. -// -// * An interesting alternative is to encode cxq as (List,LockByte) where -// the LockByte is 0 iff the monitor is owned. _owner is simply an auxiliary -// variable, like _recursions, in the scheme. The threads or Events that form -// the list would have to be aligned in 256-byte addresses. A thread would -// try to acquire the lock or enqueue itself with CAS, but exiting threads -// could use a 1-0 protocol and simply STB to set the LockByte to 0. -// Note that is is *not* word-tearing, but it does presume that full-word -// CAS operations are coherent with intermix with STB operations. That's true -// on most common processors. -// -// * See also http://blogs.sun.com/dave - // Check that object() and set_object() are called from the right context: static void check_object_context() { @@ -257,7 +244,6 @@ ObjectMonitor::ObjectMonitor(oop object) : _EntryList(nullptr), _cxq(nullptr), _succ(nullptr), - _Responsible(nullptr), _SpinDuration(ObjectMonitor::Knob_SpinLimit), _contentions(0), _WaitSet(nullptr), @@ -320,17 +306,11 @@ bool ObjectMonitor::enter_is_async_deflating() { return false; } -void ObjectMonitor::enter_for_with_contention_mark(JavaThread* locking_thread, ObjectMonitorContentionMark& contention_mark) { - // Used by ObjectSynchronizer::enter_for to enter for another thread. - // The monitor is private to or already owned by locking_thread which must be suspended. - // So this code may only contend with deflation. - assert(locking_thread == Thread::current() || locking_thread->is_obj_deopt_suspend(), "must be"); +bool ObjectMonitor::TryLockWithContentionMark(JavaThread* locking_thread, ObjectMonitorContentionMark& contention_mark) { assert(contention_mark._monitor == this, "must be"); assert(!is_being_async_deflated(), "must be"); - void* prev_owner = try_set_owner_from(nullptr, locking_thread); - bool success = false; if (prev_owner == nullptr) { @@ -343,8 +323,16 @@ void ObjectMonitor::enter_for_with_contention_mark(JavaThread* locking_thread, O // Racing with deflation. prev_owner = try_set_owner_from(DEFLATER_MARKER, locking_thread); if (prev_owner == DEFLATER_MARKER) { - // Cancelled deflation. Increment contentions as part of the deflation protocol. - add_to_contentions(1); + // We successfully cancelled the in-progress async deflation by + // changing owner from DEFLATER_MARKER to current. We now extend + // the lifetime of the contention_mark (e.g. contentions++) here + // to prevent the deflater thread from winning the last part of + // the 2-part async deflation protocol after the regular + // decrement occurs when the contention_mark goes out of + // scope. ObjectMonitor::deflate_monitor() which is called by + // the deflater thread will decrement contentions after it + // recognizes that the async deflation was cancelled. + contention_mark.extend(); success = true; } else if (prev_owner == nullptr) { // At this point we cannot race with deflation as we have both incremented @@ -360,12 +348,28 @@ void ObjectMonitor::enter_for_with_contention_mark(JavaThread* locking_thread, O set_owner_from_BasicLock(prev_owner, locking_thread); success = true; } + assert(!success || owner_raw() == locking_thread, "must be"); + + return success; +} + +void ObjectMonitor::enter_for_with_contention_mark(JavaThread* locking_thread, ObjectMonitorContentionMark& contention_mark) { + // Used by LightweightSynchronizer::inflate_and_enter in deoptimization path to enter for another thread. + // The monitor is private to or already owned by locking_thread which must be suspended. + // So this code may only contend with deflation. + assert(locking_thread == Thread::current() || locking_thread->is_obj_deopt_suspend(), "must be"); + bool success = TryLockWithContentionMark(locking_thread, contention_mark); + assert(success, "Failed to enter_for: locking_thread=" INTPTR_FORMAT - ", this=" INTPTR_FORMAT "{owner=" INTPTR_FORMAT "}, observed owner: " INTPTR_FORMAT, - p2i(locking_thread), p2i(this), p2i(owner_raw()), p2i(prev_owner)); + ", this=" INTPTR_FORMAT "{owner=" INTPTR_FORMAT "}", + p2i(locking_thread), p2i(this), p2i(owner_raw())); } bool ObjectMonitor::enter_for(JavaThread* locking_thread) { + // Used by ObjectSynchronizer::enter_for() to enter for another thread. + // The monitor is private to or already owned by locking_thread which must be suspended. + // So this code may only contend with deflation. + assert(locking_thread == Thread::current() || locking_thread->is_obj_deopt_suspend(), "must be"); // Block out deflation as soon as possible. ObjectMonitorContentionMark contention_mark(this); @@ -375,19 +379,29 @@ bool ObjectMonitor::enter_for(JavaThread* locking_thread) { return false; } - enter_for_with_contention_mark(locking_thread, contention_mark); + bool success = TryLockWithContentionMark(locking_thread, contention_mark); + + assert(success, "Failed to enter_for: locking_thread=" INTPTR_FORMAT + ", this=" INTPTR_FORMAT "{owner=" INTPTR_FORMAT "}", + p2i(locking_thread), p2i(this), p2i(owner_raw())); assert(owner_raw() == locking_thread, "must be"); return true; } -bool ObjectMonitor::try_enter(JavaThread* current) { - // TryLock avoids the CAS +bool ObjectMonitor::try_enter(JavaThread* current, bool check_for_recursion) { + // TryLock avoids the CAS and handles deflation. TryLockResult r = TryLock(current); if (r == TryLockResult::Success) { assert(_recursions == 0, "invariant"); return true; } + // If called from SharedRuntime::monitor_exit_helper(), we know that + // this thread doesn't already own the lock. + if (!check_for_recursion) { + return false; + } + if (r == TryLockResult::HasOwner && owner() == current) { _recursions++; return true; @@ -400,7 +414,6 @@ bool ObjectMonitor::try_enter(JavaThread* current) { set_owner_from_BasicLock(cur, current); // Convert from BasicLock* to Thread*. return true; } - return false; } @@ -561,16 +574,40 @@ void ObjectMonitor::enter_with_contention_mark(JavaThread *current, ObjectMonito ObjectMonitor::TryLockResult ObjectMonitor::TryLock(JavaThread* current) { void* own = owner_raw(); - if (own != nullptr) return TryLockResult::HasOwner; - if (try_set_owner_from(nullptr, current) == nullptr) { - assert(_recursions == 0, "invariant"); - return TryLockResult::Success; + void* first_own = own; + + for (;;) { + if (own == DEFLATER_MARKER) { + // Block out deflation as soon as possible. + ObjectMonitorContentionMark contention_mark(this); + + // Check for deflation. + if (enter_is_async_deflating()) { + // Treat deflation as interference. + return TryLockResult::Interference; + } + if (TryLockWithContentionMark(current, contention_mark)) { + assert(_recursions == 0, "invariant"); + return TryLockResult::Success; + } else { + // Deflation won or change of owner; dont spin + break; + } + } else if (own == nullptr) { + void* prev_own = try_set_owner_from(nullptr, current); + if (prev_own == nullptr) { + assert(_recursions == 0, "invariant"); + return TryLockResult::Success; + } else { + // The lock had been free momentarily, but we lost the race to the lock. + own = prev_own; + } + } else { + // Retry doesn't make as much sense because the lock was just acquired. + break; + } } - // The lock had been free momentarily, but we lost the race to the lock. - // Interference -- the CAS failed. - // We can either return -1 or retry. - // Retry doesn't make as much sense because the lock was just acquired. - return TryLockResult::Interference; + return first_own == own ? TryLockResult::HasOwner : TryLockResult::Interference; } // Deflate the specified ObjectMonitor if not in-use. Returns true if it @@ -746,8 +783,6 @@ const char* ObjectMonitor::is_busy_to_string(stringStream* ss) { return ss->base(); } -#define MAX_RECHECK_INTERVAL 1000 - void ObjectMonitor::EnterI(JavaThread* current) { assert(current->thread_state() == _thread_blocked, "invariant"); @@ -755,25 +790,6 @@ void ObjectMonitor::EnterI(JavaThread* current) { if (TryLock(current) == TryLockResult::Success) { assert(_succ != current, "invariant"); assert(owner_raw() == current, "invariant"); - assert(_Responsible != current, "invariant"); - return; - } - - if (try_set_owner_from(DEFLATER_MARKER, current) == DEFLATER_MARKER) { - // Cancelled the in-progress async deflation by changing owner from - // DEFLATER_MARKER to current. As part of the contended enter protocol, - // contentions was incremented to a positive value before EnterI() - // was called and that prevents the deflater thread from winning the - // last part of the 2-part async deflation protocol. After EnterI() - // returns to enter(), contentions is decremented because the caller - // now owns the monitor. We bump contentions an extra time here to - // prevent the deflater thread from winning the last part of the - // 2-part async deflation protocol after the regular decrement - // occurs in enter(). The deflater thread will decrement contentions - // after it recognizes that the async deflation was cancelled. - add_to_contentions(1); - assert(_succ != current, "invariant"); - assert(_Responsible != current, "invariant"); return; } @@ -789,14 +805,12 @@ void ObjectMonitor::EnterI(JavaThread* current) { if (TrySpin(current)) { assert(owner_raw() == current, "invariant"); assert(_succ != current, "invariant"); - assert(_Responsible != current, "invariant"); return; } // The Spin failed -- Enqueue and park the thread ... assert(_succ != current, "invariant"); assert(owner_raw() != current, "invariant"); - assert(_Responsible != current, "invariant"); // Enqueue "current" on ObjectMonitor's _cxq. // @@ -826,40 +840,10 @@ void ObjectMonitor::EnterI(JavaThread* current) { if (TryLock(current) == TryLockResult::Success) { assert(_succ != current, "invariant"); assert(owner_raw() == current, "invariant"); - assert(_Responsible != current, "invariant"); return; } } - // Check for cxq|EntryList edge transition to non-null. This indicates - // the onset of contention. While contention persists exiting threads - // will use a ST:MEMBAR:LD 1-1 exit protocol. When contention abates exit - // operations revert to the faster 1-0 mode. This enter operation may interleave - // (race) a concurrent 1-0 exit operation, resulting in stranding, so we - // arrange for one of the contending thread to use a timed park() operations - // to detect and recover from the race. (Stranding is form of progress failure - // where the monitor is unlocked but all the contending threads remain parked). - // That is, at least one of the contended threads will periodically poll _owner. - // One of the contending threads will become the designated "Responsible" thread. - // The Responsible thread uses a timed park instead of a normal indefinite park - // operation -- it periodically wakes and checks for and recovers from potential - // strandings admitted by 1-0 exit operations. We need at most one Responsible - // thread per-monitor at any given moment. Only threads on cxq|EntryList may - // be responsible for a monitor. - // - // Currently, one of the contended threads takes on the added role of "Responsible". - // A viable alternative would be to use a dedicated "stranding checker" thread - // that periodically iterated over all the threads (or active monitors) and unparked - // successors where there was risk of stranding. This would help eliminate the - // timer scalability issues we see on some platforms as we'd only have one thread - // -- the checker -- parked on a timer. - - if (nxt == nullptr && _EntryList == nullptr) { - // Try to assume the role of responsible thread for the monitor. - // CONSIDER: ST vs CAS vs { if (Responsible==null) Responsible=current } - Atomic::replace_if_null(&_Responsible, current); - } - // The lock might have been released while this thread was occupied queueing // itself onto _cxq. To close the race and avoid "stranding" and // progress-liveness failure we must resample-retry _owner before parking. @@ -871,8 +855,6 @@ void ObjectMonitor::EnterI(JavaThread* current) { // to defer the state transitions until absolutely necessary, // and in doing so avoid some transitions ... - int recheckInterval = 1; - for (;;) { if (TryLock(current) == TryLockResult::Success) { @@ -881,37 +863,12 @@ void ObjectMonitor::EnterI(JavaThread* current) { assert(owner_raw() != current, "invariant"); // park self - if (_Responsible == current) { - current->_ParkEvent->park((jlong) recheckInterval); - // Increase the recheckInterval, but clamp the value. - recheckInterval *= 8; - if (recheckInterval > MAX_RECHECK_INTERVAL) { - recheckInterval = MAX_RECHECK_INTERVAL; - } - } else { - current->_ParkEvent->park(); - } + current->_ParkEvent->park(); if (TryLock(current) == TryLockResult::Success) { break; } - if (try_set_owner_from(DEFLATER_MARKER, current) == DEFLATER_MARKER) { - // Cancelled the in-progress async deflation by changing owner from - // DEFLATER_MARKER to current. As part of the contended enter protocol, - // contentions was incremented to a positive value before EnterI() - // was called and that prevents the deflater thread from winning the - // last part of the 2-part async deflation protocol. After EnterI() - // returns to enter(), contentions is decremented because the caller - // now owns the monitor. We bump contentions an extra time here to - // prevent the deflater thread from winning the last part of the - // 2-part async deflation protocol after the regular decrement - // occurs in enter(). The deflater thread will decrement contentions - // after it recognizes that the async deflation was cancelled. - add_to_contentions(1); - break; - } - // The lock is still contested. // Keep a tally of the # of futile wakeups. @@ -953,44 +910,23 @@ void ObjectMonitor::EnterI(JavaThread* current) { assert(owner_raw() == current, "invariant"); UnlinkAfterAcquire(current, &node); - if (_succ == current) _succ = nullptr; - - assert(_succ != current, "invariant"); - if (_Responsible == current) { - _Responsible = nullptr; - OrderAccess::fence(); // Dekker pivot-point - - // We may leave threads on cxq|EntryList without a designated - // "Responsible" thread. This is benign. When this thread subsequently - // exits the monitor it can "see" such preexisting "old" threads -- - // threads that arrived on the cxq|EntryList before the fence, above -- - // by LDing cxq|EntryList. Newly arrived threads -- that is, threads - // that arrive on cxq after the ST:MEMBAR, above -- will set Responsible - // non-null and elect a new "Responsible" timer thread. - // - // This thread executes: - // ST Responsible=null; MEMBAR (in enter epilogue - here) - // LD cxq|EntryList (in subsequent exit) - // - // Entering threads in the slow/contended path execute: - // ST cxq=nonnull; MEMBAR; LD Responsible (in enter prolog) - // The (ST cxq; MEMBAR) is accomplished with CAS(). - // - // The MEMBAR, above, prevents the LD of cxq|EntryList in the subsequent - // exit operation from floating above the ST Responsible=null. + if (_succ == current) { + _succ = nullptr; + // Note that we don't need to do OrderAccess::fence() after clearing + // _succ here, since we own the lock. } // We've acquired ownership with CAS(). // CAS is serializing -- it has MEMBAR/FENCE-equivalent semantics. // But since the CAS() this thread may have also stored into _succ, - // EntryList, cxq or Responsible. These meta-data updates must be + // EntryList or cxq. These meta-data updates must be // visible __before this thread subsequently drops the lock. // Consider what could occur if we didn't enforce this constraint -- // STs to monitor meta-data and user-data could reorder with (become // visible after) the ST in exit that drops ownership of the lock. // Some other thread could then acquire the lock, but observe inconsistent // or old monitor meta-data and heap data. That violates the JMM. - // To that end, the 1-0 exit() operation must have at least STST|LDST + // To that end, the exit() operation must have at least STST|LDST // "release" barrier semantics. Specifically, there must be at least a // STST|LDST barrier in exit() before the ST of null into _owner that drops // the lock. The barrier ensures that changes to monitor meta-data and data @@ -1000,8 +936,7 @@ void ObjectMonitor::EnterI(JavaThread* current) { // // Critically, any prior STs to _succ or EntryList must be visible before // the ST of null into _owner in the *subsequent* (following) corresponding - // monitorexit. Recall too, that in 1-0 mode monitorexit does not necessarily - // execute a serializing instruction. + // monitorexit. return; } @@ -1174,39 +1109,32 @@ void ObjectMonitor::UnlinkAfterAcquire(JavaThread* current, ObjectWaiter* curren // In that case exit() is called with _thread_state == _thread_blocked, // but the monitor's _contentions field is > 0, which inhibits reclamation. // -// 1-0 exit -// ~~~~~~~~ -// ::exit() uses a canonical 1-1 idiom with a MEMBAR although some of -// the fast-path operators have been optimized so the common ::exit() -// operation is 1-0, e.g., see macroAssembler_x86.cpp: fast_unlock(). -// The code emitted by fast_unlock() elides the usual MEMBAR. This -// greatly improves latency -- MEMBAR and CAS having considerable local -// latency on modern processors -- but at the cost of "stranding". Absent the -// MEMBAR, a thread in fast_unlock() can race a thread in the slow -// ::enter() path, resulting in the entering thread being stranding -// and a progress-liveness failure. Stranding is extremely rare. -// We use timers (timed park operations) & periodic polling to detect -// and recover from stranding. Potentially stranded threads periodically -// wake up and poll the lock. See the usage of the _Responsible variable. +// This is the exit part of the locking protocol, often implemented in +// C2_MacroAssembler::fast_unlock() +// +// 1. A release barrier ensures that changes to monitor meta-data +// (_succ, _EntryList, _cxq) and data protected by the lock will be +// visible before we release the lock. +// 2. Release the lock by clearing the owner. +// 3. A storeload MEMBAR is needed between releasing the owner and +// subsequently reading meta-data to safely determine if the lock is +// contended (step 4) without an elected successor (step 5). +// 4. If both _EntryList and _cxq are null, we are done, since there is no +// other thread waiting on the lock to wake up. I.e. there is no +// contention. +// 5. If there is a successor (_succ is non-null), we are done. The +// responsibility for guaranteeing progress-liveness has now implicitly +// been moved from the exiting thread to the successor. +// 6. There are waiters in the entry list (_EntryList and/or cxq are +// non-null), but there is no successor (_succ is null), so we need to +// wake up (unpark) a waiting thread to avoid stranding. // -// The CAS() in enter provides for safety and exclusion, while the CAS or -// MEMBAR in exit provides for progress and avoids stranding. 1-0 locking -// eliminates the CAS/MEMBAR from the exit path, but it admits stranding. -// We detect and recover from stranding with timers. +// Note that since only the current lock owner can manipulate the _EntryList +// or drain _cxq, we need to reacquire the lock before we can wake up +// (unpark) a waiting thread. // -// If a thread transiently strands it'll park until (a) another -// thread acquires the lock and then drops the lock, at which time the -// exiting thread will notice and unpark the stranded thread, or, (b) -// the timer expires. If the lock is high traffic then the stranding latency -// will be low due to (a). If the lock is low traffic then the odds of -// stranding are lower, although the worst-case stranding latency -// is longer. Critically, we don't want to put excessive load in the -// platform's timer subsystem. We want to minimize both the timer injection -// rate (timers created/sec) as well as the number of timers active at -// any one time. (more precisely, we want to minimize timer-seconds, which is -// the integral of the # of active timers at any instant over time). -// Both impinge on OS scalability. Given that, at most one thread parked on -// a monitor will use a timer. +// The CAS() in enter provides for safety and exclusion, while the +// MEMBAR in exit provides for progress and avoids stranding. // // There is also the risk of a futile wake-up. If we drop the lock // another thread can reacquire the lock immediately, and we can @@ -1248,10 +1176,6 @@ void ObjectMonitor::exit(JavaThread* current, bool not_suspended) { return; } - // Invariant: after setting Responsible=null an thread must execute - // a MEMBAR or other serializing instruction before fetching EntryList|cxq. - _Responsible = nullptr; - #if INCLUDE_JFR // get the owner's thread id for the MonitorEnter event // if it is enabled and the thread isn't suspended @@ -1278,14 +1202,15 @@ void ObjectMonitor::exit(JavaThread* current, bool not_suspended) { // Other threads are blocked trying to acquire the lock. // Normally the exiting thread is responsible for ensuring succession, - // but if other successors are ready or other entering threads are spinning - // then this thread can simply store null into _owner and exit without - // waking a successor. The existence of spinners or ready successors - // guarantees proper succession (liveness). Responsibility passes to the - // ready or running successors. The exiting thread delegates the duty. - // More precisely, if a successor already exists this thread is absolved - // of the responsibility of waking (unparking) one. - // + // but if this thread observes other successors are ready or other + // entering threads are spinning after it has stored null into _owner + // then it can exit without waking a successor. The existence of + // spinners or ready successors guarantees proper succession (liveness). + // Responsibility passes to the ready or running successors. The exiting + // thread delegates the duty. More precisely, if a successor already + // exists this thread is absolved of the responsibility of waking + // (unparking) one. + // The _succ variable is critical to reducing futile wakeup frequency. // _succ identifies the "heir presumptive" thread that has been made // ready (unparked) but that has not yet run. We need only one such @@ -1296,24 +1221,20 @@ void ObjectMonitor::exit(JavaThread* current, bool not_suspended) { // Note that spinners in Enter() also set _succ non-null. // In the current implementation spinners opportunistically set // _succ so that exiting threads might avoid waking a successor. - // Another less appealing alternative would be for the exiting thread - // to drop the lock and then spin briefly to see if a spinner managed - // to acquire the lock. If so, the exiting thread could exit - // immediately without waking a successor, otherwise the exiting - // thread would need to dequeue and wake a successor. - // (Note that we'd need to make the post-drop spin short, but no - // shorter than the worst-case round-trip cache-line migration time. - // The dropped lock needs to become visible to the spinner, and then - // the acquisition of the lock by the spinner must become visible to - // the exiting thread). + // Which means that the exiting thread could exit immediately without + // waking a successor, if it observes a successor after it has dropped + // the lock. Note that the dropped lock needs to become visible to the + // spinner. // It appears that an heir-presumptive (successor) must be made ready. // Only the current lock owner can manipulate the EntryList or // drain _cxq, so we need to reacquire the lock. If we fail // to reacquire the lock the responsibility for ensuring succession // falls to the new owner. - // - if (try_set_owner_from(nullptr, current) != nullptr) { + + if (TryLock(current) != TryLockResult::Success) { + // Some other thread acquired the lock (or the monitor was + // deflated). Either way we are done. return; } @@ -1376,7 +1297,7 @@ void ObjectMonitor::exit(JavaThread* current, bool not_suspended) { q = p; } - // In 1-0 mode we need: ST EntryList; MEMBAR #storestore; ST _owner = nullptr + // We need to: ST EntryList; MEMBAR #storestore; ST _owner = nullptr // The MEMBAR is satisfied by the release_store() operation in ExitEpilog(). // See if we can abdicate to a spinner instead of waking a thread. @@ -1566,8 +1487,6 @@ void ObjectMonitor::wait(jlong millis, bool interruptible, TRAPS) { AddWaiter(&node); Thread::SpinRelease(&_WaitSetLock); - _Responsible = nullptr; - intx save = _recursions; // record the old recursion count _waiters++; // increment the number of waiters _recursions = 0; // set the recursion level to be 1 @@ -2245,7 +2164,6 @@ void ObjectMonitor::print() const { print_on(tty); } // _EntryList = 0x0000000000000000 // _cxq = 0x0000000000000000 // _succ = 0x0000000000000000 -// _Responsible = 0x0000000000000000 // _SpinDuration = 5000 // _contentions = 0 // _WaitSet = 0x0000700009756248 @@ -2274,7 +2192,6 @@ void ObjectMonitor::print_debug_style_on(outputStream* st) const { st->print_cr(" _EntryList = " INTPTR_FORMAT, p2i(_EntryList)); st->print_cr(" _cxq = " INTPTR_FORMAT, p2i(_cxq)); st->print_cr(" _succ = " INTPTR_FORMAT, p2i(_succ)); - st->print_cr(" _Responsible = " INTPTR_FORMAT, p2i(_Responsible)); st->print_cr(" _SpinDuration = %d", _SpinDuration); st->print_cr(" _contentions = %d", contentions()); st->print_cr(" _WaitSet = " INTPTR_FORMAT, p2i(_WaitSet)); diff --git a/src/hotspot/share/runtime/objectMonitor.hpp b/src/hotspot/share/runtime/objectMonitor.hpp index ef85559c2b6..30d2e509416 100644 --- a/src/hotspot/share/runtime/objectMonitor.hpp +++ b/src/hotspot/share/runtime/objectMonitor.hpp @@ -179,7 +179,6 @@ class ObjectMonitor : public CHeapObj { ObjectWaiter* volatile _cxq; // LL of recently-arrived threads blocked on entry. JavaThread* volatile _succ; // Heir presumptive thread - used for futile wakeup throttling - JavaThread* volatile _Responsible; volatile int _SpinDuration; @@ -348,7 +347,7 @@ class ObjectMonitor : public CHeapObj { void enter_for_with_contention_mark(JavaThread* locking_thread, ObjectMonitorContentionMark& contention_mark); bool enter_for(JavaThread* locking_thread); bool enter(JavaThread* current); - bool try_enter(JavaThread* current); + bool try_enter(JavaThread* current, bool check_for_recursion = true); bool spin_enter(JavaThread* current); void enter_with_contention_mark(JavaThread* current, ObjectMonitorContentionMark& contention_mark); void exit(JavaThread* current, bool not_suspended = true); @@ -377,6 +376,7 @@ class ObjectMonitor : public CHeapObj { enum class TryLockResult { Interference = -1, HasOwner = 0, Success = 1 }; + bool TryLockWithContentionMark(JavaThread* locking_thread, ObjectMonitorContentionMark& contention_mark); TryLockResult TryLock(JavaThread* current); bool TrySpin(JavaThread* current); @@ -395,12 +395,17 @@ class ObjectMonitorContentionMark : StackObj { DEBUG_ONLY(friend class ObjectMonitor;) ObjectMonitor* _monitor; + bool _extended; NONCOPYABLE(ObjectMonitorContentionMark); public: explicit ObjectMonitorContentionMark(ObjectMonitor* monitor); ~ObjectMonitorContentionMark(); + + // Extends the contention scope beyond this objects lifetime. + // Requires manual decrement of the contentions counter. + void extend(); }; #endif // SHARE_RUNTIME_OBJECTMONITOR_HPP diff --git a/src/hotspot/share/runtime/objectMonitor.inline.hpp b/src/hotspot/share/runtime/objectMonitor.inline.hpp index d26c459b1b4..6d3c6ff24c3 100644 --- a/src/hotspot/share/runtime/objectMonitor.inline.hpp +++ b/src/hotspot/share/runtime/objectMonitor.inline.hpp @@ -206,15 +206,32 @@ inline void ObjectMonitor::set_next_om(ObjectMonitor* new_value) { Atomic::store(&_next_om, new_value); } +// Block out deflation. inline ObjectMonitorContentionMark::ObjectMonitorContentionMark(ObjectMonitor* monitor) - : _monitor(monitor) { + : _monitor(monitor), _extended(false) { + // Contentions is incremented to a positive value as part of the + // contended enter protocol, which prevents the deflater thread from + // winning the last part of the 2-part async deflation + // protocol. See: ObjectMonitor::deflate_monitor() and + // ObjectMonitor::TryLockWithContentionMark(). _monitor->add_to_contentions(1); } inline ObjectMonitorContentionMark::~ObjectMonitorContentionMark() { + // Decrement contentions when the contention mark goes out of + // scope. This opens up for deflation, if the contention mark + // hasn't been extended. _monitor->add_to_contentions(-1); } +inline void ObjectMonitorContentionMark::extend() { + // Used by ObjectMonitor::TryLockWithContentionMark() to "extend the + // lifetime" of the contention mark. + assert(!_extended, "extending twice is probably a bad design"); + _monitor->add_to_contentions(1); + _extended = true; +} + inline oop ObjectMonitor::object_peek() const { if (_object.is_null()) { return nullptr; diff --git a/src/hotspot/share/runtime/reflection.cpp b/src/hotspot/share/runtime/reflection.cpp index ab3d82ad7e2..15172b7f4c3 100644 --- a/src/hotspot/share/runtime/reflection.cpp +++ b/src/hotspot/share/runtime/reflection.cpp @@ -766,10 +766,10 @@ static Handle new_type(Symbol* signature, Klass* k, TRAPS) { } oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_access, TRAPS) { - // Allow sun.reflect.ConstantPool to refer to methods as java.lang.reflect.Methods. - assert(!method()->is_initializer() || - (for_constant_pool_access && method()->is_static()), - "should call new_constructor instead"); + // Allow jdk.internal.reflect.ConstantPool to refer to methods as java.lang.reflect.Methods. + assert(!method()->is_object_initializer() && + (for_constant_pool_access || !method()->is_static_initializer()), + "Should not be the initializer"); InstanceKlass* holder = method->method_holder(); int slot = method->method_idnum(); @@ -817,7 +817,7 @@ oop Reflection::new_method(const methodHandle& method, bool for_constant_pool_ac oop Reflection::new_constructor(const methodHandle& method, TRAPS) { - assert(method()->is_initializer(), "should call new_method instead"); + assert(method()->is_object_initializer(), "Should be the initializer"); InstanceKlass* holder = method->method_holder(); int slot = method->method_idnum(); diff --git a/src/hotspot/share/runtime/sharedRuntime.cpp b/src/hotspot/share/runtime/sharedRuntime.cpp index d9b38133f99..e4d4e6aea0f 100644 --- a/src/hotspot/share/runtime/sharedRuntime.cpp +++ b/src/hotspot/share/runtime/sharedRuntime.cpp @@ -651,7 +651,7 @@ void SharedRuntime::throw_and_post_jvmti_exception(JavaThread* current, Handle h } #if INCLUDE_JVMCI - if (EnableJVMCI && UseJVMCICompiler) { + if (EnableJVMCI) { vframeStream vfst(current, true); methodHandle method = methodHandle(current, vfst.method()); int bci = vfst.bci(); @@ -1963,6 +1963,26 @@ void SharedRuntime::monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThrea assert(JavaThread::current() == current, "invariant"); // Exit must be non-blocking, and therefore no exceptions can be thrown. ExceptionMark em(current); + + // Check if C2_MacroAssembler::fast_unlock() or + // C2_MacroAssembler::fast_unlock_lightweight() unlocked an inflated + // monitor before going slow path. Since there is no safepoint + // polling when calling into the VM, we can be sure that the monitor + // hasn't been deallocated. + ObjectMonitor* m = current->unlocked_inflated_monitor(); + if (m != nullptr) { + assert(m->owner_raw() != current, "must be"); + current->clear_unlocked_inflated_monitor(); + + // We need to reacquire the lock before we can call ObjectSynchronizer::exit(). + if (!m->try_enter(current, /*check_for_recursion*/ false)) { + // Some other thread acquired the lock (or the monitor was + // deflated). Either way we are done. + current->dec_held_monitor_count(); + return; + } + } + // The object could become unlocked through a JNI call, which we have no other checks for. // Give a fatal message if CheckJNICalls. Otherwise we ignore it. if (obj->is_unlocked()) { diff --git a/src/hotspot/share/runtime/thread.cpp b/src/hotspot/share/runtime/thread.cpp index 7c01c8d4e16..df6a660a0aa 100644 --- a/src/hotspot/share/runtime/thread.cpp +++ b/src/hotspot/share/runtime/thread.cpp @@ -83,7 +83,6 @@ Thread::Thread(MemTag mem_tag) { set_handle_area(new (mem_tag) HandleArea(mem_tag, nullptr)); set_metadata_handles(new (mtClass) GrowableArray(30, mtClass)); set_last_handle_mark(nullptr); - DEBUG_ONLY(_missed_ic_stub_refill_verifier = nullptr); // Initial value of zero ==> never claimed. _threads_do_token = 0; @@ -145,6 +144,16 @@ Thread::Thread(MemTag mem_tag) { MACOS_AARCH64_ONLY(DEBUG_ONLY(_wx_init = false)); } +#ifdef ASSERT +address Thread::stack_base() const { + // Note: can't report Thread::name() here as that can require a ResourceMark which we + // can't use because this gets called too early in the thread initialization. + assert(_stack_base != nullptr, "Stack base not yet set for thread id:%d (0 if not set)", + osthread() != nullptr ? osthread()->thread_id() : 0); + return _stack_base; +} +#endif + void Thread::initialize_tlab() { if (UseTLAB) { tlab().initialize(); diff --git a/src/hotspot/share/runtime/thread.hpp b/src/hotspot/share/runtime/thread.hpp index 567a76d0ead..45c39eae151 100644 --- a/src/hotspot/share/runtime/thread.hpp +++ b/src/hotspot/share/runtime/thread.hpp @@ -46,7 +46,6 @@ class CompilerThread; class HandleArea; class HandleMark; -class ICRefillVerifier; class JvmtiRawMonitor; class NMethodClosure; class Metadata; @@ -242,20 +241,6 @@ class Thread: public ThreadShadow { public: void set_last_handle_mark(HandleMark* mark) { _last_handle_mark = mark; } HandleMark* last_handle_mark() const { return _last_handle_mark; } - private: - -#ifdef ASSERT - ICRefillVerifier* _missed_ic_stub_refill_verifier; - - public: - ICRefillVerifier* missed_ic_stub_refill_verifier() { - return _missed_ic_stub_refill_verifier; - } - - void set_missed_ic_stub_refill_verifier(ICRefillVerifier* verifier) { - _missed_ic_stub_refill_verifier = verifier; - } -#endif // ASSERT private: // Used by SkipGCALot class. @@ -532,7 +517,7 @@ class Thread: public ThreadShadow { public: // Stack overflow support - address stack_base() const { assert(_stack_base != nullptr,"Sanity check"); return _stack_base; } + address stack_base() const DEBUG_ONLY(;) NOT_DEBUG({ return _stack_base; }) void set_stack_base(address base) { _stack_base = base; } size_t stack_size() const { return _stack_size; } void set_stack_size(size_t size) { _stack_size = size; } diff --git a/src/hotspot/share/runtime/vmOperation.hpp b/src/hotspot/share/runtime/vmOperation.hpp index 532a9231b70..eede52f00d5 100644 --- a/src/hotspot/share/runtime/vmOperation.hpp +++ b/src/hotspot/share/runtime/vmOperation.hpp @@ -109,7 +109,6 @@ template(PrintCompileQueue) \ template(PrintClassHierarchy) \ template(PrintClasses) \ - template(ICBufferFull) \ template(PrintMetadata) \ template(GTestExecuteAtSafepoint) \ template(GTestStopSafepoint) \ diff --git a/src/hotspot/share/runtime/vmOperations.hpp b/src/hotspot/share/runtime/vmOperations.hpp index 5ccf689eaf3..ea7f62df37d 100644 --- a/src/hotspot/share/runtime/vmOperations.hpp +++ b/src/hotspot/share/runtime/vmOperations.hpp @@ -60,12 +60,6 @@ class VM_ForceSafepoint: public VM_EmptyOperation { VMOp_Type type() const { return VMOp_ForceSafepoint; } }; -// empty vm op, when forcing a safepoint due to inline cache buffers being full -class VM_ICBufferFull: public VM_EmptyOperation { - public: - VMOp_Type type() const { return VMOp_ICBufferFull; } -}; - class VM_ClearICs: public VM_Operation { private: bool _preserve_static_stubs; diff --git a/src/hotspot/share/services/heapDumper.cpp b/src/hotspot/share/services/heapDumper.cpp index 5b3749381a0..10e1a804ad2 100644 --- a/src/hotspot/share/services/heapDumper.cpp +++ b/src/hotspot/share/services/heapDumper.cpp @@ -1512,6 +1512,38 @@ class ClassDumper : public KlassClosure { } }; +// Support class used to generate HPROF_LOAD_CLASS records + +class LoadedClassDumper : public LockedClassesDo { + private: + AbstractDumpWriter* _writer; + GrowableArray* _klass_map; + u4 _class_serial_num; + AbstractDumpWriter* writer() const { return _writer; } + void add_class_serial_number(Klass* k, int serial_num) { + _klass_map->at_put_grow(serial_num, k); + } + public: + LoadedClassDumper(AbstractDumpWriter* writer, GrowableArray* klass_map) + : _writer(writer), _klass_map(klass_map), _class_serial_num(0) {} + + void do_klass(Klass* k) { + // len of HPROF_LOAD_CLASS record + u4 remaining = 2 * oopSize + 2 * sizeof(u4); + DumperSupport::write_header(writer(), HPROF_LOAD_CLASS, remaining); + // class serial number is just a number + writer()->write_u4(++_class_serial_num); + // class ID + writer()->write_classID(k); + // add the Klass* and class serial number pair + add_class_serial_number(k, _class_serial_num); + writer()->write_u4(STACK_TRACE_ID); + // class name ID + Symbol* name = k->name(); + writer()->write_symbolID(name); + } +}; + // Support class used to generate HPROF_GC_ROOT_JNI_LOCAL records class JNILocalsDumper : public OopClosure { @@ -2190,9 +2222,7 @@ void DumpMerger::do_merge() { // The VM operation that performs the heap dump class VM_HeapDumper : public VM_GC_Operation, public WorkerTask, public UnmountedVThreadDumper { private: - static VM_HeapDumper* _global_dumper; - static DumpWriter* _global_writer; - DumpWriter* _local_writer; + DumpWriter* _writer; JavaThread* _oome_thread; Method* _oome_constructor; bool _gc_before_heap_dump; @@ -2218,33 +2248,13 @@ class VM_HeapDumper : public VM_GC_Operation, public WorkerTask, public Unmounte return Atomic::fetch_then_add(&_dump_seq, 1); } - // accessors and setters - static VM_HeapDumper* dumper() { assert(_global_dumper != nullptr, "Error"); return _global_dumper; } - static DumpWriter* writer() { assert(_global_writer != nullptr, "Error"); return _global_writer; } - - void set_global_dumper() { - assert(_global_dumper == nullptr, "Error"); - _global_dumper = this; - } - void set_global_writer() { - assert(_global_writer == nullptr, "Error"); - _global_writer = _local_writer; - } - void clear_global_dumper() { _global_dumper = nullptr; } - void clear_global_writer() { _global_writer = nullptr; } + DumpWriter* writer() const { return _writer; } bool skip_operation() const; - // writes a HPROF_LOAD_CLASS record to global writer - static void do_load_class(Klass* k); - // HPROF_GC_ROOT_THREAD_OBJ records for platform and mounted virtual threads void dump_threads(AbstractDumpWriter* writer); - void add_class_serial_number(Klass* k, int serial_num) { - _klass_map->at_put_grow(serial_num, k); - } - bool is_oom_thread(JavaThread* thread) const { return thread == _oome_thread && _oome_constructor != nullptr; } @@ -2259,7 +2269,7 @@ class VM_HeapDumper : public VM_GC_Operation, public WorkerTask, public Unmounte 0 /* total full collections, dummy, ignored */, gc_before_heap_dump), WorkerTask("dump heap") { - _local_writer = writer; + _writer = writer; _gc_before_heap_dump = gc_before_heap_dump; _klass_map = new (mtServiceability) GrowableArray(INITIAL_CLASS_COUNT, mtServiceability); @@ -2313,9 +2323,6 @@ class VM_HeapDumper : public VM_GC_Operation, public WorkerTask, public Unmounte void dump_vthread(oop vt, AbstractDumpWriter* segment_writer); }; -VM_HeapDumper* VM_HeapDumper::_global_dumper = nullptr; -DumpWriter* VM_HeapDumper::_global_writer = nullptr; - bool VM_HeapDumper::skip_operation() const { return false; } @@ -2329,31 +2336,6 @@ void DumperSupport::end_of_dump(AbstractDumpWriter* writer) { writer->write_u4(0); } -// writes a HPROF_LOAD_CLASS record for the class -void VM_HeapDumper::do_load_class(Klass* k) { - static u4 class_serial_num = 0; - - // len of HPROF_LOAD_CLASS record - u4 remaining = 2*oopSize + 2*sizeof(u4); - - DumperSupport::write_header(writer(), HPROF_LOAD_CLASS, remaining); - - // class serial number is just a number - writer()->write_u4(++class_serial_num); - - // class ID - writer()->write_classID(k); - - // add the Klass* and class serial number pair - dumper()->add_class_serial_number(k, class_serial_num); - - writer()->write_u4(STACK_TRACE_ID); - - // class name ID - Symbol* name = k->name(); - writer()->write_symbolID(name); -} - // Write a HPROF_GC_ROOT_THREAD_OBJ record for platform/carrier and mounted virtual threads. // Then walk the stack so that locals and JNI locals are dumped. void VM_HeapDumper::dump_threads(AbstractDumpWriter* writer) { @@ -2430,11 +2412,6 @@ void VM_HeapDumper::doit() { } } - // At this point we should be the only dumper active, so - // the following should be safe. - set_global_dumper(); - set_global_writer(); - WorkerThreads* workers = ch->safepoint_workers(); prepare_parallel_dump(workers); @@ -2446,10 +2423,6 @@ void VM_HeapDumper::doit() { workers->run_task(this, _num_dumper_threads); _poi = nullptr; } - - // Now we clear the global variables, so that a future dumper can run. - clear_global_dumper(); - clear_global_writer(); } void VM_HeapDumper::work(uint worker_id) { @@ -2480,8 +2453,8 @@ void VM_HeapDumper::work(uint worker_id) { // write HPROF_LOAD_CLASS records { - LockedClassesDo locked_load_classes(&do_load_class); - ClassLoaderDataGraph::classes_do(&locked_load_classes); + LoadedClassDumper loaded_class_dumper(writer(), _klass_map); + ClassLoaderDataGraph::classes_do(&loaded_class_dumper); } // write HPROF_FRAME and HPROF_TRACE records diff --git a/src/hotspot/share/utilities/macros.hpp b/src/hotspot/share/utilities/macros.hpp index 1034dec0d9a..23094c9e8c4 100644 --- a/src/hotspot/share/utilities/macros.hpp +++ b/src/hotspot/share/utilities/macros.hpp @@ -338,6 +338,7 @@ #define NOT_PRODUCT_ARG(arg) #define PRODUCT_RETURN {} #define PRODUCT_RETURN0 { return 0; } +#define PRODUCT_RETURN_NULL { return nullptr; } #define PRODUCT_RETURN_(code) { code } #else // PRODUCT #define PRODUCT_ONLY(code) @@ -345,6 +346,7 @@ #define NOT_PRODUCT_ARG(arg) arg, #define PRODUCT_RETURN /*next token must be ;*/ #define PRODUCT_RETURN0 /*next token must be ;*/ +#define PRODUCT_RETURN_NULL /* next token must be ;*/ #define PRODUCT_RETURN_(code) /*next token must be ;*/ #endif // PRODUCT diff --git a/src/java.base/macosx/native/libjli/java_md_macosx.m b/src/java.base/macosx/native/libjli/java_md_macosx.m index c5e7ba580a5..7aeb32be859 100644 --- a/src/java.base/macosx/native/libjli/java_md_macosx.m +++ b/src/java.base/macosx/native/libjli/java_md_macosx.m @@ -297,6 +297,7 @@ static void ParkEventLoop() { static void MacOSXStartup(int argc, char *argv[]) { // Thread already started? static jboolean started = false; + int rc; if (started) { return; } @@ -309,12 +310,14 @@ static void MacOSXStartup(int argc, char *argv[]) { // Fire up the main thread pthread_t main_thr; - if (pthread_create(&main_thr, NULL, &apple_main, &args) != 0) { - JLI_ReportErrorMessageSys("Could not create main thread: %s\n", strerror(errno)); + rc = pthread_create(&main_thr, NULL, &apple_main, &args); + if (rc != 0) { + JLI_ReportErrorMessageSys("Could not create main thread, return code: %d\n", rc); exit(1); } - if (pthread_detach(main_thr)) { - JLI_ReportErrorMessageSys("pthread_detach() failed: %s\n", strerror(errno)); + rc = pthread_detach(main_thr); + if (rc != 0) { + JLI_ReportErrorMessage("pthread_detach() failed, return code: %d\n", rc); exit(1); } diff --git a/src/java.base/share/classes/com/sun/crypto/provider/GaloisCounterMode.java b/src/java.base/share/classes/com/sun/crypto/provider/GaloisCounterMode.java index 44cfb76d162..478593dfac1 100644 --- a/src/java.base/share/classes/com/sun/crypto/provider/GaloisCounterMode.java +++ b/src/java.base/share/classes/com/sun/crypto/provider/GaloisCounterMode.java @@ -72,7 +72,7 @@ abstract class GaloisCounterMode extends CipherSpi { // data size when buffer is divided up to aid in intrinsics private static final int TRIGGERLEN = 65536; // 64k // x86-64 parallel intrinsic data size - private static final int PARALLEL_LEN = 7680; + private static final int PARALLEL_LEN = 512; // max data size for x86-64 intrinsic private static final int SPLIT_LEN = 1048576; // 1MB diff --git a/src/java.base/share/classes/java/io/BufferedInputStream.java b/src/java.base/share/classes/java/io/BufferedInputStream.java index cfc2a3d2c75..c401873ce12 100644 --- a/src/java.base/share/classes/java/io/BufferedInputStream.java +++ b/src/java.base/share/classes/java/io/BufferedInputStream.java @@ -50,6 +50,11 @@ * reread before new bytes are taken from * the contained input stream. * + * @apiNote + * Once wrapped in a {@code BufferedInputStream}, the underlying + * {@code InputStream} should not be used directly nor wrapped with + * another stream. + * * @author Arthur van Hoff * @since 1.0 */ diff --git a/src/java.base/share/classes/java/io/BufferedOutputStream.java b/src/java.base/share/classes/java/io/BufferedOutputStream.java index ecc1e8a8a48..687f0c91bc4 100644 --- a/src/java.base/share/classes/java/io/BufferedOutputStream.java +++ b/src/java.base/share/classes/java/io/BufferedOutputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2024, 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 @@ -35,6 +35,11 @@ * output stream without necessarily causing a call to the underlying * system for each byte written. * + * @apiNote + * Once wrapped in a {@code BufferedOutputStream}, the underlying + * {@code OutputStream} should not be used directly nor wrapped with + * another stream. + * * @author Arthur van Hoff * @since 1.0 */ diff --git a/src/java.base/share/classes/java/io/BufferedReader.java b/src/java.base/share/classes/java/io/BufferedReader.java index 2cd027c8bd8..c2f6b89e086 100644 --- a/src/java.base/share/classes/java/io/BufferedReader.java +++ b/src/java.base/share/classes/java/io/BufferedReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2024, 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 @@ -43,8 +43,9 @@ * *

In general, each read request made of a Reader causes a corresponding * read request to be made of the underlying character or byte stream. It is - * therefore advisable to wrap a BufferedReader around any Reader whose read() - * operations may be costly, such as FileReaders and InputStreamReaders. For + * therefore advisable to wrap a {@code BufferedReader} around any + * {@code Reader} whose {@code read()} operations may be costly, such as + * {@code FileReader}s and {@code InputStreamReader}s. For * example, * * {@snippet lang=java : @@ -52,12 +53,18 @@ * } * * will buffer the input from the specified file. Without buffering, each - * invocation of read() or readLine() could cause bytes to be read from the - * file, converted into characters, and then returned, which can be very - * inefficient. + * invocation of {@code read()} or {@code readLine()} could cause bytes to be + * read from the file, converted into characters, and then returned, which can + * be very inefficient. * - *

Programs that use DataInputStreams for textual input can be localized by - * replacing each DataInputStream with an appropriate BufferedReader. + *

Programs that use {@code DataInputStream}s for textual input can be + * localized by replacing each {@code DataInputStream} with an appropriate + * {@code BufferedReader}. + * + * @apiNote + * Once wrapped in a {@code BufferedReader}, the underlying + * {@code Reader} should not be used directly nor wrapped with + * another reader. * * @see FileReader * @see InputStreamReader diff --git a/src/java.base/share/classes/java/io/BufferedWriter.java b/src/java.base/share/classes/java/io/BufferedWriter.java index 4904f718072..17862a265ae 100644 --- a/src/java.base/share/classes/java/io/BufferedWriter.java +++ b/src/java.base/share/classes/java/io/BufferedWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2024, 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 @@ -37,25 +37,31 @@ *

The buffer size may be specified, or the default size may be accepted. * The default is large enough for most purposes. * - *

A newLine() method is provided, which uses the platform's own notion of - * line separator as defined by the system property {@code line.separator}. - * Not all platforms use the newline character ('\n') to terminate lines. - * Calling this method to terminate each output line is therefore preferred to - * writing a newline character directly. + *

A {@code newLine()} method is provided, which uses the platform's own + * notion of line separator as defined by the system property + * {@linkplain System#lineSeparator() line.separator}. Not all platforms use the newline character ('\n') + * to terminate lines. Calling this method to terminate each output line is + * therefore preferred to writing a newline character directly. * - *

In general, a Writer sends its output immediately to the underlying - * character or byte stream. Unless prompt output is required, it is advisable - * to wrap a BufferedWriter around any Writer whose write() operations may be - * costly, such as FileWriters and OutputStreamWriters. For example, + *

In general, a {@code Writer} sends its output immediately to the + * underlying character or byte stream. Unless prompt output is required, it + * is advisable to wrap a {@code BufferedWriter} around any {@code Writer} whose + * {@code write()} operations may be costly, such as {@code FileWriter}s and + * {@code OutputStreamWriter}s. For example, * * {@snippet lang=java : * PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("foo.out"))); * } * - * will buffer the PrintWriter's output to the file. Without buffering, each - * invocation of a print() method would cause characters to be converted into - * bytes that would then be written immediately to the file, which can be very - * inefficient. + * will buffer the {@code PrintWriter}'s output to the file. Without buffering, + * each invocation of a {@code print()} method would cause characters to be + * converted into bytes that would then be written immediately to the file, + * which can be very inefficient. + * + * @apiNote + * Once wrapped in a {@code BufferedWriter}, the underlying + * {@code Writer} should not be used directly nor wrapped with + * another writer. * * @see PrintWriter * @see FileWriter diff --git a/src/java.base/share/classes/java/io/InputStream.java b/src/java.base/share/classes/java/io/InputStream.java index 736b6ebd904..a87870bfce0 100644 --- a/src/java.base/share/classes/java/io/InputStream.java +++ b/src/java.base/share/classes/java/io/InputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2024, 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 @@ -25,6 +25,8 @@ package java.io; +import jdk.internal.util.ArraysSupport; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -305,12 +307,9 @@ public int read(byte[] b, int off, int len) throws IOException { } /** - * The maximum size of array to allocate. - * Some VMs reserve some header words in an array. - * Attempts to allocate larger arrays may result in - * OutOfMemoryError: Requested array size exceeds VM limit + * The maximum size of array to allocate */ - private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8; + private static final int MAX_BUFFER_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; /** * Reads all remaining bytes from the input stream. This method blocks until diff --git a/src/java.base/share/classes/java/lang/Boolean.java b/src/java.base/share/classes/java/lang/Boolean.java index ba88157dc92..2c0925a9790 100644 --- a/src/java.base/share/classes/java/lang/Boolean.java +++ b/src/java.base/share/classes/java/lang/Boolean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2024, 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 @@ -37,10 +37,10 @@ import static java.lang.constant.ConstantDescs.CD_Boolean; /** - * The Boolean class wraps a value of the primitive type - * {@code boolean} in an object. An object of type - * {@code Boolean} contains a single field whose type is - * {@code boolean}. + * The {@code Boolean} class is the {@linkplain + * java.lang##wrapperClass wrapper class} for values of the primitive + * type {@code boolean}. An object of type {@code Boolean} contains a + * single field whose type is {@code boolean}. * *

In addition, this class provides many methods for * converting a {@code boolean} to a {@code String} and a diff --git a/src/java.base/share/classes/java/lang/Byte.java b/src/java.base/share/classes/java/lang/Byte.java index 18502abf69c..ade75a7a99e 100644 --- a/src/java.base/share/classes/java/lang/Byte.java +++ b/src/java.base/share/classes/java/lang/Byte.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2024, 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 @@ -39,10 +39,10 @@ import static java.lang.constant.ConstantDescs.DEFAULT_NAME; /** - * - * The {@code Byte} class wraps a value of primitive type {@code byte} - * in an object. An object of type {@code Byte} contains a single - * field whose type is {@code byte}. + * The {@code Byte} class is the {@linkplain + * java.lang##wrapperClass wrapper class} for values of the primitive + * type {@code byte}. An object of type {@code Byte} contains a + * single field whose type is {@code byte}. * *

In addition, this class provides several methods for converting * a {@code byte} to a {@code String} and a {@code String} to a {@code diff --git a/src/java.base/share/classes/java/lang/Character.java b/src/java.base/share/classes/java/lang/Character.java index a829d71e113..84db550d7cc 100644 --- a/src/java.base/share/classes/java/lang/Character.java +++ b/src/java.base/share/classes/java/lang/Character.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, 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 @@ -43,12 +43,12 @@ import static java.lang.constant.ConstantDescs.DEFAULT_NAME; /** - * The {@code Character} class wraps a value of the primitive - * type {@code char} in an object. An object of class - * {@code Character} contains a single field whose type is - * {@code char}. - *

- * In addition, this class provides a large number of static methods for + * The {@code Character} class is the {@linkplain + * java.lang##wrapperClass wrapper class} for values of the primitive + * type {@code char}. An object of type {@code Character} contains a + * single field whose type is {@code char}. + * + *

In addition, this class provides a large number of static methods for * determining a character's category (lowercase letter, digit, etc.) * and for converting characters from uppercase to lowercase and vice * versa. diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java index 48ffeea5289..79cd57011b0 100644 --- a/src/java.base/share/classes/java/lang/Class.java +++ b/src/java.base/share/classes/java/lang/Class.java @@ -140,22 +140,24 @@ * }} * * It is also possible to get the {@code Class} object for a named - * class or interface (or for {@code void}) using a class literal. + * class or interface (or for {@code void}) using a class literal + * (JLS {@jls 15.8.2}). * For example: * * {@snippet lang="java" : - * System.out.println("The name of class Foo is: "+Foo.class.getName()); + * System.out.println("The name of class Foo is: " + Foo.class.getName()); // @highlight substring="Foo.class" * } * *

Some methods of class {@code Class} expose whether the declaration of * a class or interface in Java source code was enclosed within * another declaration. Other methods describe how a class or interface - * is situated in a nest. A nest is a set of + * is situated in a {@index "nest"}. A nest is a set of * classes and interfaces, in the same run-time package, that * allow mutual access to their {@code private} members. - * The classes and interfaces are known as nestmates. + * The classes and interfaces are known as {@index "nestmates"} + * (JVMS {@jvms 4.7.29}). * One nestmate acts as the - * nest host, and enumerates the other nestmates which + * nest host (JVMS {@jvms 4.7.28}), and enumerates the other nestmates which * belong to the nest; each of them in turn records it as the nest host. * The classes and interfaces which belong to a nest, including its host, are * determined when @@ -167,7 +169,7 @@ *

Hidden Classes

* A class or interface created by the invocation of * {@link java.lang.invoke.MethodHandles.Lookup#defineHiddenClass(byte[], boolean, MethodHandles.Lookup.ClassOption...) - * Lookup::defineHiddenClass} is a {@linkplain Class#isHidden() hidden} + * Lookup::defineHiddenClass} is a {@linkplain Class#isHidden() hidden} * class or interface. * All kinds of class, including enum classes and record classes, may be * hidden classes; all kinds of interface, including annotation interfaces, @@ -216,7 +218,6 @@ * * @see java.lang.ClassLoader#defineClass(byte[], int, int) * @since 1.0 - * @jls 15.8.2 Class Literals */ public final class Class implements java.io.Serializable, GenericDeclaration, diff --git a/src/java.base/share/classes/java/lang/Double.java b/src/java.base/share/classes/java/lang/Double.java index 9b11964d9e6..68fff6a2fbd 100644 --- a/src/java.base/share/classes/java/lang/Double.java +++ b/src/java.base/share/classes/java/lang/Double.java @@ -36,10 +36,10 @@ import jdk.internal.vm.annotation.IntrinsicCandidate; /** - * The {@code Double} class wraps a value of the primitive type - * {@code double} in an object. An object of type - * {@code Double} contains a single field whose type is - * {@code double}. + * The {@code Double} class is the {@linkplain + * java.lang##wrapperClass wrapper class} for values of the primitive + * type {@code double}. An object of type {@code Double} contains a + * single field whose type is {@code double}. * *

In addition, this class provides several methods for converting a * {@code double} to a {@code String} and a @@ -148,7 +148,7 @@ * relations that can be defined over floating-point values: * *

- *
numerical equality ({@code ==} + *
{@index "numerical equality"} ({@code ==} * operator): (Not an equivalence relation)
*
Two floating-point values represent the same extended real * number. The extended real numbers are the real numbers augmented @@ -158,7 +158,7 @@ * number and is not equal to any value, including itself. *
* - *
bit-wise equivalence:
+ *
{@index "bit-wise equivalence"}:
*
The bits of the two floating-point values are the same. This * equivalence relation for {@code double} values {@code a} and {@code * b} is implemented by the expression @@ -168,7 +168,7 @@ * is distinguished from every other bit pattern encoding a NaN. *
* - *
representation equivalence:
+ *
{@index "representation equivalence"}:
*
The two floating-point values represent the same IEEE 754 * datum. In particular, for {@linkplain #isFinite(double) * finite} values, the sign, {@linkplain Math#getExponent(double) diff --git a/src/java.base/share/classes/java/lang/Float.java b/src/java.base/share/classes/java/lang/Float.java index 02b66007773..470eb71cf70 100644 --- a/src/java.base/share/classes/java/lang/Float.java +++ b/src/java.base/share/classes/java/lang/Float.java @@ -36,10 +36,10 @@ import jdk.internal.vm.annotation.IntrinsicCandidate; /** - * The {@code Float} class wraps a value of primitive type - * {@code float} in an object. An object of type - * {@code Float} contains a single field whose type is - * {@code float}. + * The {@code Float} class is the {@linkplain + * java.lang##wrapperClass wrapper class} for values of the primitive + * type {@code float}. An object of type {@code Float} contains a + * single field whose type is {@code float}. * *

In addition, this class provides several methods for converting a * {@code float} to a {@code String} and a diff --git a/src/java.base/share/classes/java/lang/Integer.java b/src/java.base/share/classes/java/lang/Integer.java index 7a65046181f..eab0a942d9a 100644 --- a/src/java.base/share/classes/java/lang/Integer.java +++ b/src/java.base/share/classes/java/lang/Integer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2024, 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 @@ -45,9 +45,10 @@ import static java.lang.String.UTF16; /** - * The {@code Integer} class wraps a value of the primitive type - * {@code int} in an object. An object of type {@code Integer} - * contains a single field whose type is {@code int}. + * The {@code Integer} class is the {@linkplain + * java.lang##wrapperClass wrapper class} for values of the primitive + * type {@code int}. An object of type {@code Integer} contains a + * single field whose type is {@code int}. * *

In addition, this class provides several methods for converting * an {@code int} to a {@code String} and a {@code String} to an @@ -63,8 +64,9 @@ *

Implementation note: The implementations of the "bit twiddling" * methods (such as {@link #highestOneBit(int) highestOneBit} and * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are - * based on material from Henry S. Warren, Jr.'s Hacker's - * Delight, (Addison Wesley, 2002). + * based on material from Henry S. Warren, Jr.'s Hacker's + * Delight, (Addison Wesley, 2002) and Hacker's + * Delight, Second Edition, (Pearson Education, 2013). * * @author Lee Boynton * @author Arthur van Hoff @@ -1736,7 +1738,7 @@ public static int reverse(int i) { * compress(expand(x, m), m) == x & compress(m, m) * } *

- * The Sheep And Goats (SAG) operation (see Hacker's Delight, section 7.7) + * The Sheep And Goats (SAG) operation (see Hacker's Delight, Second Edition, section 7.7) * can be implemented as follows: * {@snippet lang="java" : * int compressLeft(int i, int mask) { diff --git a/src/java.base/share/classes/java/lang/Long.java b/src/java.base/share/classes/java/lang/Long.java index ee9533b29eb..f86e1622b38 100644 --- a/src/java.base/share/classes/java/lang/Long.java +++ b/src/java.base/share/classes/java/lang/Long.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2024, 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 @@ -45,8 +45,9 @@ import static java.lang.String.UTF16; /** - * The {@code Long} class wraps a value of the primitive type {@code - * long} in an object. An object of type {@code Long} contains a + * The {@code Long} class is the {@linkplain + * java.lang##wrapperClass wrapper class} for values of the primitive + * type {@code long}. An object of type {@code Long} contains a * single field whose type is {@code long}. * *

In addition, this class provides several methods for converting @@ -63,8 +64,9 @@ *

Implementation note: The implementations of the "bit twiddling" * methods (such as {@link #highestOneBit(long) highestOneBit} and * {@link #numberOfTrailingZeros(long) numberOfTrailingZeros}) are - * based on material from Henry S. Warren, Jr.'s Hacker's - * Delight, (Addison Wesley, 2002). + * based on material from Henry S. Warren, Jr.'s Hacker's + * Delight, (Addison Wesley, 2002) and Hacker's + * Delight, Second Edition, (Pearson Education, 2013). * * @author Lee Boynton * @author Arthur van Hoff @@ -1749,7 +1751,7 @@ public static long reverse(long i) { * compress(expand(x, m), m) == x & compress(m, m) * } *

- * The Sheep And Goats (SAG) operation (see Hacker's Delight, section 7.7) + * The Sheep And Goats (SAG) operation (see Hacker's Delight, Second Edition, section 7.7) * can be implemented as follows: * {@snippet lang="java" : * long compressLeft(long i, long mask) { diff --git a/src/java.base/share/classes/java/lang/Object.java b/src/java.base/share/classes/java/lang/Object.java index d9813df57a4..7909f053042 100644 --- a/src/java.base/share/classes/java/lang/Object.java +++ b/src/java.base/share/classes/java/lang/Object.java @@ -109,7 +109,7 @@ public Object() {} /** * Indicates whether some other object is "equal to" this one. *

- * The {@code equals} method implements an equivalence relation + * The {@code equals} method implements an {@index "equivalence relation"} * on non-null object references: *

    *
  • It is reflexive: for any non-null reference value diff --git a/src/java.base/share/classes/java/lang/Short.java b/src/java.base/share/classes/java/lang/Short.java index 6a148d1edac..ec792de47e2 100644 --- a/src/java.base/share/classes/java/lang/Short.java +++ b/src/java.base/share/classes/java/lang/Short.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2024, 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 @@ -39,8 +39,9 @@ import static java.lang.constant.ConstantDescs.DEFAULT_NAME; /** - * The {@code Short} class wraps a value of primitive type {@code - * short} in an object. An object of type {@code Short} contains a + * The {@code Short} class is the {@linkplain + * java.lang##wrapperClass wrapper class} for values of the primitive + * type {@code short}. An object of type {@code Short} contains a * single field whose type is {@code short}. * *

    In addition, this class provides several methods for converting diff --git a/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java b/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java index 16f513801a2..7b27238bbdf 100644 --- a/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java +++ b/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java @@ -429,6 +429,8 @@ default CodeBuilder trying(Consumer tryHandler, * @param tk the load type * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code tk} is {@link TypeKind#VOID void} + * or {@code slot} is out of range * @since 23 */ default CodeBuilder loadLocal(TypeKind tk, int slot) { @@ -440,6 +442,8 @@ default CodeBuilder loadLocal(TypeKind tk, int slot) { * @param tk the store type * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code tk} is {@link TypeKind#VOID void} + * or {@code slot} is out of range * @since 23 */ default CodeBuilder storeLocal(TypeKind tk, int slot) { @@ -793,6 +797,7 @@ default CodeBuilder characterRange(Label startScope, Label endScope, int charact * @param startScope the start scope of the variable * @param endScope the end scope of the variable * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder localVariable(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope) { return with(LocalVariable.of(slot, nameEntry, descriptorEntry, startScope, endScope)); @@ -806,6 +811,7 @@ default CodeBuilder localVariable(int slot, Utf8Entry nameEntry, Utf8Entry descr * @param startScope the start scope of the variable * @param endScope the end scope of the variable * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder localVariable(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope) { return localVariable(slot, @@ -822,6 +828,7 @@ default CodeBuilder localVariable(int slot, String name, ClassDesc descriptor, L * @param startScope the start scope of the variable * @param endScope the end scope of the variable * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder localVariableType(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope) { return with(LocalVariableType.of(slot, nameEntry, signatureEntry, startScope, endScope)); @@ -835,6 +842,7 @@ default CodeBuilder localVariableType(int slot, Utf8Entry nameEntry, Utf8Entry s * @param startScope the start scope of the variable * @param endScope the end scope of the variable * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder localVariableType(int slot, String name, Signature signature, Label startScope, Label endScope) { return localVariableType(slot, @@ -877,6 +885,7 @@ default CodeBuilder aastore() { * * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder aload(int slot) { return loadLocal(TypeKind.REFERENCE, slot); @@ -925,6 +934,7 @@ default CodeBuilder arraylength() { * * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder astore(int slot) { return storeLocal(TypeKind.REFERENCE, slot); @@ -958,6 +968,7 @@ default CodeBuilder bastore() { * Generate an instruction pushing an int in the range of byte onto the operand stack. * @param b the int in the range of byte * @return this builder + * @throws IllegalArgumentException if {@code b} is out of range of byte */ default CodeBuilder bipush(int b) { return with(ConstantInstruction.ofArgument(Opcode.BIPUSH, b)); @@ -1094,6 +1105,7 @@ default CodeBuilder ddiv() { * * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder dload(int slot) { return loadLocal(TypeKind.DOUBLE, slot); @@ -1139,6 +1151,7 @@ default CodeBuilder dreturn() { * * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder dstore(int slot) { return storeLocal(TypeKind.DOUBLE, slot); @@ -1306,6 +1319,7 @@ default CodeBuilder fdiv() { * * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder fload(int slot) { return loadLocal(TypeKind.FLOAT, slot); @@ -1351,6 +1365,7 @@ default CodeBuilder freturn() { * * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder fstore(int slot) { return storeLocal(TypeKind.FLOAT, slot); @@ -1726,6 +1741,7 @@ default CodeBuilder ifne(Label target) { * @param slot the local variable slot * @param val the increment value * @return this builder + * @throws IllegalArgumentException if {@code slot} or {@code val} is out of range */ default CodeBuilder iinc(int slot, int val) { return with(IncrementInstruction.of(slot, val)); @@ -1739,6 +1755,7 @@ default CodeBuilder iinc(int slot, int val) { * * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder iload(int slot) { return loadLocal(TypeKind.INT, slot); @@ -1997,6 +2014,7 @@ default CodeBuilder ishr() { * * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder istore(int slot) { return storeLocal(TypeKind.INT, slot); @@ -2159,6 +2177,7 @@ default CodeBuilder ldiv() { * * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder lload(int slot) { return loadLocal(TypeKind.LONG, slot); @@ -2228,6 +2247,7 @@ default CodeBuilder lshr() { * * @param slot the local variable slot * @return this builder + * @throws IllegalArgumentException if {@code slot} is out of range */ default CodeBuilder lstore(int slot) { return storeLocal(TypeKind.LONG, slot); @@ -2278,6 +2298,7 @@ default CodeBuilder monitorexit() { * @param array the array type * @param dims the number of dimensions * @return this builder + * @throws IllegalArgumentException if {@code dims} is out of range */ default CodeBuilder multianewarray(ClassEntry array, int dims) { return with(NewMultiArrayInstruction.of(array, dims)); @@ -2289,6 +2310,7 @@ default CodeBuilder multianewarray(ClassEntry array, int dims) { * @param dims the number of dimensions * @return this builder * @throws IllegalArgumentException if {@code array} represents a primitive type + * or if {@code dims} is out of range */ default CodeBuilder multianewarray(ClassDesc array, int dims) { return multianewarray(constantPool().classEntry(array), dims); @@ -2327,6 +2349,8 @@ default CodeBuilder new_(ClassDesc clazz) { * Generate an instruction to create a new array of a primitive type * @param typeKind the primitive array type * @return this builder + * @throws IllegalArgumentException when the {@code typeKind} is not a legal + * primitive array component type */ default CodeBuilder newarray(TypeKind typeKind) { return with(NewPrimitiveArrayInstruction.of(typeKind)); @@ -2423,6 +2447,7 @@ default CodeBuilder sastore() { * Generate an instruction pushing an int in the range of short onto the operand stack. * @param s the int in the range of short * @return this builder + * @throws IllegalArgumentException if {@code s} is out of range of short */ default CodeBuilder sipush(int s) { return with(ConstantInstruction.ofArgument(Opcode.SIPUSH, s)); diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/DiscontinuedInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/DiscontinuedInstruction.java index 61ea14c4598..84bead6d8cc 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/DiscontinuedInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/DiscontinuedInstruction.java @@ -30,6 +30,7 @@ import java.lang.classfile.Label; import java.lang.classfile.Opcode; import jdk.internal.classfile.impl.AbstractInstruction; +import jdk.internal.classfile.impl.BytecodeHelpers; import jdk.internal.classfile.impl.Util; import jdk.internal.javac.PreviewFeature; @@ -112,10 +113,10 @@ sealed interface RetInstruction extends DiscontinuedInstruction * which must be of kind {@link Opcode.Kind#DISCONTINUED_RET} * @param slot the local variable slot to load return address from * @throws IllegalArgumentException if the opcode kind is not - * {@link Opcode.Kind#DISCONTINUED_RET}. + * {@link Opcode.Kind#DISCONTINUED_RET} or if {@code slot} is out of range */ static RetInstruction of(Opcode op, int slot) { - Util.checkKind(op, Opcode.Kind.DISCONTINUED_RET); + BytecodeHelpers.validateRet(op, slot); return new AbstractInstruction.UnboundRetInstruction(op, slot); } @@ -123,6 +124,7 @@ static RetInstruction of(Opcode op, int slot) { * {@return a RET instruction} * * @param slot the local variable slot to load return address from + * @throws IllegalArgumentException if {@code slot} is out of range */ static RetInstruction of(int slot) { return of(slot < 256 ? Opcode.RET : Opcode.RET_W, slot); diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/IncrementInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/IncrementInstruction.java index 3bde87ee48d..bebb101d7f3 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/IncrementInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/IncrementInstruction.java @@ -58,6 +58,7 @@ public sealed interface IncrementInstruction extends Instruction * * @param slot the local variable slot to increment * @param constant the value to increment by + * @throws IllegalArgumentException if {@code slot} or {@code constant} is out of range */ static IncrementInstruction of(int slot, int constant) { return new AbstractInstruction.UnboundIncrementInstruction(slot, constant); diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/LoadInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/LoadInstruction.java index f4cc8bab794..ea10ba6a0d0 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/LoadInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/LoadInstruction.java @@ -62,9 +62,12 @@ public sealed interface LoadInstruction extends Instruction * * @param kind the type of the value to be loaded * @param slot the local variable slot to load from + * @throws IllegalArgumentException if {@code kind} is + * {@link TypeKind#VOID void} or {@code slot} is out of range */ static LoadInstruction of(TypeKind kind, int slot) { - return of(BytecodeHelpers.loadOpcode(kind, slot), slot); + var opcode = BytecodeHelpers.loadOpcode(kind, slot); // validates slot, trusted + return new AbstractInstruction.UnboundLoadInstruction(opcode, slot); } /** @@ -74,10 +77,11 @@ static LoadInstruction of(TypeKind kind, int slot) { * which must be of kind {@link Opcode.Kind#LOAD} * @param slot the local variable slot to load from * @throws IllegalArgumentException if the opcode kind is not - * {@link Opcode.Kind#LOAD}. + * {@link Opcode.Kind#LOAD} or {@code slot} is out of range */ static LoadInstruction of(Opcode op, int slot) { Util.checkKind(op, Opcode.Kind.LOAD); + BytecodeHelpers.validateSlot(op, slot, true); return new AbstractInstruction.UnboundLoadInstruction(op, slot); } } diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariable.java b/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariable.java index 84a85993152..390034bd666 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariable.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariable.java @@ -92,6 +92,7 @@ default ClassDesc typeSymbol() { * @param descriptorEntry the local variable descriptor * @param startScope the start range of the local variable scope * @param endScope the end range of the local variable scope + * @throws IllegalArgumentException if {@code slot} is out of range */ static LocalVariable of(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope) { return new AbstractPseudoInstruction.UnboundLocalVariable(slot, nameEntry, descriptorEntry, @@ -106,6 +107,7 @@ static LocalVariable of(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry * @param descriptor the local variable descriptor * @param startScope the start range of the local variable scope * @param endScope the end range of the local variable scope + * @throws IllegalArgumentException if {@code slot} is out of range */ static LocalVariable of(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope) { return of(slot, diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariableType.java b/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariableType.java index 4409abe6db2..d0d2cd1581f 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariableType.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariableType.java @@ -89,6 +89,7 @@ default Signature signatureSymbol() { * @param signatureEntry the local variable signature * @param startScope the start range of the local variable scope * @param endScope the end range of the local variable scope + * @throws IllegalArgumentException if {@code slot} is out of range */ static LocalVariableType of(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope) { return new AbstractPseudoInstruction.UnboundLocalVariableType(slot, nameEntry, signatureEntry, @@ -103,6 +104,7 @@ static LocalVariableType of(int slot, Utf8Entry nameEntry, Utf8Entry signatureEn * @param signature the local variable signature * @param startScope the start range of the local variable scope * @param endScope the end range of the local variable scope + * @throws IllegalArgumentException if {@code slot} is out of range */ static LocalVariableType of(int slot, String name, Signature signature, Label startScope, Label endScope) { return of(slot, diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/NewMultiArrayInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/NewMultiArrayInstruction.java index 2f45b967603..2c572c607b4 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/NewMultiArrayInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/NewMultiArrayInstruction.java @@ -29,6 +29,7 @@ import java.lang.classfile.constantpool.ClassEntry; import java.lang.classfile.Instruction; import jdk.internal.classfile.impl.AbstractInstruction; +import jdk.internal.classfile.impl.BytecodeHelpers; import jdk.internal.javac.PreviewFeature; /** @@ -58,9 +59,11 @@ public sealed interface NewMultiArrayInstruction extends Instruction * * @param arrayTypeEntry the type of the array * @param dimensions the number of dimensions of the array + * @throws IllegalArgumentException if {@code dimensions} is out of range */ static NewMultiArrayInstruction of(ClassEntry arrayTypeEntry, int dimensions) { + BytecodeHelpers.validateMultiArrayDimensions(dimensions); return new AbstractInstruction.UnboundNewMultidimensionalArrayInstruction(arrayTypeEntry, dimensions); } } diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/StoreInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/StoreInstruction.java index 278bf8c0ec3..5bfe13421da 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/StoreInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/StoreInstruction.java @@ -61,9 +61,12 @@ public sealed interface StoreInstruction extends Instruction * * @param kind the type of the value to be stored * @param slot the local variable slot to store to + * @throws IllegalArgumentException if {@code kind} is {@link + * TypeKind#VOID void} or {@code slot} is out of range */ static StoreInstruction of(TypeKind kind, int slot) { - return of(BytecodeHelpers.storeOpcode(kind, slot), slot); + var opcode = BytecodeHelpers.storeOpcode(kind, slot); // validates slot + return new AbstractInstruction.UnboundStoreInstruction(opcode, slot); } /** @@ -73,10 +76,11 @@ static StoreInstruction of(TypeKind kind, int slot) { * which must be of kind {@link Opcode.Kind#STORE} * @param slot the local variable slot to store to * @throws IllegalArgumentException if the opcode kind is not - * {@link Opcode.Kind#STORE}. + * {@link Opcode.Kind#STORE} or {@code slot} is out of range */ static StoreInstruction of(Opcode op, int slot) { Util.checkKind(op, Opcode.Kind.STORE); + BytecodeHelpers.validateSlot(op, slot, false); return new AbstractInstruction.UnboundStoreInstruction(op, slot); } } diff --git a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java index 4fbbec17693..97848e1fcb3 100644 --- a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java +++ b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java @@ -1526,7 +1526,7 @@ public void accept(CodeBuilder cb) { * length = length(this.length, arg0, arg1, ..., argN); */ if (staticConcat) { - cb.ldc(length); + cb.loadConstant(length); } else { cb.aload(thisSlot) .getfield(concatClass, "length", CD_int); @@ -1549,7 +1549,7 @@ public void accept(CodeBuilder cb) { * length -= suffix.length(); */ if (staticConcat) { - cb.ldc(constants[paramCount].length()) + cb.loadConstant(constants[paramCount].length()) .isub() .istore(lengthSlot); } else { @@ -1557,7 +1557,7 @@ public void accept(CodeBuilder cb) { .getfield(concatClass, "constants", CD_Array_String) .dup() .astore(constantsSlot) - .ldc(paramCount) + .loadConstant(paramCount) .aaload() .dup() .astore(suffixSlot) @@ -1572,7 +1572,7 @@ public void accept(CodeBuilder cb) { * buf = newArrayWithSuffix(suffix, length, coder) */ if (staticConcat) { - cb.ldc(constants[paramCount]); + cb.loadConstant(constants[paramCount]); } else { cb.aload(suffixSlot); } @@ -1759,10 +1759,10 @@ public void accept(CodeBuilder cb) { .loadLocal(kind, cb.parameterSlot(i)); if (staticConcat) { - cb.ldc(constants[i - 3]); + cb.loadConstant(constants[i - 3]); } else { cb.aload(constantsSlot) - .ldc(i - 4) + .loadConstant(i - 4) .aaload(); } diff --git a/src/java.base/share/classes/java/lang/package-info.java b/src/java.base/share/classes/java/lang/package-info.java index 882a610c1a0..0484ecb2952 100644 --- a/src/java.base/share/classes/java/lang/package-info.java +++ b/src/java.base/share/classes/java/lang/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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 @@ -25,35 +25,42 @@ /** * Provides classes that are fundamental to the design of the Java - * programming language. The most important classes are {@code - * Object}, which is the root of the class hierarchy, and {@code + * programming language. The most important classes are {@link + * Object}, which is the root of the class hierarchy, and {@link * Class}, instances of which represent classes at run time. * *

    Frequently it is necessary to represent a value of primitive - * type as if it were an object. The wrapper classes {@code Boolean}, - * {@code Character}, {@code Integer}, {@code Long}, {@code Float}, - * and {@code Double} serve this purpose. An object of type {@code - * Double}, for example, contains a field whose type is double, - * representing that value in such a way that a reference to it can be - * stored in a variable of reference type. These classes also provide - * a number of methods for converting among primitive values, as well - * as supporting such standard methods as equals and hashCode. The - * {@code Void} class is a non-instantiable class that holds a - * reference to a {@code Class} object representing the type void. + * type as if it were an object.The {@index + * "wrapper classes"} {@link Boolean}, {@link Byte}, {@link + * Character}, {@link Short}, {@link Integer}, {@link Long}, {@link + * Float}, and {@link Double} serve this purpose. An object of type + * {@code Double}, for example, contains a field whose type is {@code + * double}, representing that value in such a way that a reference to + * it can be stored in a variable of reference type. As discussed in + * The Java Language Specification, the wrapper classes + * are involved in boxing (JLS {@jls 5.1.7}) and unboxing (JLS {@jls + * 5.1.8}) conversions. These classes provide a number of methods for + * converting among primitive values, as well as methods supporting + * such standard functionality as {@code equals} and {@code hashCode}. + * The {@link Void} class is a non-instantiable class that holds a + * reference to a {@code Class} object representing the type {@code + * void}. * - *

    The class {@code Math} provides commonly used mathematical - * functions such as sine, cosine, and square root. The classes {@code - * String}, {@code StringBuffer}, and {@code StringBuilder} similarly - * provide commonly used operations on character strings. + *

    The class {@link Math} provides commonly used mathematical + * functions such as {@linkplain Math#sin(double) sine}, {@linkplain + * Math#cos(double) cosine}, and {@linkplain Math#sqrt(double) square + * root}. The classes {@link String}, {@link StringBuffer}, and {@link + * StringBuilder} similarly provide commonly used operations on + * character strings. * - *

    Classes {@code ClassLoader}, {@code Process}, {@code - * ProcessBuilder}, {@code Runtime}, {@code SecurityManager}, and - * {@code System} provide "system operations" that manage the dynamic + *

    Classes {@link ClassLoader}, {@link Process}, {@link + * ProcessBuilder}, {@link Runtime}, {@link SecurityManager}, and + * {@link System} provide "system operations" that manage the dynamic * loading of classes, creation of external processes, host * environment inquiries such as the time of day, and enforcement of * security policies. * - *

    Class {@code Throwable} encompasses objects that may be thrown + *

    Class {@link Throwable} encompasses objects that may be thrown * by the {@code throw} statement. Subclasses of {@code Throwable} * represent errors and exceptions. * diff --git a/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java b/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java index bfdb76e2ef1..f380cf1070d 100644 --- a/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java +++ b/src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java @@ -659,7 +659,7 @@ private static Consumer generateTypeSwitchSkeleton(Class selecto MethodTypeDesc.of(ConstantDescs.CD_char)); cb.labelBinding(compare); - cb.ldc(integerLabel); + cb.loadConstant(integerLabel); cb.if_icmpne(next); } else if ((caseLabel instanceof Long || caseLabel instanceof Float || diff --git a/src/java.base/share/classes/java/math/MutableBigInteger.java b/src/java.base/share/classes/java/math/MutableBigInteger.java index b84e50f567e..6ff435ba1ed 100644 --- a/src/java.base/share/classes/java/math/MutableBigInteger.java +++ b/src/java.base/share/classes/java/math/MutableBigInteger.java @@ -597,44 +597,52 @@ void leftShift(int n) { */ if (intLen == 0) return; + int nInts = n >>> 5; - int nBits = n&0x1F; - int bitsInHighWord = BigInteger.bitLengthForInt(value[offset]); + int nBits = n & 0x1F; + int leadingZeros = Integer.numberOfLeadingZeros(value[offset]); // If shift can be done without moving words, do so - if (n <= (32-bitsInHighWord)) { + if (n <= leadingZeros) { primitiveLeftShift(nBits); return; } - int newLen = intLen + nInts +1; - if (nBits <= (32-bitsInHighWord)) - newLen--; - if (value.length < newLen) { - // The array must grow - int[] result = new int[newLen]; - for (int i=0; i < intLen; i++) - result[i] = value[offset+i]; - setValue(result, newLen); - } else if (value.length - offset >= newLen) { - // Use space on right - for(int i=0; i < newLen - intLen; i++) - value[offset+intLen+i] = 0; + int newLen = intLen + nInts; + if (nBits > leadingZeros) + newLen++; + + int[] result; + final int newOffset; + if (value.length < newLen) { // The array must grow + result = new int[newLen]; + newOffset = 0; } else { - // Must use space on left - for (int i=0; i < intLen; i++) - value[i] = value[offset+i]; - for (int i=intLen; i < newLen; i++) - value[i] = 0; - offset = 0; + result = value; + newOffset = value.length - offset >= newLen ? offset : 0; } + + int trailingZerosPos = newOffset + intLen; + if (nBits != 0) { + // Do primitive shift directly for speed + if (nBits <= leadingZeros) { + primitiveLeftShift(nBits, result, newOffset); // newOffset <= offset + } else { + int lastInt = value[offset + intLen - 1]; + primitiveRightShift(32 - nBits, result, newOffset); // newOffset <= offset + result[trailingZerosPos++] = lastInt << nBits; + } + } else if (result != value || newOffset != offset) { + System.arraycopy(value, offset, result, newOffset, intLen); + } + + // Add trailing zeros + if (result == value) + Arrays.fill(result, trailingZerosPos, newOffset + newLen, 0); + + value = result; intLen = newLen; - if (nBits == 0) - return; - if (nBits <= (32-bitsInHighWord)) - primitiveLeftShift(nBits); - else - primitiveRightShift(32 -nBits); + offset = newOffset; } /** @@ -698,15 +706,30 @@ private int mulsubBorrow(int[] q, int[] a, int x, int len, int offset) { * less than 32. * Assumes that intLen > 0, n > 0 for speed */ - private final void primitiveRightShift(int n) { + private void primitiveRightShift(int n) { + primitiveRightShift(n, value, offset); + } + + /** + * Right shift this MutableBigInteger n bits, where n is + * less than 32, placing the result in the specified array. + * Assumes that intLen > 0, n > 0 for speed. + * The result can be the value array of this MutableBigInteger, + * but for speed the copy is not performed safely, so, in that case + * the caller has to make sure that + * {@code (resFrom <= offset || resFrom >= offset + intLen)}. + */ + private void primitiveRightShift(int n, int[] result, int resFrom) { int[] val = value; int n2 = 32 - n; - for (int i=offset+intLen-1, c=val[i]; i > offset; i--) { - int b = c; - c = val[i-1]; - val[i] = (c << n2) | (b >>> n); + + int b = val[offset]; + result[resFrom] = b >>> n; + for (int i = 1; i < intLen; i++) { + int c = b; + b = val[offset + i]; + result[resFrom + i] = (c << n2) | (b >>> n); } - val[offset] >>>= n; } /** @@ -714,15 +737,30 @@ private final void primitiveRightShift(int n) { * less than 32. * Assumes that intLen > 0, n > 0 for speed */ - private final void primitiveLeftShift(int n) { + private void primitiveLeftShift(int n) { + primitiveLeftShift(n, value, offset); + } + + /** + * Left shift this MutableBigInteger n bits, where n is + * less than 32, placing the result in the specified array. + * Assumes that intLen > 0, n > 0 for speed. + * The result can be the value array of this MutableBigInteger, + * but for speed the copy is not performed safely, so, in that case + * the caller has to make sure that + * {@code (resFrom <= offset || resFrom >= offset + intLen)}. + */ + private void primitiveLeftShift(int n, int[] result, int resFrom) { int[] val = value; int n2 = 32 - n; - for (int i=offset, c=val[i], m=i+intLen-1; i < m; i++) { - int b = c; - c = val[i+1]; - val[i] = (b << n) | (c >>> n2); + final int m = intLen - 1; + int b = val[offset]; + for (int i = 0; i < m; i++) { + int c = val[offset + i + 1]; + result[resFrom + i] = (b << n) | (c >>> n2); + b = c; } - val[offset+intLen-1] <<= n; + result[resFrom + m] = b << n; } /** @@ -1511,17 +1549,6 @@ long divide(long v, MutableBigInteger quotient) { } } - private static void copyAndShift(int[] src, int srcFrom, int srcLen, int[] dst, int dstFrom, int shift) { - int n2 = 32 - shift; - int c=src[srcFrom]; - for (int i=0; i < srcLen-1; i++) { - int b = c; - c = src[++srcFrom]; - dst[dstFrom+i] = (b << shift) | (c >>> n2); - } - dst[dstFrom+srcLen-1] = c << shift; - } - /** * Divide this MutableBigInteger by the divisor. * The quotient will be placed into the provided quotient object & @@ -1539,13 +1566,13 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div, MutableBigInteger rem; // Remainder starts as dividend with space for a leading zero if (shift > 0) { divisor = new int[dlen]; - copyAndShift(div.value,div.offset,dlen,divisor,0,shift); + div.primitiveLeftShift(shift, divisor, 0); if (Integer.numberOfLeadingZeros(value[offset]) >= shift) { int[] remarr = new int[intLen + 1]; rem = new MutableBigInteger(remarr); rem.intLen = intLen; rem.offset = 1; - copyAndShift(value,offset,intLen,remarr,1,shift); + this.primitiveLeftShift(shift, remarr, 1); } else { int[] remarr = new int[intLen + 2]; rem = new MutableBigInteger(remarr); diff --git a/src/java.base/share/classes/java/nio/charset/spi/CharsetProvider.java b/src/java.base/share/classes/java/nio/charset/spi/CharsetProvider.java index 11d36ee242d..114558d9392 100644 --- a/src/java.base/share/classes/java/nio/charset/spi/CharsetProvider.java +++ b/src/java.base/share/classes/java/nio/charset/spi/CharsetProvider.java @@ -33,17 +33,29 @@ * Charset service-provider class. * *

    A charset provider is a concrete subclass of this class that has a - * zero-argument constructor and some number of associated charset - * implementation classes. Charset providers may be installed in an instance - * of the Java platform as extensions. Providers may also be made available by - * adding them to the application class path or by some other - * platform-specific means. Charset providers are looked up via the current - * thread's {@link java.lang.Thread#getContextClassLoader() context class - * loader}. + * zero-argument constructor and some number of associated {@code Charset} + * implementation classes. Charset providers are deployed on the application + * module path or the application class path. In order to be looked up, charset + * providers must be visible to the {@link ClassLoader#getSystemClassLoader() system + * class loader}. See {@link java.util.ServiceLoader##developing-service-providers + * Deploying Service Providers} for further detail on deploying a charset + * provider as a module or on the class path. * - *

    A charset provider identifies itself with a provider-configuration file - * named {@code java.nio.charset.spi.CharsetProvider} in the resource - * directory {@code META-INF/services}. The file should contain a list of + *

    For a charset provider deployed in a module, the provides + * directive must be specified in the module declaration. The provides directive + * specifies both the service and the service provider. In this case, the service + * is {@code java.nio.charset.spi.CharsetProvider}. + * + *

    As an example, a charset provider deployed as a module might specify the + * following directive: + *

    {@code
    + *     provides java.nio.charset.spi.CharsetProvider with com.example.ExternalCharsetProvider;
    + * }
    + * + *

    For a charset provider deployed on the class path, it identifies itself + * with a provider-configuration file named {@code + * java.nio.charset.spi.CharsetProvider} in the resource directory + * {@code META-INF/services}. The file should contain a list of * fully-qualified concrete charset-provider class names, one per line. A line * is terminated by any one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a line feed. diff --git a/src/java.base/share/classes/java/util/ArrayDeque.java b/src/java.base/share/classes/java/util/ArrayDeque.java index 9997110b658..60bb3ed4a45 100644 --- a/src/java.base/share/classes/java/util/ArrayDeque.java +++ b/src/java.base/share/classes/java/util/ArrayDeque.java @@ -38,6 +38,7 @@ import java.util.function.Consumer; import java.util.function.Predicate; import jdk.internal.access.SharedSecrets; +import jdk.internal.util.ArraysSupport; /** * Resizable-array implementation of the {@link Deque} interface. Array @@ -124,12 +125,9 @@ public class ArrayDeque extends AbstractCollection transient int tail; /** - * The maximum size of array to allocate. - * Some VMs reserve some header words in an array. - * Attempts to allocate larger arrays may result in - * OutOfMemoryError: Requested array size exceeds VM limit + * The maximum size of array to allocate */ - private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; + private static final int MAX_ARRAY_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; /** * Increases the capacity of this deque by at least the given amount. diff --git a/src/java.base/share/classes/java/util/BitSet.java b/src/java.base/share/classes/java/util/BitSet.java index fea9693d7ed..de4910b20c6 100644 --- a/src/java.base/share/classes/java/util/BitSet.java +++ b/src/java.base/share/classes/java/util/BitSet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2024, 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 @@ -1184,7 +1184,7 @@ private void readObject(ObjectInputStream s) public String toString() { checkInvariants(); - final int MAX_INITIAL_CAPACITY = Integer.MAX_VALUE - 8; + final int MAX_INITIAL_CAPACITY = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; int numBits = (wordsInUse > 128) ? cardinality() : wordsInUse * BITS_PER_WORD; // Avoid overflow in the case of a humongous numBits diff --git a/src/java.base/share/classes/java/util/Hashtable.java b/src/java.base/share/classes/java/util/Hashtable.java index 1fd56d5a258..ddff8f7a0ab 100644 --- a/src/java.base/share/classes/java/util/Hashtable.java +++ b/src/java.base/share/classes/java/util/Hashtable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2024, 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,6 +30,7 @@ import java.util.function.Function; import java.util.function.BiFunction; import jdk.internal.access.SharedSecrets; +import jdk.internal.util.ArraysSupport; /** * This class implements a hash table, which maps keys to values. Any @@ -390,12 +391,9 @@ public synchronized V get(Object key) { } /** - * The maximum size of array to allocate. - * Some VMs reserve some header words in an array. - * Attempts to allocate larger arrays may result in - * OutOfMemoryError: Requested array size exceeds VM limit + * The maximum size of array to allocate */ - private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; + private static final int MAX_ARRAY_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; /** * Increases the capacity of and internally reorganizes this diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java index 4df4f73695f..5a23fdb05a6 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java @@ -69,6 +69,7 @@ import java.util.function.ToLongFunction; import java.util.stream.Stream; import jdk.internal.misc.Unsafe; +import jdk.internal.util.ArraysSupport; /** * A hash table supporting full concurrency of retrievals and @@ -517,7 +518,7 @@ public class ConcurrentHashMap extends AbstractMap * The largest possible (non-power of two) array size. * Needed by toArray and related methods. */ - static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; + static final int MAX_ARRAY_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; /** * The default concurrency level for this table. Unused but diff --git a/src/java.base/share/classes/java/util/regex/Pattern.java b/src/java.base/share/classes/java/util/regex/Pattern.java index 0e87bebdcbf..654adb5376f 100644 --- a/src/java.base/share/classes/java/util/regex/Pattern.java +++ b/src/java.base/share/classes/java/util/regex/Pattern.java @@ -1502,8 +1502,8 @@ public static String quote(String s) { return "\\Q" + s + "\\E"; int lenHint = s.length(); - lenHint = (lenHint < Integer.MAX_VALUE - 8 - lenHint) ? - (lenHint << 1) : (Integer.MAX_VALUE - 8); + lenHint = (lenHint < ArraysSupport.SOFT_MAX_ARRAY_LENGTH - lenHint) ? + (lenHint << 1) : ArraysSupport.SOFT_MAX_ARRAY_LENGTH; StringBuilder sb = new StringBuilder(lenHint); sb.append("\\Q"); diff --git a/src/java.base/share/classes/java/util/stream/Nodes.java b/src/java.base/share/classes/java/util/stream/Nodes.java index 7c06823b925..77d70091717 100644 --- a/src/java.base/share/classes/java/util/stream/Nodes.java +++ b/src/java.base/share/classes/java/util/stream/Nodes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -24,6 +24,8 @@ */ package java.util.stream; +import jdk.internal.util.ArraysSupport; + import java.util.ArrayDeque; import java.util.Arrays; import java.util.Collection; @@ -57,7 +59,7 @@ private Nodes() { /** * The maximum size of an array that can be allocated. */ - static final long MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; + static final long MAX_ARRAY_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; // IllegalArgumentException messages static final String BAD_SIZE = "Stream size exceeds max array size"; diff --git a/src/java.base/share/classes/java/util/zip/ZipFile.java b/src/java.base/share/classes/java/util/zip/ZipFile.java index d54e6c1e4fc..43b2261f1c6 100644 --- a/src/java.base/share/classes/java/util/zip/ZipFile.java +++ b/src/java.base/share/classes/java/util/zip/ZipFile.java @@ -63,6 +63,7 @@ import jdk.internal.access.JavaUtilZipFileAccess; import jdk.internal.access.JavaUtilJarAccess; import jdk.internal.access.SharedSecrets; +import jdk.internal.util.ArraysSupport; import jdk.internal.util.OperatingSystem; import jdk.internal.perf.PerfCounter; import jdk.internal.ref.CleanerFactory; @@ -1178,6 +1179,8 @@ private static class Source { // "META-INF/".length() private static final int META_INF_LEN = 9; private static final int[] EMPTY_META_VERSIONS = new int[0]; + // CEN size is limited to the maximum array size in the JDK + private static final int MAX_CEN_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; private final Key key; // the key in files private final @Stable ZipCoder zc; // ZIP coder used to decode/encode @@ -1185,7 +1188,7 @@ private static class Source { private int refs = 1; private RandomAccessFile zfile; // zfile of the underlying ZIP file - private byte[] cen; // CEN & ENDHDR + private byte[] cen; // CEN private long locpos; // position of first LOC header (usually 0) private byte[] comment; // ZIP file comment // list of meta entries in META-INF dir @@ -1241,7 +1244,7 @@ private int checkAndAddEntry(int pos, int index) // should not exceed 65,535 bytes per the PKWare APP.NOTE // 4.4.10, 4.4.11, & 4.4.12. Also check that current CEN header will // not exceed the length of the CEN array - if (headerSize > 0xFFFF || pos + headerSize > cen.length - ENDHDR) { + if (headerSize > 0xFFFF || pos + headerSize > cen.length) { zerror("invalid CEN header (bad header size)"); } @@ -1294,7 +1297,7 @@ private void checkExtraFields(int cenPos, int startingOffset, } // CEN Offset where this Extra field ends int extraEndOffset = startingOffset + extraFieldLen; - if (extraEndOffset > cen.length - ENDHDR) { + if (extraEndOffset > cen.length) { zerror("Invalid CEN header (extra data field size too long)"); } int currentOffset = startingOffset; @@ -1732,12 +1735,12 @@ private void initCEN(int knownTotal) throws IOException { if (locpos < 0) { zerror("invalid END header (bad central directory offset)"); } - // read in the CEN and END - if (end.cenlen + ENDHDR >= Integer.MAX_VALUE) { + // read in the CEN + if (end.cenlen > MAX_CEN_SIZE) { zerror("invalid END header (central directory size too large)"); } - cen = this.cen = new byte[(int)(end.cenlen + ENDHDR)]; - if (readFullyAt(cen, 0, cen.length, cenpos) != end.cenlen + ENDHDR) { + cen = this.cen = new byte[(int)end.cenlen]; + if (readFullyAt(cen, 0, cen.length, cenpos) != end.cenlen) { zerror("read CEN tables failed"); } this.total = end.centot; @@ -1766,7 +1769,7 @@ private void initCEN(int knownTotal) throws IOException { int idx = 0; // Index into the entries array int pos = 0; int entryPos = CENHDR; - int limit = cen.length - ENDHDR; + int limit = cen.length; manifestNum = 0; while (entryPos <= limit) { if (idx >= entriesLength) { @@ -1829,7 +1832,7 @@ private void initCEN(int knownTotal) throws IOException { } else { metaVersions = EMPTY_META_VERSIONS; } - if (pos + ENDHDR != cen.length) { + if (pos != cen.length) { zerror("invalid CEN header (bad header size)"); } } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractInstruction.java b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractInstruction.java index edcd6a7abff..d3258427937 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractInstruction.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractInstruction.java @@ -848,9 +848,9 @@ public static final class UnboundIncrementInstruction final int constant; public UnboundIncrementInstruction(int slot, int constant) { - super(slot <= 255 && constant < 128 && constant > -127 - ? Opcode.IINC - : Opcode.IINC_W); + super(BytecodeHelpers.validateAndIsWideIinc(slot, constant) + ? Opcode.IINC_W + : Opcode.IINC); this.slot = slot; this.constant = constant; } @@ -867,7 +867,7 @@ public int constant() { @Override public void writeTo(DirectCodeBuilder writer) { - writer.writeIncrement(slot, constant); + writer.writeIncrement(op == Opcode.IINC_W, slot, constant); } @Override diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPseudoInstruction.java b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPseudoInstruction.java index 00d817b8cb0..dc170ce72b5 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPseudoInstruction.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPseudoInstruction.java @@ -163,6 +163,7 @@ private abstract static sealed class AbstractLocalPseudo extends AbstractPseudoI protected final Label endScope; public AbstractLocalPseudo(int slot, Utf8Entry name, Utf8Entry descriptor, Label startScope, Label endScope) { + BytecodeHelpers.validateSlot(slot); this.slot = slot; this.name = name; this.descriptor = descriptor; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/BytecodeHelpers.java b/src/java.base/share/classes/jdk/internal/classfile/impl/BytecodeHelpers.java index a5b4b55b05b..6994a62c0ab 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/BytecodeHelpers.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/BytecodeHelpers.java @@ -45,6 +45,7 @@ import java.lang.classfile.constantpool.MemberRefEntry; import java.lang.classfile.constantpool.MethodHandleEntry; import java.lang.classfile.constantpool.NameAndTypeEntry; +import java.util.Objects; import static jdk.internal.classfile.impl.RawBytecodeHelper.*; @@ -60,6 +61,14 @@ public static IllegalArgumentException cannotConvertException(TypeKind from, Typ return new IllegalArgumentException(String.format("convert %s -> %s", from, to)); } + public static IllegalArgumentException slotOutOfBounds(int slot) { + return new IllegalArgumentException("Invalid slot index :".concat(Integer.toString(slot))); + } + + public static IllegalArgumentException slotOutOfBounds(Opcode opcode, int slot) { + return new IllegalArgumentException("Invalid slot index %d for %s".formatted(slot, opcode)); + } + public static Opcode loadOpcode(TypeKind tk, int slot) { return switch (tk) { case INT, SHORT, BYTE, CHAR, BOOLEAN @@ -78,7 +87,13 @@ public static Opcode aload(int slot) { case 1 -> Opcode.ALOAD_1; case 2 -> Opcode.ALOAD_2; case 3 -> Opcode.ALOAD_3; - default -> (slot < 256) ? Opcode.ALOAD : Opcode.ALOAD_W; + default -> { + if ((slot & 0xFF) == slot) + yield Opcode.ALOAD; + if ((slot & 0xFFFF) == slot) + yield Opcode.ALOAD_W; + throw slotOutOfBounds(slot); + } }; } @@ -88,7 +103,13 @@ public static Opcode fload(int slot) { case 1 -> Opcode.FLOAD_1; case 2 -> Opcode.FLOAD_2; case 3 -> Opcode.FLOAD_3; - default -> (slot < 256) ? Opcode.FLOAD : Opcode.FLOAD_W; + default -> { + if ((slot & 0xFF) == slot) + yield Opcode.FLOAD; + if ((slot & 0xFFFF) == slot) + yield Opcode.FLOAD_W; + throw slotOutOfBounds(slot); + } }; } @@ -98,7 +119,13 @@ public static Opcode dload(int slot) { case 1 -> Opcode.DLOAD_1; case 2 -> Opcode.DLOAD_2; case 3 -> Opcode.DLOAD_3; - default -> (slot < 256) ? Opcode.DLOAD : Opcode.DLOAD_W; + default -> { + if ((slot & 0xFF) == slot) + yield Opcode.DLOAD; + if ((slot & 0xFFFF) == slot) + yield Opcode.DLOAD_W; + throw slotOutOfBounds(slot); + } }; } @@ -108,7 +135,13 @@ public static Opcode lload(int slot) { case 1 -> Opcode.LLOAD_1; case 2 -> Opcode.LLOAD_2; case 3 -> Opcode.LLOAD_3; - default -> (slot < 256) ? Opcode.LLOAD : Opcode.LLOAD_W; + default -> { + if ((slot & 0xFF) == slot) + yield Opcode.LLOAD; + if ((slot & 0xFFFF) == slot) + yield Opcode.LLOAD_W; + throw slotOutOfBounds(slot); + } }; } @@ -118,7 +151,13 @@ public static Opcode iload(int slot) { case 1 -> Opcode.ILOAD_1; case 2 -> Opcode.ILOAD_2; case 3 -> Opcode.ILOAD_3; - default -> (slot < 256) ? Opcode.ILOAD : Opcode.ILOAD_W; + default -> { + if ((slot & 0xFF) == slot) + yield Opcode.ILOAD; + if ((slot & 0xFFFF) == slot) + yield Opcode.ILOAD_W; + throw slotOutOfBounds(slot); + } }; } @@ -140,7 +179,13 @@ public static Opcode astore(int slot) { case 1 -> Opcode.ASTORE_1; case 2 -> Opcode.ASTORE_2; case 3 -> Opcode.ASTORE_3; - default -> (slot < 256) ? Opcode.ASTORE : Opcode.ASTORE_W; + default -> { + if ((slot & 0xFF) == slot) + yield Opcode.ASTORE; + if ((slot & 0xFFFF) == slot) + yield Opcode.ASTORE_W; + throw slotOutOfBounds(slot); + } }; } @@ -150,7 +195,13 @@ public static Opcode fstore(int slot) { case 1 -> Opcode.FSTORE_1; case 2 -> Opcode.FSTORE_2; case 3 -> Opcode.FSTORE_3; - default -> (slot < 256) ? Opcode.FSTORE : Opcode.FSTORE_W; + default -> { + if ((slot & 0xFF) == slot) + yield Opcode.FSTORE; + if ((slot & 0xFFFF) == slot) + yield Opcode.FSTORE_W; + throw slotOutOfBounds(slot); + } }; } @@ -160,7 +211,13 @@ public static Opcode dstore(int slot) { case 1 -> Opcode.DSTORE_1; case 2 -> Opcode.DSTORE_2; case 3 -> Opcode.DSTORE_3; - default -> (slot < 256) ? Opcode.DSTORE : Opcode.DSTORE_W; + default -> { + if ((slot & 0xFF) == slot) + yield Opcode.DSTORE; + if ((slot & 0xFFFF) == slot) + yield Opcode.DSTORE_W; + throw slotOutOfBounds(slot); + } }; } @@ -170,7 +227,13 @@ public static Opcode lstore(int slot) { case 1 -> Opcode.LSTORE_1; case 2 -> Opcode.LSTORE_2; case 3 -> Opcode.LSTORE_3; - default -> (slot < 256) ? Opcode.LSTORE : Opcode.LSTORE_W; + default -> { + if ((slot & 0xFF) == slot) + yield Opcode.LSTORE; + if ((slot & 0xFFFF) == slot) + yield Opcode.LSTORE_W; + throw slotOutOfBounds(slot); + } }; } @@ -180,7 +243,13 @@ public static Opcode istore(int slot) { case 1 -> Opcode.ISTORE_1; case 2 -> Opcode.ISTORE_2; case 3 -> Opcode.ISTORE_3; - default -> (slot < 256) ? Opcode.ISTORE : Opcode.ISTORE_W; + default -> { + if ((slot & 0xFF) == slot) + yield Opcode.ISTORE; + if ((slot & 0xFFFF) == slot) + yield Opcode.ISTORE_W; + throw slotOutOfBounds(slot); + } }; } @@ -305,6 +374,48 @@ public static TypeKind convertToType(Opcode opcode) { }; } + public static void validateSlot(Opcode opcode, int slot, boolean load) { + int size = opcode.sizeIfFixed(); + if (size == 1 && slot == (load ? intrinsicLoadSlot(opcode) : intrinsicStoreSlot(opcode)) || + size == 2 && slot == (slot & 0xFF) || + size == 4 && slot == (slot & 0xFFFF)) + return; + throw slotOutOfBounds(opcode, slot); + } + + public static void validateSlot(int slot) { + if ((slot & 0xFFFF) != slot) + throw slotOutOfBounds(slot); + } + + public static boolean validateAndIsWideIinc(int slot, int val) { + var ret = false; + if ((slot & 0xFF) != slot) { + validateSlot(slot); + ret = true; + } + if ((byte) val != val) { + if ((short) val != val) { + throw new IllegalArgumentException("cannot encode as S2: ".concat(String.valueOf(val))); + } + ret = true; + } + return ret; + } + + public static void validateRet(Opcode opcode, int slot) { + if (opcode == Opcode.RET && slot == (slot & 0xFF) || + opcode == Opcode.RET_W && slot == (slot & 0xFFFF)) + return; + Objects.requireNonNull(opcode); + throw slotOutOfBounds(opcode, slot); + } + + public static void validateMultiArrayDimensions(int value) { + if (value < 1 || value > 0xFF) + throw new IllegalArgumentException("Not a valid array dimension: ".concat(String.valueOf(value))); + } + public static void validateSipush(int value) { if (value != (short) value) throw new IllegalArgumentException( diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java index 48394d3da96..aa9603b1508 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/CodeImpl.java @@ -55,13 +55,13 @@ public final class CodeImpl case ARRAY_STORE -> ArrayStoreInstruction.of(o); case CONSTANT -> ConstantInstruction.ofIntrinsic(o); case CONVERT -> ConvertInstruction.of(o); - case LOAD -> LoadInstruction.of(o, BytecodeHelpers.intrinsicLoadSlot(o)); + case LOAD -> new AbstractInstruction.UnboundLoadInstruction(o, BytecodeHelpers.intrinsicLoadSlot(o)); case MONITOR -> MonitorInstruction.of(o); case NOP -> NopInstruction.of(); case OPERATOR -> OperatorInstruction.of(o); case RETURN -> ReturnInstruction.of(o); case STACK -> StackInstruction.of(o); - case STORE -> StoreInstruction.of(o, BytecodeHelpers.intrinsicStoreSlot(o)); + case STORE -> new AbstractInstruction.UnboundStoreInstruction(o, BytecodeHelpers.intrinsicStoreSlot(o)); case THROW_EXCEPTION -> ThrowInstruction.of(); default -> throw new AssertionError("invalid opcode: " + o); }; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java b/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java index 301b61241f7..ee312a97dad 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java @@ -506,12 +506,12 @@ public void writeLocalVar(Opcode opcode, int localVar) { } } - public void writeIncrement(int slot, int val) { - Opcode opcode = (slot < 256 && val < 128 && val > -127) - ? IINC - : IINC_W; - writeBytecode(opcode); - if (opcode.isWide()) { + public void writeIncrement(boolean wide, int slot, int val) { + if (wide) { + bytecodesBufWriter.writeU1(RawBytecodeHelper.WIDE); + } + bytecodesBufWriter.writeU1(RawBytecodeHelper.IINC); + if (wide) { bytecodesBufWriter.writeU2(slot); bytecodesBufWriter.writeU2(val); } else { @@ -1216,7 +1216,7 @@ public CodeBuilder idiv() { @Override public CodeBuilder iinc(int slot, int val) { - writeIncrement(slot, val); + writeIncrement(validateAndIsWideIinc(slot, val), slot, val); return this; } diff --git a/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java b/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java index 64994af5cb7..c3b6295853f 100644 --- a/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java +++ b/src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java @@ -379,7 +379,7 @@ private int checkArraySize(String typeName, int elemSize) { throw new IllegalStateException(String.format("Segment size is not a multiple of %d. Size: %d", elemSize, length)); } long arraySize = length / elemSize; - if (arraySize > (Integer.MAX_VALUE - 8)) { //conservative check + if (arraySize > ArraysSupport.SOFT_MAX_ARRAY_LENGTH) { //conservative check throw new IllegalStateException(String.format("Segment is too large to wrap as %s. Size: %d", typeName, length)); } return (int)arraySize; diff --git a/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java b/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java index 1f7df79009f..84e5c50672d 100644 --- a/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java +++ b/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java @@ -1084,5 +1084,8 @@ private static URL checkURL(URL url) { private void resetArchivedStates() { ucp = null; resourceCache = null; + if (!moduleToReader.isEmpty()) { + moduleToReader.clear(); + } } } diff --git a/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java b/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java index 7b0f4d13e40..ab4aa3fb907 100644 --- a/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java +++ b/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java @@ -210,13 +210,6 @@ void appendToClassPathForInstrumentation(String path) { protected Package defineOrCheckPackage(String pn, Manifest man, URL url) { return super.defineOrCheckPackage(pn, man, url); } - - /** - * Called by the VM, during -Xshare:dump - */ - private void resetArchivedStates() { - setClassPath(null); - } } /** diff --git a/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java b/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java index 04d607d06bb..656104e2455 100644 --- a/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java +++ b/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java @@ -33,6 +33,7 @@ import java.lang.module.ModuleReference; import java.lang.module.ResolvedModule; import java.net.URI; +import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; @@ -139,7 +140,6 @@ public static ModuleFinder limitedFinder() { */ private static boolean canUseArchivedBootLayer() { return getProperty("jdk.module.upgrade.path") == null && - getProperty("jdk.module.path") == null && getProperty("jdk.module.patch.0") == null && // --patch-module getProperty("jdk.module.addmods.0") == null && // --add-modules getProperty("jdk.module.limitmods") == null && // --limit-modules @@ -203,7 +203,8 @@ private static ModuleLayer boot2() { SystemModules systemModules = null; ModuleFinder systemModuleFinder; - boolean haveModulePath = (appModulePath != null || upgradeModulePath != null); + boolean haveUpgradeModulePath = (upgradeModulePath != null); + boolean haveModulePath = (appModulePath != null || haveUpgradeModulePath); boolean needResolution = true; boolean mayContainSplitPackages = true; boolean mayContainIncubatorModules = true; @@ -463,7 +464,10 @@ private static ModuleLayer boot2() { // Step 8: CDS dump phase - if (CDS.isDumpingStaticArchive() && !haveModulePath && addModules.isEmpty()) { + if (CDS.isDumpingStaticArchive() + && !haveUpgradeModulePath + && addModules.isEmpty() + && allJrtOrModularJar(cf)) { assert !isPatched; // Archive module graph and maybe boot layer @@ -510,6 +514,29 @@ private static void loadModules(Configuration cf, } } + /** + * Returns true if all modules in the configuration are in the run-time image or + * modular JAR files. + */ + private static boolean allJrtOrModularJar(Configuration cf) { + return !cf.modules().stream() + .map(m -> m.reference().location().orElseThrow()) + .anyMatch(uri -> !uri.getScheme().equalsIgnoreCase("jrt") + && !isJarFile(uri)); + } + + /** + * Returns true if the given URI locates a jar file on the file system. + */ + private static boolean isJarFile(URI uri) { + if ("file".equalsIgnoreCase(uri.getScheme())) { + Path path = Path.of(uri); + return path.toString().endsWith(".jar") && Files.isRegularFile(path); + } else { + return false; + } + } + /** * Returns true if the configuration contains modules with overlapping packages. */ diff --git a/src/java.base/share/classes/jdk/internal/module/ModuleReferences.java b/src/java.base/share/classes/jdk/internal/module/ModuleReferences.java index 346838b47d9..a5ad79eb7c6 100644 --- a/src/java.base/share/classes/jdk/internal/module/ModuleReferences.java +++ b/src/java.base/share/classes/jdk/internal/module/ModuleReferences.java @@ -91,8 +91,19 @@ static ModuleReference newJarModule(ModuleInfo.Attributes attrs, ModulePatcher patcher, Path file) { URI uri = file.toUri(); - Supplier supplier = () -> new JarModuleReader(file, uri); - HashSupplier hasher = (a) -> ModuleHashes.computeHash(supplier, a); + String fileString = file.toString(); + Supplier supplier = new Supplier<>() { + @Override + public ModuleReader get() { + return new JarModuleReader(fileString, uri); + } + }; + HashSupplier hasher = new HashSupplier() { + @Override + public byte[] generate(String algorithm) { + return ModuleHashes.computeHash(supplier, algorithm); + } + }; return newModule(attrs, uri, supplier, patcher, hasher); } @@ -222,9 +233,9 @@ static class JarModuleReader extends SafeCloseModuleReader { private final JarFile jf; private final URI uri; - static JarFile newJarFile(Path path) { + static JarFile newJarFile(String path) { try { - return new JarFile(new File(path.toString()), + return new JarFile(new File(path), true, // verify ZipFile.OPEN_READ, JarFile.runtimeVersion()); @@ -233,7 +244,7 @@ static JarFile newJarFile(Path path) { } } - JarModuleReader(Path path, URI uri) { + JarModuleReader(String path, URI uri) { this.jf = newJarFile(path); this.uri = uri; } diff --git a/src/java.base/share/classes/jdk/internal/vm/vector/VectorSupport.java b/src/java.base/share/classes/jdk/internal/vm/vector/VectorSupport.java index ccfa006b102..5c4040d9128 100644 --- a/src/java.base/share/classes/jdk/internal/vm/vector/VectorSupport.java +++ b/src/java.base/share/classes/jdk/internal/vm/vector/VectorSupport.java @@ -263,6 +263,20 @@ V shuffleToVector(Class> vClass, Class eClass, Class> { + SH apply(SH sh); + } + + @IntrinsicCandidate + public static + > + SH wrapShuffleIndexes(Class eClass, Class shClass, SH sh, int length, + WrapShuffleIndexesOperation defaultImpl) { + assert isNonCapturingLambda(defaultImpl) : defaultImpl; + return defaultImpl.apply(sh); + } + /* ============================================================================ */ public interface IndexOperation, S extends VectorSpecies> { @@ -605,6 +619,23 @@ V rearrangeOp(Class vClass, Class shClass, Class mClass, Cla return defaultImpl.apply(v, sh, m); } + public interface VectorSelectFromOp, + M extends VectorMask> { + V apply(V v1, V v2, M m); + } + + @IntrinsicCandidate + public static + , + M extends VectorMask, + E> + V selectFromOp(Class vClass, Class mClass, Class eClass, + int length, V v1, V v2, M m, + VectorSelectFromOp defaultImpl) { + assert isNonCapturingLambda(defaultImpl) : defaultImpl; + return defaultImpl.apply(v1, v2, m); + } + /* ============================================================================ */ public interface VectorBlendOp, diff --git a/src/java.base/share/classes/sun/security/util/SignatureFileVerifier.java b/src/java.base/share/classes/sun/security/util/SignatureFileVerifier.java index 1e204816bd6..1576388b653 100644 --- a/src/java.base/share/classes/sun/security/util/SignatureFileVerifier.java +++ b/src/java.base/share/classes/sun/security/util/SignatureFileVerifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -36,6 +36,7 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; +import jdk.internal.util.ArraysSupport; import sun.security.action.GetIntegerAction; import sun.security.jca.Providers; import sun.security.pkcs.PKCS7; @@ -87,8 +88,8 @@ public class SignatureFileVerifier { // the maximum allowed size in bytes for the signature-related files public static final int MAX_SIG_FILE_SIZE = initializeMaxSigFileSize(); - // The maximum size of array to allocate. Some VMs reserve some header words in an array. - private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; + // The maximum size of array to allocate + private static final int MAX_ARRAY_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; /** * Create the named SignatureFileVerifier. diff --git a/src/java.base/share/classes/sun/security/validator/CADistrustPolicy.java b/src/java.base/share/classes/sun/security/validator/CADistrustPolicy.java index 0b27a13e17f..17b9e7248c0 100644 --- a/src/java.base/share/classes/sun/security/validator/CADistrustPolicy.java +++ b/src/java.base/share/classes/sun/security/validator/CADistrustPolicy.java @@ -57,7 +57,7 @@ void checkDistrust(String variant, X509Certificate[] chain) /** * Distrust TLS Server certificates anchored by an Entrust root CA and - * issued after October 31, 2024. If enabled, this policy is currently + * issued after November 11, 2024. If enabled, this policy is currently * enforced by the PKIX and SunX509 TrustManager implementations * of the SunJSSE provider implementation. */ diff --git a/src/java.base/share/classes/sun/security/validator/EntrustTLSPolicy.java b/src/java.base/share/classes/sun/security/validator/EntrustTLSPolicy.java index 49b75627fd8..4c4906d8eb3 100644 --- a/src/java.base/share/classes/sun/security/validator/EntrustTLSPolicy.java +++ b/src/java.base/share/classes/sun/security/validator/EntrustTLSPolicy.java @@ -88,8 +88,8 @@ final class EntrustTLSPolicy { // Any TLS Server certificate that is anchored by one of the Entrust // roots above and is issued after this date will be distrusted. - private static final LocalDate OCTOBER_31_2024 = - LocalDate.of(2024, Month.OCTOBER, 31); + private static final LocalDate NOVEMBER_11_2024 = + LocalDate.of(2024, Month.NOVEMBER, 11); /** * This method assumes the eeCert is a TLS Server Cert and chains back to @@ -111,8 +111,8 @@ static void checkDistrust(X509Certificate[] chain) Date notBefore = chain[0].getNotBefore(); LocalDate ldNotBefore = LocalDate.ofInstant(notBefore.toInstant(), ZoneOffset.UTC); - // reject if certificate is issued after October 31, 2024 - checkNotBefore(ldNotBefore, OCTOBER_31_2024, anchor); + // reject if certificate is issued after November 11, 2024 + checkNotBefore(ldNotBefore, NOVEMBER_11_2024, anchor); } } diff --git a/src/java.base/share/conf/security/java.security b/src/java.base/share/conf/security/java.security index 9651ae2d373..9d07cb85a47 100644 --- a/src/java.base/share/conf/security/java.security +++ b/src/java.base/share/conf/security/java.security @@ -1358,7 +1358,7 @@ jdk.sasl.disabledMechanisms= # Distrust after December 31, 2019. # # ENTRUST_TLS : Distrust TLS Server certificates anchored by -# an Entrust root CA and issued after October 31, 2024. +# an Entrust root CA and issued after November 11, 2024. # # Leading and trailing whitespace surrounding each value are ignored. # Unknown values are ignored. If the property is commented out or set to the diff --git a/src/java.base/share/data/cacerts/ssltlsrootecc2022 b/src/java.base/share/data/cacerts/ssltlsrootecc2022 new file mode 100644 index 00000000000..706e6aefb4e --- /dev/null +++ b/src/java.base/share/data/cacerts/ssltlsrootecc2022 @@ -0,0 +1,21 @@ +Owner: CN=SSL.com TLS ECC Root CA 2022, O=SSL Corporation, C=US +Issuer: CN=SSL.com TLS ECC Root CA 2022, O=SSL Corporation, C=US +Serial number: 1403f5abfb378b17405be243b2a5d1c4 +Valid from: Thu Aug 25 16:33:48 GMT 2022 until: Sun Aug 19 16:33:47 GMT 2046 +Signature algorithm name: SHA384withECDSA +Subject Public Key Algorithm: 384-bit EC (secp384r1) key +Version: 3 +-----BEGIN CERTIFICATE----- +MIICOjCCAcCgAwIBAgIQFAP1q/s3ixdAW+JDsqXRxDAKBggqhkjOPQQDAzBOMQsw +CQYDVQQGEwJVUzEYMBYGA1UECgwPU1NMIENvcnBvcmF0aW9uMSUwIwYDVQQDDBxT +U0wuY29tIFRMUyBFQ0MgUm9vdCBDQSAyMDIyMB4XDTIyMDgyNTE2MzM0OFoXDTQ2 +MDgxOTE2MzM0N1owTjELMAkGA1UEBhMCVVMxGDAWBgNVBAoMD1NTTCBDb3Jwb3Jh +dGlvbjElMCMGA1UEAwwcU1NMLmNvbSBUTFMgRUNDIFJvb3QgQ0EgMjAyMjB2MBAG +ByqGSM49AgEGBSuBBAAiA2IABEUpNXP6wrgjzhR9qLFNoFs27iosU8NgCTWyJGYm +acCzldZdkkAZDsalE3D07xJRKF3nzL35PIXBz5SQySvOkkJYWWf9lCcQZIxPBLFN +SeR7T5v15wj4A4j3p8OSSxlUgaNjMGEwDwYDVR0TAQH/BAUwAwEB/zAfBgNVHSME +GDAWgBSJjy+j6CugFFR781a4Jl9nOAuc0DAdBgNVHQ4EFgQUiY8vo+groBRUe/NW +uCZfZzgLnNAwDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMDA2gAMGUCMFXjIlbp +15IkWE8elDIPDAI2wv2sdDJO4fscgIijzPvX6yv/N33w7deedWo1dlJF4AIxAMeN +b0Igj762TVntd00pxCAgRWSGOlDGxK0tk/UYfXLtqc/ErFc2KAhl3zx5Zn6g6g== +-----END CERTIFICATE----- diff --git a/src/java.base/share/data/cacerts/ssltlsrootrsa2022 b/src/java.base/share/data/cacerts/ssltlsrootrsa2022 new file mode 100644 index 00000000000..ad456b0b5f4 --- /dev/null +++ b/src/java.base/share/data/cacerts/ssltlsrootrsa2022 @@ -0,0 +1,39 @@ +Owner: CN=SSL.com TLS RSA Root CA 2022, O=SSL Corporation, C=US +Issuer: CN=SSL.com TLS RSA Root CA 2022, O=SSL Corporation, C=US +Serial number: 6fbedaad73bd0840e28b4dbed4f75b91 +Valid from: Thu Aug 25 16:34:22 GMT 2022 until: Sun Aug 19 16:34:21 GMT 2046 +Signature algorithm name: SHA256withRSA +Subject Public Key Algorithm: 4096-bit RSA key +Version: 3 +-----BEGIN CERTIFICATE----- +MIIFiTCCA3GgAwIBAgIQb77arXO9CEDii02+1PdbkTANBgkqhkiG9w0BAQsFADBO +MQswCQYDVQQGEwJVUzEYMBYGA1UECgwPU1NMIENvcnBvcmF0aW9uMSUwIwYDVQQD +DBxTU0wuY29tIFRMUyBSU0EgUm9vdCBDQSAyMDIyMB4XDTIyMDgyNTE2MzQyMloX +DTQ2MDgxOTE2MzQyMVowTjELMAkGA1UEBhMCVVMxGDAWBgNVBAoMD1NTTCBDb3Jw +b3JhdGlvbjElMCMGA1UEAwwcU1NMLmNvbSBUTFMgUlNBIFJvb3QgQ0EgMjAyMjCC +AiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBANCkCXJPQIgSYT41I57u9nTP +L3tYPc48DRAokC+X94xI2KDYJbFMsBFMF3NQ0CJKY7uB0ylu1bUJPiYYf7ISf5OY +t6/wNr/y7hienDtSxUcZXXTzZGbVXcdotL8bHAajvI9AI7YexoS9UcQbOcGV0ins +S657Lb85/bRi3pZ7QcacoOAGcvvwB5cJOYF0r/c0WRFXCsJbwST0MXMwgsadugL3 +PnxEX4MN8/HdIGkWCVDi1FW24IBydm5MR7d1VVm0U3TZlMZBrViKMWYPHqIbKUBO +L9975hYsLfy/7PO0+r4Y9ptJ1O4Fbtk085zx7AGL0SDGD6C1vBdOSHtRwvzpXGk3 +R2azaPgVKPC506QVzFpPulJwoxJF3ca6TvvC0PeoUidtbnm1jPx7jMEWTO6Af77w +dr5BUxIzrlo4QqvXDz5BjXYHMtWrifZOZ9mxQnUjbvPNQrL8VfVThxc7wDNY8VLS ++YCk8OjwO4s4zKTGkH8PnP2L0aPP2oOnaclQNtVcBdIKQXTbYxE3waWglksejBYS +d66UNHsef8JmAOSqg+qKkK3ONkRN0VHpvB/zagX9wHQfJRlAUW7qglFA35u5CCoG +AtUjHBPW6dvbxrB6y3snm/vg1UYk7RBLY0ulBY+6uB0rpvqR4pJSvezrZ5dtmi2f +gTIFZzL7SAg/2SW4BCUvAgMBAAGjYzBhMA8GA1UdEwEB/wQFMAMBAf8wHwYDVR0j +BBgwFoAU+y437uOEeicuzRk1sTN8/9REQrkwHQYDVR0OBBYEFPsuN+7jhHonLs0Z +NbEzfP/UREK5MA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQsFAAOCAgEAjYlt +hEUY8U+zoO9opMAdrDC8Z2awms22qyIZZtM7QbUQnRC6cm4pJCAcAZli05bg4vsM +QtfhWsSWTVTNj8pDU/0quOr4ZcoBwq1gaAafORpR2eCNJvkLTqVTJXojpBzOCBvf +R4iyrT7gJ4eLSYwfqUdYe5byiB0YrrPRpgqU+tvT5TgKa3kSM/tKWTcWQA673vWJ +DPFs0/dRa1419dvAJuoSc06pkZCmF8NsLzjUo3KUQyxi4U5cMj29TH0ZR6LDSeeW +P4+a0zvkEdiLA9z2tmBVGKaBUfPhqBVq6+AL8BQx1rmMRTqoENjwuSfr98t67wVy +lrXEj5ZzxOhWc5y8aVFjvO9nHEMaX3cZHxj4HCUp+UmZKbaSPaKDN7EgkaibMOlq +bLQjk2UEqxHzDh1TJElTHaE/nUiSEeJ9DU/1172iWD54nR4fK/4huxoTtrEoZP2w +AgDHbICivRZQIA9ygV/MlP+7mea6kMvq+cYMwq7FGc4zoWtcu358NFcXrfA/rs3q +r5nsLFR+jM4uElZI7xc7P0peYNLcdDa8pUNjyw9bowJWCZ4kLOGGgYz+qxcs+sji +Mho6/4UIyYOf8kpIEFR3N+2ivEC+5BB09+Rbu7nzifmPQdjH5FCQNYA+HLhNkNPU +98OwoX6EyneSMSy4kLGCenROmxMmtNVQZlR4rmA= +-----END CERTIFICATE----- diff --git a/src/java.base/unix/native/libjli/java_md_common.c b/src/java.base/unix/native/libjli/java_md_common.c index 511519ae362..453d605f710 100644 --- a/src/java.base/unix/native/libjli/java_md_common.c +++ b/src/java.base/unix/native/libjli/java_md_common.c @@ -243,13 +243,7 @@ JLI_ReportErrorMessage(const char* fmt, ...) { JNIEXPORT void JNICALL JLI_ReportErrorMessageSys(const char* fmt, ...) { va_list vl; - char *emsg; - - /* - * TODO: its safer to use strerror_r but is not available on - * Solaris 8. Until then.... - */ - emsg = strerror(errno); + char *emsg = strerror(errno); if (emsg != NULL) { fprintf(stderr, "%s\n", emsg); } diff --git a/src/java.compiler/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor7.java b/src/java.compiler/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor7.java index 0ca2bb13766..dbdeb3a9506 100644 --- a/src/java.compiler/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor7.java +++ b/src/java.compiler/share/classes/javax/lang/model/util/AbstractAnnotationValueVisitor7.java @@ -37,7 +37,7 @@ * @param the return type of this visitor's methods * @param

    the type of the additional parameter to this visitor's methods. * - * @see AbstractAnnotationValueVisitor6##note_for_subclasses" + * @see AbstractAnnotationValueVisitor6##note_for_subclasses * Compatibility note for subclasses * @see AbstractAnnotationValueVisitor6 * @see AbstractAnnotationValueVisitor8 diff --git a/src/java.compiler/share/classes/javax/lang/model/util/Types.java b/src/java.compiler/share/classes/javax/lang/model/util/Types.java index 266d63178ba..ce83cda4058 100644 --- a/src/java.compiler/share/classes/javax/lang/model/util/Types.java +++ b/src/java.compiler/share/classes/javax/lang/model/util/Types.java @@ -50,6 +50,11 @@ *

    Compatibility Note: Methods may be added to this interface * in future releases of the platform. * + * @apiNote + * In the reference implementation, handling {@linkplain ErrorType + * error types} generally does not cause an {@code + * IllegalArgumentException} from the methods in this interface. + * * @see javax.annotation.processing.ProcessingEnvironment#getTypeUtils * @since 1.6 */ @@ -198,8 +203,11 @@ public interface Types { * * @param t the type to be unboxed * @return the type of an unboxed value of type {@code t} + * * @throws IllegalArgumentException if the given type has no - * unboxing conversion + * unboxing conversion. Only types for the {@linkplain + * java.lang##wrapperClasses wrapper classes} have an + * unboxing conversion. * @jls 5.1.8 Unboxing Conversion */ PrimitiveType unboxedType(TypeMirror t); @@ -268,7 +276,10 @@ public interface Types { * * @param extendsBound the extends (upper) bound, or {@code null} if none * @param superBound the super (lower) bound, or {@code null} if none - * @throws IllegalArgumentException if bounds are not valid + * + * @throws IllegalArgumentException if bounds are not valid. Invalid bounds + * include all types that are not {@linkplain ReferenceType + * reference types}. * @jls 4.5.1 Type Arguments of Parameterized Types */ WildcardType getWildcardType(TypeMirror extendsBound, diff --git a/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m b/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m index 66e0c362318..e74f8ee50fb 100644 --- a/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m +++ b/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m @@ -271,11 +271,13 @@ static int isInAquaSession() { SplashCreateThread(Splash * splash) { pthread_t thr; pthread_attr_t attr; - int rc; int rslt = pthread_attr_init(&attr); if (rslt != 0) return; - rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash); + rslt = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash); + if (rslt != 0) { + fprintf(stderr, "Could not create SplashScreen thread, error number:%d\n", rslt); + } pthread_attr_destroy(&attr); } diff --git a/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c b/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c index 5a008d10a48..e89d813fff4 100644 --- a/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c +++ b/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c @@ -741,7 +741,10 @@ SplashCreateThread(Splash * splash) { int rslt = pthread_attr_init(&attr); if (rslt != 0) return; - pthread_create(&thr, &attr, SplashScreenThread, (void *) splash); + rslt = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash); + if (rslt != 0) { + fprintf(stderr, "Could not create SplashScreen thread, error number:%d\n", rslt); + } pthread_attr_destroy(&attr); } diff --git a/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java b/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java index ed76ce57f94..5f0531c0ff7 100644 --- a/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java +++ b/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -957,6 +957,8 @@ private boolean lockFile(boolean shared) throws SecurityException{ try { Thread.sleep(sleepTime); } catch(InterruptedException e) { + // Don't lose the interrupt. + Thread.currentThread().interrupt(); checkLockFile0ErrorCode(errorCode); return false; } diff --git a/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java b/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java index 4eb29482e29..35ce808c187 100644 --- a/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java +++ b/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java @@ -28,12 +28,13 @@ import com.sun.tools.attach.AttachNotSupportedException; import com.sun.tools.attach.spi.AttachProvider; -import java.io.InputStream; -import java.io.IOException; import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.Files; +import java.util.Optional; import static java.nio.charset.StandardCharsets.UTF_8; @@ -47,13 +48,35 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { // location is the same for all processes, otherwise the tools // will not be able to find all Hotspot processes. // Any changes to this needs to be synchronized with HotSpot. - private static final String tmpdir = "/tmp"; + private static final Path TMPDIR = Path.of("/tmp"); + + private static final Path PROC = Path.of("/proc"); + private static final Path NS_MNT = Path.of("ns/mnt"); + private static final Path NS_PID = Path.of("ns/pid"); + private static final Path SELF = PROC.resolve("self"); + private static final Path STATUS = Path.of("status"); + private static final Path ROOT_TMP = Path.of("root/tmp"); + + private static final Optional SELF_MNT_NS; + + static { + Path nsPath = null; + + try { + nsPath = Files.readSymbolicLink(SELF.resolve(NS_MNT)); + } catch (IOException _) { + // do nothing + } finally { + SELF_MNT_NS = Optional.ofNullable(nsPath); + } + } + String socket_path; + /** * Attaches to the target VM */ - VirtualMachineImpl(AttachProvider provider, String vmid) - throws AttachNotSupportedException, IOException + VirtualMachineImpl(AttachProvider provider, String vmid) throws AttachNotSupportedException, IOException { super(provider, vmid); @@ -64,12 +87,12 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine { } // Try to resolve to the "inner most" pid namespace - int ns_pid = getNamespacePid(pid); + final long ns_pid = getNamespacePid(pid); // Find the socket file. If not found then we attempt to start the // attach mechanism in the target VM by sending it a QUIT signal. // Then we attempt to find the socket file again. - File socket_file = findSocketFile(pid, ns_pid); + final File socket_file = findSocketFile(pid, ns_pid); socket_path = socket_file.getPath(); if (!socket_file.exists()) { // Keep canonical version of File, to delete, in case target process ends and /proc link has gone: @@ -211,49 +234,102 @@ protected void close(long fd) throws IOException { } // Return the socket file for the given process. - private File findSocketFile(int pid, int ns_pid) throws IOException { - String root = findTargetProcessTmpDirectory(pid, ns_pid); - return new File(root, ".java_pid" + ns_pid); + private File findSocketFile(long pid, long ns_pid) throws AttachNotSupportedException, IOException { + return new File(findTargetProcessTmpDirectory(pid, ns_pid), ".java_pid" + ns_pid); } // On Linux a simple handshake is used to start the attach mechanism // if not already started. The client creates a .attach_pid file in the // target VM's working directory (or temp directory), and the SIGQUIT handler // checks for the file. - private File createAttachFile(int pid, int ns_pid) throws IOException { - String fn = ".attach_pid" + ns_pid; - String path = "/proc/" + pid + "/cwd/" + fn; - File f = new File(path); + private File createAttachFile(long pid, long ns_pid) throws AttachNotSupportedException, IOException { + Path fn = Path.of(".attach_pid" + ns_pid); + Path path = PROC.resolve(Path.of(Long.toString(pid), "cwd")).resolve(fn); + File f = new File(path.toString()); try { // Do not canonicalize the file path, or we will fail to attach to a VM in a container. f.createNewFile(); - } catch (IOException x) { - String root = findTargetProcessTmpDirectory(pid, ns_pid); - f = new File(root, fn); + } catch (IOException _) { + f = new File(findTargetProcessTmpDirectory(pid, ns_pid), fn.toString()); f.createNewFile(); } return f; } - private String findTargetProcessTmpDirectory(int pid, int ns_pid) throws IOException { - String root; - if (pid != ns_pid) { - // A process may not exist in the same mount namespace as the caller, e.g. - // if we are trying to attach to a JVM process inside a container. - // Instead, attach relative to the target root filesystem as exposed by - // procfs regardless of namespaces. - String procRootDirectory = "/proc/" + pid + "/root"; - if (!Files.isReadable(Path.of(procRootDirectory))) { - throw new IOException( - String.format("Unable to access root directory %s " + - "of target process %d", procRootDirectory, pid)); + private String findTargetProcessTmpDirectory(long pid, long ns_pid) throws AttachNotSupportedException, IOException { + // We need to handle at least 4 different cases: + // 1. Caller and target processes share PID namespace and root filesystem (host to host or container to + // container with both /tmp mounted between containers). + // 2. Caller and target processes share PID namespace and root filesystem but the target process has elevated + // privileges (host to host). + // 3. Caller and target processes share PID namespace but NOT root filesystem (container to container). + // 4. Caller and target processes share neither PID namespace nor root filesystem (host to container). + + Optional target = ProcessHandle.of(pid); + Optional ph = target; + long nsPid = ns_pid; + Optional prevPidNS = Optional.empty(); + + while (ph.isPresent()) { + final var curPid = ph.get().pid(); + final var procPidPath = PROC.resolve(Long.toString(curPid)); + Optional targetMountNS = Optional.empty(); + + try { + // attempt to read the target's mnt ns id + targetMountNS = Optional.ofNullable(Files.readSymbolicLink(procPidPath.resolve(NS_MNT))); + } catch (IOException _) { + // if we fail to read the target's mnt ns id then we either don't have access or it no longer exists! + if (!Files.exists(procPidPath)) { + throw new IOException(String.format("unable to attach, %s non-existent! process: %d terminated", procPidPath, pid)); + } + // the process still exists, but we don't have privileges to read its procfs } - root = procRootDirectory + "/" + tmpdir; + final var sameMountNS = SELF_MNT_NS.isPresent() && SELF_MNT_NS.equals(targetMountNS); + + if (sameMountNS) { + return TMPDIR.toString(); // we share TMPDIR in common! + } else { + // we could not read the target's mnt ns + final var procPidRootTmp = procPidPath.resolve(ROOT_TMP); + if (Files.isReadable(procPidRootTmp)) { + return procPidRootTmp.toString(); // not in the same mnt ns but tmp is accessible via /proc + } + } + + // let's attempt to obtain the pid ns, best efforts to avoid crossing pid ns boundaries (as with a container) + Optional curPidNS = Optional.empty(); + + try { + // attempt to read the target's pid ns id + curPidNS = Optional.ofNullable(Files.readSymbolicLink(procPidPath.resolve(NS_PID))); + } catch (IOException _) { + // if we fail to read the target's pid ns id then we either don't have access or it no longer exists! + if (!Files.exists(procPidPath)) { + throw new IOException(String.format("unable to attach, %s non-existent! process: %d terminated", procPidPath, pid)); + } + // the process still exists, but we don't have privileges to read its procfs + } + + // recurse "up" the process hierarchy if appropriate. PID 1 cannot have a parent in the same namespace + final var havePidNSes = prevPidNS.isPresent() && curPidNS.isPresent(); + final var ppid = ph.get().parent(); + + if (ppid.isPresent() && (havePidNSes && curPidNS.equals(prevPidNS)) || (!havePidNSes && nsPid > 1)) { + ph = ppid; + nsPid = getNamespacePid(ph.get().pid()); // get the ns pid of the parent + prevPidNS = curPidNS; + } else { + ph = Optional.empty(); + } + } + + if (target.orElseThrow(AttachNotSupportedException::new).isAlive()) { + return TMPDIR.toString(); // fallback... } else { - root = tmpdir; + throw new IOException(String.format("unable to attach, process: %d terminated", pid)); } - return root; } /* @@ -270,13 +346,12 @@ private void writeString(int fd, String s) throws IOException { write(fd, b, 0, 1); } - // Return the inner most namespaced PID if there is one, // otherwise return the original PID. - private int getNamespacePid(int pid) throws AttachNotSupportedException, IOException { + private long getNamespacePid(long pid) throws AttachNotSupportedException, IOException { // Assuming a real procfs sits beneath, reading this doesn't block // nor will it consume a lot of memory. - String statusFile = "/proc/" + pid + "/status"; + final var statusFile = PROC.resolve(Long.toString(pid)).resolve(STATUS).toString(); File f = new File(statusFile); if (!f.exists()) { return pid; // Likely a bad pid, but this is properly handled later. @@ -292,8 +367,7 @@ private int getNamespacePid(int pid) throws AttachNotSupportedException, IOExcep // The last entry represents the PID the JVM "thinks" it is. // Even in non-namespaced pids these entries should be // valid. You could refer to it as the inner most pid. - int ns_pid = Integer.parseInt(parts[parts.length - 1]); - return ns_pid; + return Long.parseLong(parts[parts.length - 1]); } } // Old kernels may not have NSpid field (i.e. 3.10). diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java index 2373f869b0a..6abf9f057b0 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -2352,6 +2352,12 @@ private TypeAnnotationSymbolVisitor(List attributes) { this.attributes = attributes; } + /** + * A supertype_index value of 65535 specifies that the annotation appears on the superclass + * in an extends clause of a class declaration, see JVMS 4.7.20.1 + */ + public static final int SUPERCLASS_INDEX = 65535; + @Override public Void visitClassSymbol(Symbol.ClassSymbol s, Void unused) { ClassType t = (ClassType) s.type; @@ -2361,7 +2367,7 @@ public Void visitClassSymbol(Symbol.ClassSymbol s, Void unused) { interfaces.add(addTypeAnnotations(itf, classExtends(i++))); } t.interfaces_field = interfaces.toList(); - t.supertype_field = addTypeAnnotations(t.supertype_field, classExtends(65535)); + t.supertype_field = addTypeAnnotations(t.supertype_field, classExtends(SUPERCLASS_INDEX)); if (t.typarams_field != null) { t.typarams_field = rewriteTypeParameters( diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/code/StubQueue.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/code/StubQueue.java index d59971b33ec..8d06a257e62 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/code/StubQueue.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/code/StubQueue.java @@ -52,8 +52,8 @@ public class StubQueue extends VMObject { private static CIntegerField queueEndField; private static CIntegerField numberOfStubsField; - // The type of the contained stubs (i.e., InterpreterCodelet, - // ICStub). Must be a subclass of type Stub. + // The type of the contained stubs (i.e., InterpreterCodelet). + // Must be a subclass of type Stub. private Class stubType; static { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractShuffle.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractShuffle.java index d648fd86484..fc39cb6adac 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractShuffle.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/AbstractShuffle.java @@ -133,7 +133,7 @@ public final VectorShuffle checkIndexes() { } @ForceInline - public final VectorShuffle wrapIndexes() { + public final VectorShuffle wrapIndexesTemplate() { Vector shufvec = this.toVector(); VectorMask vecmask = shufvec.compare(VectorOperators.LT, vspecies().zero()); if (vecmask.anyTrue()) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte128Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte128Vector.java index 02a389d08b2..0bc25958a76 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte128Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte128Vector.java @@ -503,7 +503,7 @@ public Byte128Vector selectFrom(Vector v, VectorMask m) { return (Byte128Vector) super.selectFromTemplate((Byte128Vector) v, - (Byte128Mask) m); // specialize + Byte128Mask.class, (Byte128Mask) m); // specialize } @@ -860,6 +860,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Byte128Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Byte128Shuffle.class, this, VLENGTH, + (s) -> ((Byte128Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Byte128Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte256Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte256Vector.java index 4e035b13b5e..639646aa77a 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte256Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte256Vector.java @@ -503,7 +503,7 @@ public Byte256Vector selectFrom(Vector v, VectorMask m) { return (Byte256Vector) super.selectFromTemplate((Byte256Vector) v, - (Byte256Mask) m); // specialize + Byte256Mask.class, (Byte256Mask) m); // specialize } @@ -892,6 +892,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Byte256Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Byte256Shuffle.class, this, VLENGTH, + (s) -> ((Byte256Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Byte256Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte512Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte512Vector.java index 15dd06cdccc..2d8151f6800 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte512Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte512Vector.java @@ -503,7 +503,7 @@ public Byte512Vector selectFrom(Vector v, VectorMask m) { return (Byte512Vector) super.selectFromTemplate((Byte512Vector) v, - (Byte512Mask) m); // specialize + Byte512Mask.class, (Byte512Mask) m); // specialize } @@ -956,6 +956,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Byte512Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Byte512Shuffle.class, this, VLENGTH, + (s) -> ((Byte512Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Byte512Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte64Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte64Vector.java index 6ac9d7a8918..bc8ed7d704d 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte64Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Byte64Vector.java @@ -503,7 +503,7 @@ public Byte64Vector selectFrom(Vector v, VectorMask m) { return (Byte64Vector) super.selectFromTemplate((Byte64Vector) v, - (Byte64Mask) m); // specialize + Byte64Mask.class, (Byte64Mask) m); // specialize } @@ -844,6 +844,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Byte64Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Byte64Shuffle.class, this, VLENGTH, + (s) -> ((Byte64Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Byte64Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteMaxVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteMaxVector.java index ed6e15ca293..597afd8d165 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteMaxVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteMaxVector.java @@ -503,7 +503,7 @@ public ByteMaxVector selectFrom(Vector v, VectorMask m) { return (ByteMaxVector) super.selectFromTemplate((ByteMaxVector) v, - (ByteMaxMask) m); // specialize + ByteMaxMask.class, (ByteMaxMask) m); // specialize } @@ -830,6 +830,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public ByteMaxShuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, ByteMaxShuffle.class, this, VLENGTH, + (s) -> ((ByteMaxShuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public ByteMaxShuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java index 8fae8d71b04..a23bbc7f709 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java @@ -2393,17 +2393,18 @@ ByteVector sliceTemplate(int origin) { */ @Override public abstract - ByteVector rearrange(VectorShuffle m); + ByteVector rearrange(VectorShuffle shuffle); /*package-private*/ @ForceInline final > ByteVector rearrangeTemplate(Class shuffletype, S shuffle) { - shuffle.checkIndexes(); + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, null, byte.class, length(), - this, shuffle, null, + this, ws, null, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); return v1.lane(ei); @@ -2428,17 +2429,14 @@ ByteVector rearrangeTemplate(Class shuffletype, M m) { m.check(masktype, this); - VectorMask valid = shuffle.laneIsValid(); - if (m.andNot(valid).anyTrue()) { - shuffle.checkIndexes(); - throw new AssertionError(); - } + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, masktype, byte.class, length(), - this, shuffle, m, + this, ws, m, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); - return ei < 0 || !m_.laneIsSet(i) ? 0 : v1.lane(ei); + return !m_.laneIsSet(i) ? 0 : v1.lane(ei); })); } @@ -2551,7 +2549,10 @@ byte.class, length(), this, m, /*package-private*/ @ForceInline final ByteVector selectFromTemplate(ByteVector v) { - return v.rearrange(this.toShuffle()); + return (ByteVector)VectorSupport.selectFromOp(getClass(), null, byte.class, + length(), this, v, null, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle())); } /** @@ -2563,9 +2564,15 @@ final ByteVector selectFromTemplate(ByteVector v) { /*package-private*/ @ForceInline - final ByteVector selectFromTemplate(ByteVector v, - AbstractMask m) { - return v.rearrange(this.toShuffle(), m); + final + > + ByteVector selectFromTemplate(ByteVector v, + Class masktype, M m) { + m.check(masktype, this); + return (ByteVector)VectorSupport.selectFromOp(getClass(), masktype, byte.class, + length(), this, v, m, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle(), _m)); } /// Ternary operations diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double128Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double128Vector.java index f2a077604f7..00840026fff 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double128Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double128Vector.java @@ -490,7 +490,7 @@ public Double128Vector selectFrom(Vector v, VectorMask m) { return (Double128Vector) super.selectFromTemplate((Double128Vector) v, - (Double128Mask) m); // specialize + Double128Mask.class, (Double128Mask) m); // specialize } @@ -821,6 +821,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Double128Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Double128Shuffle.class, this, VLENGTH, + (s) -> ((Double128Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Double128Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double256Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double256Vector.java index da9dd421b17..4b42deba738 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double256Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double256Vector.java @@ -490,7 +490,7 @@ public Double256Vector selectFrom(Vector v, VectorMask m) { return (Double256Vector) super.selectFromTemplate((Double256Vector) v, - (Double256Mask) m); // specialize + Double256Mask.class, (Double256Mask) m); // specialize } @@ -825,6 +825,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Double256Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Double256Shuffle.class, this, VLENGTH, + (s) -> ((Double256Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Double256Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double512Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double512Vector.java index d23f09e774b..c188f990c33 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double512Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double512Vector.java @@ -490,7 +490,7 @@ public Double512Vector selectFrom(Vector v, VectorMask m) { return (Double512Vector) super.selectFromTemplate((Double512Vector) v, - (Double512Mask) m); // specialize + Double512Mask.class, (Double512Mask) m); // specialize } @@ -833,6 +833,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Double512Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Double512Shuffle.class, this, VLENGTH, + (s) -> ((Double512Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Double512Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double64Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double64Vector.java index 19bd640f978..032fa1ac277 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double64Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Double64Vector.java @@ -490,7 +490,7 @@ public Double64Vector selectFrom(Vector v, VectorMask m) { return (Double64Vector) super.selectFromTemplate((Double64Vector) v, - (Double64Mask) m); // specialize + Double64Mask.class, (Double64Mask) m); // specialize } @@ -819,6 +819,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Double64Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Double64Shuffle.class, this, VLENGTH, + (s) -> ((Double64Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Double64Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleMaxVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleMaxVector.java index 73f6f2ece5d..7251ec82aa6 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleMaxVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleMaxVector.java @@ -490,7 +490,7 @@ public DoubleMaxVector selectFrom(Vector v, VectorMask m) { return (DoubleMaxVector) super.selectFromTemplate((DoubleMaxVector) v, - (DoubleMaxMask) m); // specialize + DoubleMaxMask.class, (DoubleMaxMask) m); // specialize } @@ -818,6 +818,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public DoubleMaxShuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, DoubleMaxShuffle.class, this, VLENGTH, + (s) -> ((DoubleMaxShuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public DoubleMaxShuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java index 59e67195732..6cc12048d46 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java @@ -2235,17 +2235,18 @@ DoubleVector sliceTemplate(int origin) { */ @Override public abstract - DoubleVector rearrange(VectorShuffle m); + DoubleVector rearrange(VectorShuffle shuffle); /*package-private*/ @ForceInline final > DoubleVector rearrangeTemplate(Class shuffletype, S shuffle) { - shuffle.checkIndexes(); + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, null, double.class, length(), - this, shuffle, null, + this, ws, null, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); return v1.lane(ei); @@ -2270,17 +2271,14 @@ DoubleVector rearrangeTemplate(Class shuffletype, M m) { m.check(masktype, this); - VectorMask valid = shuffle.laneIsValid(); - if (m.andNot(valid).anyTrue()) { - shuffle.checkIndexes(); - throw new AssertionError(); - } + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, masktype, double.class, length(), - this, shuffle, m, + this, ws, m, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); - return ei < 0 || !m_.laneIsSet(i) ? 0 : v1.lane(ei); + return !m_.laneIsSet(i) ? 0 : v1.lane(ei); })); } @@ -2393,7 +2391,10 @@ DoubleVector expandTemplate(Class masktype, M m) { /*package-private*/ @ForceInline final DoubleVector selectFromTemplate(DoubleVector v) { - return v.rearrange(this.toShuffle()); + return (DoubleVector)VectorSupport.selectFromOp(getClass(), null, double.class, + length(), this, v, null, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle())); } /** @@ -2405,9 +2406,15 @@ final DoubleVector selectFromTemplate(DoubleVector v) { /*package-private*/ @ForceInline - final DoubleVector selectFromTemplate(DoubleVector v, - AbstractMask m) { - return v.rearrange(this.toShuffle(), m); + final + > + DoubleVector selectFromTemplate(DoubleVector v, + Class masktype, M m) { + m.check(masktype, this); + return (DoubleVector)VectorSupport.selectFromOp(getClass(), masktype, double.class, + length(), this, v, m, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle(), _m)); } /// Ternary operations diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float128Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float128Vector.java index ae47beca5de..2e016725f81 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float128Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float128Vector.java @@ -490,7 +490,7 @@ public Float128Vector selectFrom(Vector v, VectorMask m) { return (Float128Vector) super.selectFromTemplate((Float128Vector) v, - (Float128Mask) m); // specialize + Float128Mask.class, (Float128Mask) m); // specialize } @@ -825,6 +825,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Float128Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Float128Shuffle.class, this, VLENGTH, + (s) -> ((Float128Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Float128Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float256Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float256Vector.java index d5c0506a542..00e60835883 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float256Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float256Vector.java @@ -490,7 +490,7 @@ public Float256Vector selectFrom(Vector v, VectorMask m) { return (Float256Vector) super.selectFromTemplate((Float256Vector) v, - (Float256Mask) m); // specialize + Float256Mask.class, (Float256Mask) m); // specialize } @@ -833,6 +833,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Float256Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Float256Shuffle.class, this, VLENGTH, + (s) -> ((Float256Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Float256Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float512Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float512Vector.java index 536f7db6946..1f2a792c52c 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float512Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float512Vector.java @@ -490,7 +490,7 @@ public Float512Vector selectFrom(Vector v, VectorMask m) { return (Float512Vector) super.selectFromTemplate((Float512Vector) v, - (Float512Mask) m); // specialize + Float512Mask.class, (Float512Mask) m); // specialize } @@ -849,6 +849,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Float512Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Float512Shuffle.class, this, VLENGTH, + (s) -> ((Float512Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Float512Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float64Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float64Vector.java index 849062c6cb8..6c913ce84a9 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float64Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float64Vector.java @@ -490,7 +490,7 @@ public Float64Vector selectFrom(Vector v, VectorMask m) { return (Float64Vector) super.selectFromTemplate((Float64Vector) v, - (Float64Mask) m); // specialize + Float64Mask.class, (Float64Mask) m); // specialize } @@ -821,6 +821,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Float64Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Float64Shuffle.class, this, VLENGTH, + (s) -> ((Float64Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Float64Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatMaxVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatMaxVector.java index b14797f6788..b9a0a93f912 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatMaxVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatMaxVector.java @@ -490,7 +490,7 @@ public FloatMaxVector selectFrom(Vector v, VectorMask m) { return (FloatMaxVector) super.selectFromTemplate((FloatMaxVector) v, - (FloatMaxMask) m); // specialize + FloatMaxMask.class, (FloatMaxMask) m); // specialize } @@ -818,6 +818,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public FloatMaxShuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, FloatMaxShuffle.class, this, VLENGTH, + (s) -> ((FloatMaxShuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public FloatMaxShuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java index 45427817e3d..b962dc55ce3 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java @@ -2247,17 +2247,18 @@ FloatVector sliceTemplate(int origin) { */ @Override public abstract - FloatVector rearrange(VectorShuffle m); + FloatVector rearrange(VectorShuffle shuffle); /*package-private*/ @ForceInline final > FloatVector rearrangeTemplate(Class shuffletype, S shuffle) { - shuffle.checkIndexes(); + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, null, float.class, length(), - this, shuffle, null, + this, ws, null, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); return v1.lane(ei); @@ -2282,17 +2283,14 @@ FloatVector rearrangeTemplate(Class shuffletype, M m) { m.check(masktype, this); - VectorMask valid = shuffle.laneIsValid(); - if (m.andNot(valid).anyTrue()) { - shuffle.checkIndexes(); - throw new AssertionError(); - } + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, masktype, float.class, length(), - this, shuffle, m, + this, ws, m, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); - return ei < 0 || !m_.laneIsSet(i) ? 0 : v1.lane(ei); + return !m_.laneIsSet(i) ? 0 : v1.lane(ei); })); } @@ -2405,7 +2403,10 @@ float.class, length(), this, m, /*package-private*/ @ForceInline final FloatVector selectFromTemplate(FloatVector v) { - return v.rearrange(this.toShuffle()); + return (FloatVector)VectorSupport.selectFromOp(getClass(), null, float.class, + length(), this, v, null, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle())); } /** @@ -2417,9 +2418,15 @@ final FloatVector selectFromTemplate(FloatVector v) { /*package-private*/ @ForceInline - final FloatVector selectFromTemplate(FloatVector v, - AbstractMask m) { - return v.rearrange(this.toShuffle(), m); + final + > + FloatVector selectFromTemplate(FloatVector v, + Class masktype, M m) { + m.check(masktype, this); + return (FloatVector)VectorSupport.selectFromOp(getClass(), masktype, float.class, + length(), this, v, m, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle(), _m)); } /// Ternary operations diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int128Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int128Vector.java index cd652941fb3..f7135e19cb6 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int128Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int128Vector.java @@ -503,7 +503,7 @@ public Int128Vector selectFrom(Vector v, VectorMask m) { return (Int128Vector) super.selectFromTemplate((Int128Vector) v, - (Int128Mask) m); // specialize + Int128Mask.class, (Int128Mask) m); // specialize } @@ -836,6 +836,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Int128Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Int128Shuffle.class, this, VLENGTH, + (s) -> ((Int128Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Int128Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int256Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int256Vector.java index b76a1035561..474ff974b31 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int256Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int256Vector.java @@ -503,7 +503,7 @@ public Int256Vector selectFrom(Vector v, VectorMask m) { return (Int256Vector) super.selectFromTemplate((Int256Vector) v, - (Int256Mask) m); // specialize + Int256Mask.class, (Int256Mask) m); // specialize } @@ -844,6 +844,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Int256Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Int256Shuffle.class, this, VLENGTH, + (s) -> ((Int256Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Int256Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int512Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int512Vector.java index 3a42c661144..9fec8c0c99f 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int512Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int512Vector.java @@ -503,7 +503,7 @@ public Int512Vector selectFrom(Vector v, VectorMask m) { return (Int512Vector) super.selectFromTemplate((Int512Vector) v, - (Int512Mask) m); // specialize + Int512Mask.class, (Int512Mask) m); // specialize } @@ -860,6 +860,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Int512Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Int512Shuffle.class, this, VLENGTH, + (s) -> ((Int512Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Int512Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int64Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int64Vector.java index 4181e6b4ea3..3b3c0723ee1 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int64Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Int64Vector.java @@ -503,7 +503,7 @@ public Int64Vector selectFrom(Vector v, VectorMask m) { return (Int64Vector) super.selectFromTemplate((Int64Vector) v, - (Int64Mask) m); // specialize + Int64Mask.class, (Int64Mask) m); // specialize } @@ -832,6 +832,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Int64Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Int64Shuffle.class, this, VLENGTH, + (s) -> ((Int64Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Int64Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntMaxVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntMaxVector.java index 785022fcd65..5738cb7a4bc 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntMaxVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntMaxVector.java @@ -503,7 +503,7 @@ public IntMaxVector selectFrom(Vector v, VectorMask m) { return (IntMaxVector) super.selectFromTemplate((IntMaxVector) v, - (IntMaxMask) m); // specialize + IntMaxMask.class, (IntMaxMask) m); // specialize } @@ -841,6 +841,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public IntMaxShuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, IntMaxShuffle.class, this, VLENGTH, + (s) -> ((IntMaxShuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public IntMaxShuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java index 3317e25e73e..16b5ceecba3 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java @@ -2378,17 +2378,18 @@ IntVector sliceTemplate(int origin) { */ @Override public abstract - IntVector rearrange(VectorShuffle m); + IntVector rearrange(VectorShuffle shuffle); /*package-private*/ @ForceInline final > IntVector rearrangeTemplate(Class shuffletype, S shuffle) { - shuffle.checkIndexes(); + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, null, int.class, length(), - this, shuffle, null, + this, ws, null, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); return v1.lane(ei); @@ -2413,17 +2414,14 @@ IntVector rearrangeTemplate(Class shuffletype, M m) { m.check(masktype, this); - VectorMask valid = shuffle.laneIsValid(); - if (m.andNot(valid).anyTrue()) { - shuffle.checkIndexes(); - throw new AssertionError(); - } + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, masktype, int.class, length(), - this, shuffle, m, + this, ws, m, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); - return ei < 0 || !m_.laneIsSet(i) ? 0 : v1.lane(ei); + return !m_.laneIsSet(i) ? 0 : v1.lane(ei); })); } @@ -2536,7 +2534,10 @@ int.class, length(), this, m, /*package-private*/ @ForceInline final IntVector selectFromTemplate(IntVector v) { - return v.rearrange(this.toShuffle()); + return (IntVector)VectorSupport.selectFromOp(getClass(), null, int.class, + length(), this, v, null, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle())); } /** @@ -2548,9 +2549,15 @@ final IntVector selectFromTemplate(IntVector v) { /*package-private*/ @ForceInline - final IntVector selectFromTemplate(IntVector v, - AbstractMask m) { - return v.rearrange(this.toShuffle(), m); + final + > + IntVector selectFromTemplate(IntVector v, + Class masktype, M m) { + m.check(masktype, this); + return (IntVector)VectorSupport.selectFromOp(getClass(), masktype, int.class, + length(), this, v, m, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle(), _m)); } /// Ternary operations diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long128Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long128Vector.java index 302c71bc13b..567789627c6 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long128Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long128Vector.java @@ -493,7 +493,7 @@ public Long128Vector selectFrom(Vector v, VectorMask m) { return (Long128Vector) super.selectFromTemplate((Long128Vector) v, - (Long128Mask) m); // specialize + Long128Mask.class, (Long128Mask) m); // specialize } @@ -822,6 +822,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Long128Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Long128Shuffle.class, this, VLENGTH, + (s) -> ((Long128Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Long128Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long256Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long256Vector.java index 04c51c377e1..5ef0f121464 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long256Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long256Vector.java @@ -493,7 +493,7 @@ public Long256Vector selectFrom(Vector v, VectorMask m) { return (Long256Vector) super.selectFromTemplate((Long256Vector) v, - (Long256Mask) m); // specialize + Long256Mask.class, (Long256Mask) m); // specialize } @@ -826,6 +826,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Long256Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Long256Shuffle.class, this, VLENGTH, + (s) -> ((Long256Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Long256Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long512Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long512Vector.java index fbcd57400d5..acdb471609f 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long512Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long512Vector.java @@ -493,7 +493,7 @@ public Long512Vector selectFrom(Vector v, VectorMask m) { return (Long512Vector) super.selectFromTemplate((Long512Vector) v, - (Long512Mask) m); // specialize + Long512Mask.class, (Long512Mask) m); // specialize } @@ -834,6 +834,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Long512Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Long512Shuffle.class, this, VLENGTH, + (s) -> ((Long512Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Long512Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long64Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long64Vector.java index 3b2e77f1a54..627f7437367 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long64Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Long64Vector.java @@ -493,7 +493,7 @@ public Long64Vector selectFrom(Vector v, VectorMask m) { return (Long64Vector) super.selectFromTemplate((Long64Vector) v, - (Long64Mask) m); // specialize + Long64Mask.class, (Long64Mask) m); // specialize } @@ -820,6 +820,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Long64Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Long64Shuffle.class, this, VLENGTH, + (s) -> ((Long64Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Long64Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongMaxVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongMaxVector.java index cc3641be3d6..aec3bb89fcd 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongMaxVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongMaxVector.java @@ -493,7 +493,7 @@ public LongMaxVector selectFrom(Vector v, VectorMask m) { return (LongMaxVector) super.selectFromTemplate((LongMaxVector) v, - (LongMaxMask) m); // specialize + LongMaxMask.class, (LongMaxMask) m); // specialize } @@ -820,6 +820,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public LongMaxShuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, LongMaxShuffle.class, this, VLENGTH, + (s) -> ((LongMaxShuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public LongMaxShuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java index 9dd3f2eb136..15ac2bc7b7f 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java @@ -2244,17 +2244,18 @@ LongVector sliceTemplate(int origin) { */ @Override public abstract - LongVector rearrange(VectorShuffle m); + LongVector rearrange(VectorShuffle shuffle); /*package-private*/ @ForceInline final > LongVector rearrangeTemplate(Class shuffletype, S shuffle) { - shuffle.checkIndexes(); + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, null, long.class, length(), - this, shuffle, null, + this, ws, null, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); return v1.lane(ei); @@ -2279,17 +2280,14 @@ LongVector rearrangeTemplate(Class shuffletype, M m) { m.check(masktype, this); - VectorMask valid = shuffle.laneIsValid(); - if (m.andNot(valid).anyTrue()) { - shuffle.checkIndexes(); - throw new AssertionError(); - } + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, masktype, long.class, length(), - this, shuffle, m, + this, ws, m, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); - return ei < 0 || !m_.laneIsSet(i) ? 0 : v1.lane(ei); + return !m_.laneIsSet(i) ? 0 : v1.lane(ei); })); } @@ -2402,7 +2400,10 @@ long.class, length(), this, m, /*package-private*/ @ForceInline final LongVector selectFromTemplate(LongVector v) { - return v.rearrange(this.toShuffle()); + return (LongVector)VectorSupport.selectFromOp(getClass(), null, long.class, + length(), this, v, null, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle())); } /** @@ -2414,9 +2415,15 @@ final LongVector selectFromTemplate(LongVector v) { /*package-private*/ @ForceInline - final LongVector selectFromTemplate(LongVector v, - AbstractMask m) { - return v.rearrange(this.toShuffle(), m); + final + > + LongVector selectFromTemplate(LongVector v, + Class masktype, M m) { + m.check(masktype, this); + return (LongVector)VectorSupport.selectFromOp(getClass(), masktype, long.class, + length(), this, v, m, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle(), _m)); } /// Ternary operations diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short128Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short128Vector.java index 7703df9a59a..fe34886512a 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short128Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short128Vector.java @@ -503,7 +503,7 @@ public Short128Vector selectFrom(Vector v, VectorMask m) { return (Short128Vector) super.selectFromTemplate((Short128Vector) v, - (Short128Mask) m); // specialize + Short128Mask.class, (Short128Mask) m); // specialize } @@ -844,6 +844,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Short128Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Short128Shuffle.class, this, VLENGTH, + (s) -> ((Short128Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Short128Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short256Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short256Vector.java index cf845930195..243e24ad26b 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short256Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short256Vector.java @@ -503,7 +503,7 @@ public Short256Vector selectFrom(Vector v, VectorMask m) { return (Short256Vector) super.selectFromTemplate((Short256Vector) v, - (Short256Mask) m); // specialize + Short256Mask.class, (Short256Mask) m); // specialize } @@ -860,6 +860,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Short256Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Short256Shuffle.class, this, VLENGTH, + (s) -> ((Short256Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Short256Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short512Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short512Vector.java index 67a5073df05..41147836089 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short512Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short512Vector.java @@ -503,7 +503,7 @@ public Short512Vector selectFrom(Vector v, VectorMask m) { return (Short512Vector) super.selectFromTemplate((Short512Vector) v, - (Short512Mask) m); // specialize + Short512Mask.class, (Short512Mask) m); // specialize } @@ -892,6 +892,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Short512Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Short512Shuffle.class, this, VLENGTH, + (s) -> ((Short512Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Short512Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short64Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short64Vector.java index 263ee10d907..d80d4c4e2ec 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short64Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Short64Vector.java @@ -503,7 +503,7 @@ public Short64Vector selectFrom(Vector v, VectorMask m) { return (Short64Vector) super.selectFromTemplate((Short64Vector) v, - (Short64Mask) m); // specialize + Short64Mask.class, (Short64Mask) m); // specialize } @@ -836,6 +836,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public Short64Shuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, Short64Shuffle.class, this, VLENGTH, + (s) -> ((Short64Shuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public Short64Shuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortMaxVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortMaxVector.java index 07a2caebef0..799483a6675 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortMaxVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortMaxVector.java @@ -503,7 +503,7 @@ public ShortMaxVector selectFrom(Vector v, VectorMask m) { return (ShortMaxVector) super.selectFromTemplate((ShortMaxVector) v, - (ShortMaxMask) m); // specialize + ShortMaxMask.class, (ShortMaxMask) m); // specialize } @@ -830,6 +830,13 @@ public VectorShuffle cast(VectorSpecies s) { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public ShortMaxShuffle wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, ShortMaxShuffle.class, this, VLENGTH, + (s) -> ((ShortMaxShuffle)(((AbstractShuffle)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public ShortMaxShuffle rearrange(VectorShuffle shuffle) { diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java index ba21e8a9e95..fb0512fd5b9 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java @@ -2394,17 +2394,18 @@ ShortVector sliceTemplate(int origin) { */ @Override public abstract - ShortVector rearrange(VectorShuffle m); + ShortVector rearrange(VectorShuffle shuffle); /*package-private*/ @ForceInline final > ShortVector rearrangeTemplate(Class shuffletype, S shuffle) { - shuffle.checkIndexes(); + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, null, short.class, length(), - this, shuffle, null, + this, ws, null, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); return v1.lane(ei); @@ -2429,17 +2430,14 @@ ShortVector rearrangeTemplate(Class shuffletype, M m) { m.check(masktype, this); - VectorMask valid = shuffle.laneIsValid(); - if (m.andNot(valid).anyTrue()) { - shuffle.checkIndexes(); - throw new AssertionError(); - } + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, masktype, short.class, length(), - this, shuffle, m, + this, ws, m, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); - return ei < 0 || !m_.laneIsSet(i) ? 0 : v1.lane(ei); + return !m_.laneIsSet(i) ? 0 : v1.lane(ei); })); } @@ -2552,7 +2550,10 @@ short.class, length(), this, m, /*package-private*/ @ForceInline final ShortVector selectFromTemplate(ShortVector v) { - return v.rearrange(this.toShuffle()); + return (ShortVector)VectorSupport.selectFromOp(getClass(), null, short.class, + length(), this, v, null, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle())); } /** @@ -2564,9 +2565,15 @@ final ShortVector selectFromTemplate(ShortVector v) { /*package-private*/ @ForceInline - final ShortVector selectFromTemplate(ShortVector v, - AbstractMask m) { - return v.rearrange(this.toShuffle(), m); + final + > + ShortVector selectFromTemplate(ShortVector v, + Class masktype, M m) { + m.check(masktype, this); + return (ShortVector)VectorSupport.selectFromOp(getClass(), masktype, short.class, + length(), this, v, m, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle(), _m)); } /// Ternary operations diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Vector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Vector.java index d34ac79e7c3..fda073f6863 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Vector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Vector.java @@ -2614,17 +2614,14 @@ public abstract VectorMask compare(VectorOperators.Comparison op, * elements of this vector. * * For each lane {@code N} of the shuffle, and for each lane - * source index {@code I=s.laneSource(N)} in the shuffle, + * source index {@code I=s.wrapIndex(s.laneSource(N))} in the shuffle, * the output lane {@code N} obtains the value from * the input vector at lane {@code I}. * * @param s the shuffle controlling lane index selection * @return the rearrangement of the lane elements of this vector - * @throws IndexOutOfBoundsException if there are any exceptional - * source indexes in the shuffle * @see #rearrange(VectorShuffle,VectorMask) * @see #rearrange(VectorShuffle,Vector) - * @see VectorShuffle#laneIsValid() */ public abstract Vector rearrange(VectorShuffle s); @@ -2636,27 +2633,22 @@ public abstract VectorMask compare(VectorOperators.Comparison op, * elements of this vector. * * For each lane {@code N} of the shuffle, and for each lane - * source index {@code I=s.laneSource(N)} in the shuffle, + * source index {@code I=s.wrapIndex(s.laneSource(N))} in the shuffle, * the output lane {@code N} obtains the value from * the input vector at lane {@code I} if the mask is set. * Otherwise the output lane {@code N} is set to zero. * *

    This method returns the value of this pseudocode: *

    {@code
    -     * Vector r = this.rearrange(s.wrapIndexes());
    -     * VectorMask valid = s.laneIsValid();
    -     * if (m.andNot(valid).anyTrue()) throw ...;
    +     * Vector r = this.rearrange(s);
          * return broadcast(0).blend(r, m);
          * }
    * * @param s the shuffle controlling lane index selection * @param m the mask controlling application of the shuffle * @return the rearrangement of the lane elements of this vector - * @throws IndexOutOfBoundsException if there are any exceptional - * source indexes in the shuffle where the mask is set * @see #rearrange(VectorShuffle) * @see #rearrange(VectorShuffle,Vector) - * @see VectorShuffle#laneIsValid() */ public abstract Vector rearrange(VectorShuffle s, VectorMask m); @@ -2747,7 +2739,7 @@ public abstract VectorMask compare(VectorOperators.Comparison op, * this vector. * * For each lane {@code N} of this vector, and for each lane - * value {@code I=this.lane(N)} in this vector, + * value {@code I=wrapIndex(this.lane(N))} in this vector, * the output lane {@code N} obtains the value from * the argument vector at lane {@code I}. * @@ -2760,8 +2752,6 @@ public abstract VectorMask compare(VectorOperators.Comparison op, * * @param v the vector supplying the result values * @return the rearrangement of the lane elements of {@code v} - * @throws IndexOutOfBoundsException if any invalid - * source indexes are found in {@code this} * @see #rearrange(VectorShuffle) */ public abstract Vector selectFrom(Vector v); @@ -2787,9 +2777,6 @@ public abstract VectorMask compare(VectorOperators.Comparison op, * @param v the vector supplying the result values * @param m the mask controlling selection from {@code v} * @return the rearrangement of the lane elements of {@code v} - * @throws IndexOutOfBoundsException if any invalid - * source indexes are found in {@code this}, - * in a lane which is set in the mask * @see #selectFrom(Vector) * @see #rearrange(VectorShuffle,VectorMask) */ diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template index d7562bae475..fcc128ea8c7 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template @@ -2770,17 +2770,18 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> { */ @Override public abstract - $abstractvectortype$ rearrange(VectorShuffle<$Boxtype$> m); + $abstractvectortype$ rearrange(VectorShuffle<$Boxtype$> shuffle); /*package-private*/ @ForceInline final > $abstractvectortype$ rearrangeTemplate(Class shuffletype, S shuffle) { - shuffle.checkIndexes(); + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, null, $type$.class, length(), - this, shuffle, null, + this, ws, null, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); return v1.lane(ei); @@ -2805,17 +2806,14 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> { M m) { m.check(masktype, this); - VectorMask<$Boxtype$> valid = shuffle.laneIsValid(); - if (m.andNot(valid).anyTrue()) { - shuffle.checkIndexes(); - throw new AssertionError(); - } + @SuppressWarnings("unchecked") + S ws = (S) shuffle.wrapIndexes(); return VectorSupport.rearrangeOp( getClass(), shuffletype, masktype, $type$.class, length(), - this, shuffle, m, + this, ws, m, (v1, s_, m_) -> v1.uOp((i, a) -> { int ei = s_.laneSource(i); - return ei < 0 || !m_.laneIsSet(i) ? 0 : v1.lane(ei); + return !m_.laneIsSet(i) ? 0 : v1.lane(ei); })); } @@ -2928,7 +2926,10 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> { /*package-private*/ @ForceInline final $abstractvectortype$ selectFromTemplate($abstractvectortype$ v) { - return v.rearrange(this.toShuffle()); + return ($Type$Vector)VectorSupport.selectFromOp(getClass(), null, $type$.class, + length(), this, v, null, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle())); } /** @@ -2940,9 +2941,15 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> { /*package-private*/ @ForceInline - final $abstractvectortype$ selectFromTemplate($abstractvectortype$ v, - AbstractMask<$Boxtype$> m) { - return v.rearrange(this.toShuffle(), m); + final + > + $abstractvectortype$ selectFromTemplate($abstractvectortype$ v, + Class masktype, M m) { + m.check(masktype, this); + return ($Type$Vector)VectorSupport.selectFromOp(getClass(), masktype, $type$.class, + length(), this, v, m, + (v1, v2, _m) -> + v2.rearrange(v1.toShuffle(), _m)); } /// Ternary operations diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-VectorBits.java.template b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-VectorBits.java.template index 111d4bbefd4..483962b4e06 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-VectorBits.java.template +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-VectorBits.java.template @@ -509,7 +509,7 @@ final class $vectortype$ extends $abstractvectortype$ { VectorMask<$Boxtype$> m) { return ($vectortype$) super.selectFromTemplate(($vectortype$) v, - ($masktype$) m); // specialize + $masktype$.class, ($masktype$) m); // specialize } @@ -1118,6 +1118,13 @@ final class $vectortype$ extends $abstractvectortype$ { return s.shuffleFromArray(shuffleArray, 0).check(s); } + @Override + @ForceInline + public $shuffletype$ wrapIndexes() { + return VectorSupport.wrapShuffleIndexes(ETYPE, $shuffletype$.class, this, VLENGTH, + (s) -> (($shuffletype$)(((AbstractShuffle<$Boxtype$>)(s)).wrapIndexesTemplate()))); + } + @ForceInline @Override public $shuffletype$ rearrange(VectorShuffle<$Boxtype$> shuffle) { diff --git a/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java b/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java index 78a03a4332d..014b420e1a2 100644 --- a/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java +++ b/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Main.java @@ -197,6 +197,7 @@ public ExitException(int errorCode) { private boolean hasExpiringCert = false; private boolean hasExpiringTsaCert = false; private boolean noTimestamp = true; + private boolean hasNonexistentEntries = false; // Expiration date. The value could be null if signed by a trusted cert. private Date expireDate = null; @@ -735,6 +736,7 @@ void verifyJar(String jarName) Map sigMap = new HashMap<>(); Map sigNameMap = new HashMap<>(); Map unparsableSignatures = new HashMap<>(); + Map> entriesInSF = new HashMap<>(); try { jf = new JarFile(jarName, true); @@ -782,6 +784,7 @@ void verifyJar(String jarName) break; } } + entriesInSF.put(alias, sf.getEntries().keySet()); if (!found) { unparsableSignatures.putIfAbsent(alias, String.format( @@ -881,6 +884,9 @@ void verifyJar(String jarName) sb.append('\n'); } } + for (var signed : entriesInSF.values()) { + signed.remove(name); + } } else if (showcerts && !verbose.equals("all")) { // Print no info for unsigned entries when -verbose:all, // to be consistent with old behavior. @@ -1076,6 +1082,13 @@ void verifyJar(String jarName) if (verbose != null) { System.out.println(history); } + var signed = entriesInSF.get(s); + if (!signed.isEmpty()) { + if (verbose != null) { + System.out.println(rb.getString("history.nonexistent.entries") + signed); + } + hasNonexistentEntries = true; + } } else { unparsableSignatures.putIfAbsent(s, String.format( rb.getString("history.nobk"), s)); @@ -1311,6 +1324,9 @@ private void displayMessagesAndResult(boolean isSigning) { } } + if (hasNonexistentEntries) { + warnings.add(rb.getString("nonexistent.entries.found")); + } if (externalFileAttributesDetected) { warnings.add(rb.getString("external.file.attributes.detected")); } diff --git a/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java b/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java index 6a86b72ad1b..810bd107bde 100644 --- a/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java +++ b/src/jdk.jartool/share/classes/sun/security/tools/jarsigner/Resources.java @@ -164,6 +164,7 @@ public class Resources extends java.util.ListResourceBundle { {"history.with.ts", "- Signed by \"%1$s\"\n Digest algorithm: %2$s\n Signature algorithm: %3$s, %4$s\n Timestamped by \"%6$s\" on %5$tc\n Timestamp digest algorithm: %7$s\n Timestamp signature algorithm: %8$s, %9$s"}, {"history.without.ts", "- Signed by \"%1$s\"\n Digest algorithm: %2$s\n Signature algorithm: %3$s, %4$s"}, + {"history.nonexistent.entries", " Warning: nonexistent signed entries: "}, {"history.unparsable", "- Unparsable signature-related file %s"}, {"history.nosf", "- Missing signature-related file META-INF/%s.SF"}, {"history.nobk", "- Missing block file for signature-related file META-INF/%s.SF"}, @@ -178,6 +179,7 @@ public class Resources extends java.util.ListResourceBundle { {"key.bit.disabled", "%d-bit key (disabled)"}, {"key.bit.eccurve.disabled", "%1$d-bit %2$s key (disabled)"}, {"unknown.size", "unknown size"}, + {"nonexistent.entries.found", "This jar contains signed entries for files that do not exist. See the -verbose output for more details."}, {"external.file.attributes.detected", "POSIX file permission and/or symlink attributes detected. These attributes are ignored when signing and are not protected by the signature."}, {"jarsigner.", "jarsigner: "}, diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ElementsTable.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ElementsTable.java index a531a987f0d..0ec72e4ae1c 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ElementsTable.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/ElementsTable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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 @@ -870,10 +870,12 @@ private List getFiles(ModulePackage modpkg, private ModuleSymbol findModuleOfPackageName(String packageName) { Name pack = names.fromString(packageName); - for (ModuleSymbol msym : modules.allModules()) { - PackageSymbol p = syms.getPackage(msym, pack); - if (p != null && !p.members().isEmpty()) { - return msym; + if (modules.modulesInitialized()) { + for (ModuleSymbol msym : modules.allModules()) { + PackageSymbol p = syms.getPackage(msym, pack); + if (p != null && !p.members().isEmpty()) { + return msym; + } } } return null; diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventClassBuilder.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventClassBuilder.java index 52362208484..1373c3ca496 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventClassBuilder.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventClassBuilder.java @@ -84,7 +84,7 @@ private void buildSetMethod(ClassBuilder builder) { int index = 0; for (ValueDescriptor v : fields) { codeBuilder.iload(1); - codeBuilder.ldc(index); + codeBuilder.loadConstant(index); Label notEqual = codeBuilder.newLabel(); codeBuilder.if_icmpne(notEqual); codeBuilder.aload(0); // this diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java index 71dc97d114e..d962a535829 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java @@ -499,7 +499,7 @@ private void makeInstrumented() { // if (!settingsMethod(eventConfiguration.settingX)) goto fail; codeBuilder.aload(0); getEventConfiguration(codeBuilder); - codeBuilder.ldc(index); + codeBuilder.loadConstant(index); invokevirtual(codeBuilder, TYPE_EVENT_CONFIGURATION, METHOD_EVENT_CONFIGURATION_GET_SETTING); MethodTypeDesc mdesc = MethodTypeDesc.ofDescriptor("(" + sd.paramType().descriptorString() + ")Z"); codeBuilder.checkcast(sd.paramType()); diff --git a/test/hotspot/jtreg/ProblemList-Xcomp.txt b/test/hotspot/jtreg/ProblemList-Xcomp.txt index 384374b4f76..cb6bb2b4cca 100644 --- a/test/hotspot/jtreg/ProblemList-Xcomp.txt +++ b/test/hotspot/jtreg/ProblemList-Xcomp.txt @@ -50,6 +50,8 @@ vmTestbase/nsk/jvmti/scenarios/capability/CM03/cm03t001/TestDescription.java 829 vmTestbase/nsk/stress/thread/thread006.java 8321476 linux-all +compiler/cha/TypeProfileFinalMethod.java 8341039 generic-all + gc/arguments/TestNewSizeFlags.java 8299116 macosx-aarch64 runtime/condy/escapeAnalysis/TestEscapeCondy.java 8339694 generic-all diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index aefe09fd3ae..0e75009ac8a 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -43,7 +43,6 @@ # :hotspot_compiler -applications/ctw/modules/java_base.java 8340683 generic-all compiler/ciReplay/TestSAServer.java 8029528 generic-all compiler/compilercontrol/jcmd/ClearDirectivesFileStackTest.java 8225370 generic-all diff --git a/test/hotspot/jtreg/TEST.ROOT b/test/hotspot/jtreg/TEST.ROOT index 74540b6ad45..5ed0227068c 100644 --- a/test/hotspot/jtreg/TEST.ROOT +++ b/test/hotspot/jtreg/TEST.ROOT @@ -81,7 +81,7 @@ requires.properties= \ vm.jvmti \ vm.graal.enabled \ jdk.hasLibgraal \ - vm.libgraal.enabled \ + vm.libgraal.jit \ vm.compiler1.enabled \ vm.compiler2.enabled \ vm.musl \ diff --git a/test/hotspot/jtreg/TEST.groups b/test/hotspot/jtreg/TEST.groups index 101cbe76afd..f54dc79fcfc 100644 --- a/test/hotspot/jtreg/TEST.groups +++ b/test/hotspot/jtreg/TEST.groups @@ -435,8 +435,11 @@ hotspot_cds_only = \ hotspot_appcds_dynamic = \ runtime/cds/appcds/ \ -runtime/cds/appcds/cacheObject \ + -runtime/cds/appcds/complexURI \ -runtime/cds/appcds/customLoader \ -runtime/cds/appcds/dynamicArchive \ + -runtime/cds/appcds/jigsaw/modulepath/ModulePathAndFMG.java \ + -runtime/cds/appcds/jigsaw/modulepath/OptimizeModuleHandlingTest.java \ -runtime/cds/appcds/loaderConstraints/DynamicLoaderConstraintsTest.java \ -runtime/cds/appcds/javaldr/ArrayTest.java \ -runtime/cds/appcds/javaldr/ExceptionDuringDumpAtObjectsInitPhase.java \ @@ -453,6 +456,7 @@ hotspot_appcds_dynamic = \ -runtime/cds/appcds/BadBSM.java \ -runtime/cds/appcds/DumpClassList.java \ -runtime/cds/appcds/DumpClassListWithLF.java \ + -runtime/cds/appcds/DumpRuntimeClassesTest.java \ -runtime/cds/appcds/DumpingWithNoCoops.java \ -runtime/cds/appcds/ExtraSymbols.java \ -runtime/cds/appcds/LambdaContainsOldInf.java \ diff --git a/test/hotspot/jtreg/compiler/c2/aarch64/TestVolatiles.java b/test/hotspot/jtreg/compiler/c2/aarch64/TestVolatiles.java index 23b9321fc35..3f82c3e00b3 100644 --- a/test/hotspot/jtreg/compiler/c2/aarch64/TestVolatiles.java +++ b/test/hotspot/jtreg/compiler/c2/aarch64/TestVolatiles.java @@ -261,20 +261,11 @@ private void checkstore(OutputAnalyzer output, String testType, boolean useCompr }; break; case "G1": - // a card mark volatile barrier should be generated - // before the card mark strb - // - // following the fix for 8225776 the G1 barrier is now - // scheduled out of line after the membar volatile and - // and subsequent return matches = new String[] { "membar_release \\(elided\\)", useCompressedOops ? "stlrw?" : "stlr", "membar_volatile \\(elided\\)", - "ret", - "membar_volatile", - "dmb ish", - "strb" + "ret" }; break; case "Shenandoah": @@ -332,20 +323,11 @@ private void checkcas(OutputAnalyzer output, String testType, boolean useCompres }; break; case "G1": - // a card mark volatile barrier should be generated - // before the card mark strb - // - // following the fix for 8225776 the G1 barrier is now - // scheduled out of line after the membar acquire and - // and subsequent return matches = new String[] { "membar_release \\(elided\\)", useCompressedOops ? "cmpxchgw?_acq" : "cmpxchg_acq", "membar_acquire \\(elided\\)", - "ret", - "membar_volatile", - "dmb ish", - "strb" + "ret" }; break; case "Shenandoah": @@ -418,20 +400,11 @@ private void checkcae(OutputAnalyzer output, String testType, boolean useCompres return; case "G1": - // a card mark volatile barrier should be generated - // before the card mark strb - // - // following the fix for 8225776 the G1 barrier is now - // scheduled out of line after the membar acquire and - // and subsequent return matches = new String[] { "membar_release \\(elided\\)", useCompressedOops ? "cmpxchgw?_acq" : "cmpxchg_acq", "membar_acquire \\(elided\\)", - "ret", - "membar_volatile", - "dmb ish", - "strb" + "ret" }; break; case "Shenandoah": @@ -484,20 +457,11 @@ private void checkgas(OutputAnalyzer output, String testType, boolean useCompres }; break; case "G1": - // a card mark volatile barrier should be generated - // before the card mark strb - // - // following the fix for 8225776 the G1 barrier is now - // scheduled out of line after the membar acquire and - // and subsequent return matches = new String[] { "membar_release \\(elided\\)", useCompressedOops ? "atomic_xchgw?_acq" : "atomic_xchg_acq", "membar_acquire \\(elided\\)", - "ret", - "membar_volatile", - "dmb ish", - "strb" + "ret" }; break; case "Shenandoah": diff --git a/test/hotspot/jtreg/compiler/c2/irTests/scalarReplacement/AllocationMergesTests.java b/test/hotspot/jtreg/compiler/c2/irTests/scalarReplacement/AllocationMergesTests.java index cd3d5329771..69b3cb5274b 100644 --- a/test/hotspot/jtreg/compiler/c2/irTests/scalarReplacement/AllocationMergesTests.java +++ b/test/hotspot/jtreg/compiler/c2/irTests/scalarReplacement/AllocationMergesTests.java @@ -1355,9 +1355,12 @@ int testReReduce(boolean cond, int x, int y) { } @Test - @IR(counts = { IRNode.ALLOC, "1" }) - // The last allocation won't be reduced because it would cause the creation - // of a nested SafePointScalarMergeNode. + // Using G1, all allocations are reduced. + @IR(applyIf = {"UseG1GC", "true"}, failOn = { IRNode.ALLOC }) + // Otherwise, the last allocation won't be reduced because it would cause + // the creation of a nested SafePointScalarMergeNode. This is caused by the + // store barrier corresponding to 'C.other = B'. + @IR(applyIf = {"UseG1GC", "false"}, counts = { IRNode.ALLOC, "1" }) int testReReduce_C2(boolean cond1, int x, int y) { return testReReduce(cond1, x, y); } @DontCompile diff --git a/test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java b/test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java index d0b45333fb8..ecdb415843b 100644 --- a/test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java +++ b/test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java @@ -179,7 +179,9 @@ public static void main(String[] args) throws Exception { // Fails if code heap sizes do not add up pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+SegmentedCodeCache", "-XX:ReservedCodeCacheSize=10M", - "-XX:NonNMethodCodeHeapSize=5M", + // After fixing a round_down issue with large page sizes (JDK-8334564), + // 5M is a bit too small for NonNMethodCodeHeap + "-XX:NonNMethodCodeHeapSize=6M", "-XX:ProfiledCodeHeapSize=5M", "-XX:NonProfiledCodeHeapSize=5M", "-version"); diff --git a/test/hotspot/jtreg/compiler/gcbarriers/TestG1BarrierGeneration.java b/test/hotspot/jtreg/compiler/gcbarriers/TestG1BarrierGeneration.java new file mode 100644 index 00000000000..36ad0bf84a4 --- /dev/null +++ b/test/hotspot/jtreg/compiler/gcbarriers/TestG1BarrierGeneration.java @@ -0,0 +1,639 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.gcbarriers; + +import compiler.lib.ir_framework.*; +import java.lang.invoke.VarHandle; +import java.lang.invoke.MethodHandles; +import java.lang.ref.Reference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.SoftReference; +import java.lang.ref.WeakReference; +import java.util.concurrent.ThreadLocalRandom; +import jdk.test.lib.Asserts; + +/** + * @test + * @summary Test that G1 barriers are generated and optimized as expected. + * @library /test/lib / + * @requires vm.gc.G1 + * @run driver compiler.gcbarriers.TestG1BarrierGeneration + */ + +public class TestG1BarrierGeneration { + static final String PRE_ONLY = "pre"; + static final String POST_ONLY = "post"; + static final String POST_ONLY_NOT_NULL = "post notnull"; + static final String PRE_AND_POST = "pre post"; + static final String PRE_AND_POST_NOT_NULL = "pre post notnull"; + + static class Outer { + Object f; + } + + static class OuterWithVolatileField { + volatile Object f; + } + + static class OuterWithFewFields implements Cloneable { + Object f1; + Object f2; + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + } + + static class OuterWithManyFields implements Cloneable { + Object f1; + Object f2; + Object f3; + Object f4; + Object f5; + Object f6; + Object f7; + Object f8; + Object f9; + Object f10; + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + } + + static final VarHandle fVarHandle; + static { + MethodHandles.Lookup l = MethodHandles.lookup(); + try { + fVarHandle = l.findVarHandle(Outer.class, "f", Object.class); + } catch (Exception e) { + throw new Error(e); + } + } + + public static void main(String[] args) { + TestFramework framework = new TestFramework(); + Scenario[] scenarios = new Scenario[2*2]; + int scenarioIndex = 0; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 2; j++) { + scenarios[scenarioIndex] = + new Scenario(scenarioIndex, + "-XX:CompileCommand=inline,java.lang.ref.*::*", + "-XX:" + (i == 0 ? "-" : "+") + "UseCompressedOops", + "-XX:" + (j == 0 ? "-" : "+") + "ReduceInitialCardMarks"); + scenarioIndex++; + } + } + framework.addScenarios(scenarios); + framework.start(); + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + public static void testStore(Outer o, Object o1) { + o.f = o1; + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_STORE_N_WITH_BARRIER_FLAG, PRE_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + public static void testStoreNull(Outer o) { + o.f = null; + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_STORE_N_WITH_BARRIER_FLAG, PRE_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + public static void testStoreObfuscatedNull(Outer o, Object o1) { + Object o2 = o1; + for (int i = 0; i < 4; i++) { + if ((i % 2) == 0) { + o2 = null; + } + } + // o2 is null here, but this is only known to C2 after applying some + // optimizations (loop unrolling, IGVN). + o.f = o2; + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_AND_POST_NOT_NULL, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, PRE_AND_POST_NOT_NULL, "1"}, + phase = CompilePhase.FINAL_CODE) + public static void testStoreNotNull(Outer o, Object o1) { + if (o1.hashCode() == 42) { + return; + } + o.f = o1; + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_AND_POST, "2"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, PRE_AND_POST, "2"}, + phase = CompilePhase.FINAL_CODE) + public static void testStoreTwice(Outer o, Outer p, Object o1) { + o.f = o1; + p.f = o1; + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + public static void testStoreVolatile(OuterWithVolatileField o, Object o1) { + o.f = o1; + } + + @Test + @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, POST_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"}, + counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, POST_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"}, + failOn = {IRNode.G1_STORE_P}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"}, + failOn = {IRNode.G1_STORE_N, IRNode.G1_ENCODE_P_AND_STORE_N}, + phase = CompilePhase.FINAL_CODE) + public static Outer testStoreOnNewObject(Object o1) { + Outer o = new Outer(); + o.f = o1; + return o; + } + + @Test + @IR(failOn = {IRNode.STORE_P, IRNode.STORE_N}, + phase = CompilePhase.BEFORE_MACRO_EXPANSION) + public static Outer testStoreNullOnNewObject() { + Outer o = new Outer(); + o.f = null; + return o; + } + + @Test + @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, POST_ONLY_NOT_NULL, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"}, + counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, POST_ONLY_NOT_NULL, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"}, + failOn = {IRNode.G1_STORE_P}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"}, + failOn = {IRNode.G1_STORE_N, IRNode.G1_ENCODE_P_AND_STORE_N}, + phase = CompilePhase.FINAL_CODE) + public static Outer testStoreNotNullOnNewObject(Object o1) { + if (o1.hashCode() == 42) { + return null; + } + Outer o = new Outer(); + o.f = o1; + return o; + } + + @Test + @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, POST_ONLY, "2"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"}, + counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, POST_ONLY, "2"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"}, + failOn = {IRNode.G1_STORE_P}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"}, + failOn = {IRNode.G1_STORE_N, IRNode.G1_ENCODE_P_AND_STORE_N}, + phase = CompilePhase.FINAL_CODE) + public static Outer testStoreOnNewObjectInTwoPaths(Object o1, boolean c) { + Outer o; + if (c) { + o = new Outer(); + o.f = o1; + } else { + o = new Outer(); + o.f = o1; + } + return o; + } + + @Run(test = {"testStore", + "testStoreNull", + "testStoreObfuscatedNull", + "testStoreNotNull", + "testStoreTwice", + "testStoreVolatile", + "testStoreOnNewObject", + "testStoreNullOnNewObject", + "testStoreNotNullOnNewObject", + "testStoreOnNewObjectInTwoPaths"}) + public void runStoreTests() { + { + Outer o = new Outer(); + Object o1 = new Object(); + testStore(o, o1); + Asserts.assertEquals(o1, o.f); + } + { + Outer o = new Outer(); + testStoreNull(o); + Asserts.assertNull(o.f); + } + { + Outer o = new Outer(); + Object o1 = new Object(); + testStoreObfuscatedNull(o, o1); + Asserts.assertNull(o.f); + } + { + Outer o = new Outer(); + Object o1 = new Object(); + testStoreNotNull(o, o1); + Asserts.assertEquals(o1, o.f); + } + { + Outer o = new Outer(); + Outer p = new Outer(); + Object o1 = new Object(); + testStoreTwice(o, p, o1); + Asserts.assertEquals(o1, o.f); + Asserts.assertEquals(o1, p.f); + } + { + OuterWithVolatileField o = new OuterWithVolatileField(); + Object o1 = new Object(); + testStoreVolatile(o, o1); + Asserts.assertEquals(o1, o.f); + } + { + Object o1 = new Object(); + Outer o = testStoreOnNewObject(o1); + Asserts.assertEquals(o1, o.f); + } + { + Outer o = testStoreNullOnNewObject(); + Asserts.assertNull(o.f); + } + { + Object o1 = new Object(); + Outer o = testStoreNotNullOnNewObject(o1); + Asserts.assertEquals(o1, o.f); + } + { + Object o1 = new Object(); + Outer o = testStoreOnNewObjectInTwoPaths(o1, ThreadLocalRandom.current().nextBoolean()); + Asserts.assertEquals(o1, o.f); + } + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + public static void testArrayStore(Object[] a, int index, Object o1) { + a[index] = o1; + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_STORE_N_WITH_BARRIER_FLAG, PRE_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + public static void testArrayStoreNull(Object[] a, int index) { + a[index] = null; + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_AND_POST_NOT_NULL, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, PRE_AND_POST_NOT_NULL, "1"}, + phase = CompilePhase.FINAL_CODE) + public static void testArrayStoreNotNull(Object[] a, int index, Object o1) { + if (o1.hashCode() == 42) { + return; + } + a[index] = o1; + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, PRE_AND_POST, "2"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, PRE_AND_POST, "2"}, + phase = CompilePhase.FINAL_CODE) + public static void testArrayStoreTwice(Object[] a, Object[] b, int index, Object o1) { + a[index] = o1; + b[index] = o1; + } + + @Test + @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"}, + failOn = {IRNode.G1_STORE_P}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"}, + failOn = {IRNode.G1_STORE_N, IRNode.G1_ENCODE_P_AND_STORE_N}, + phase = CompilePhase.FINAL_CODE) + public static Object[] testStoreOnNewArray(Object o1) { + Object[] a = new Object[10]; + // The index needs to be concrete for C2 to detect that it is safe to + // remove the pre-barrier. + a[4] = o1; + return a; + } + + @Run(test = {"testArrayStore", + "testArrayStoreNull", + "testArrayStoreNotNull", + "testArrayStoreTwice", + "testStoreOnNewArray"}) + public void runArrayStoreTests() { + { + Object[] a = new Object[10]; + Object o1 = new Object(); + testArrayStore(a, 4, o1); + Asserts.assertEquals(o1, a[4]); + } + { + Object[] a = new Object[10]; + testArrayStoreNull(a, 4); + Asserts.assertNull(a[4]); + } + { + Object[] a = new Object[10]; + Object o1 = new Object(); + testArrayStoreNotNull(a, 4, o1); + Asserts.assertEquals(o1, a[4]); + } + { + Object[] a = new Object[10]; + Object[] b = new Object[10]; + Object o1 = new Object(); + testArrayStoreTwice(a, b, 4, o1); + Asserts.assertEquals(o1, a[4]); + Asserts.assertEquals(o1, b[4]); + } + { + Object o1 = new Object(); + Object[] a = testStoreOnNewArray(o1); + Asserts.assertEquals(o1, a[4]); + } + } + + @Test + public static Object[] testCloneArrayOfObjects(Object[] a) { + Object[] a1 = null; + try { + a1 = a.clone(); + } catch (Exception e) {} + return a1; + } + + @Test + @IR(applyIf = {"ReduceInitialCardMarks", "true"}, + failOn = {IRNode.G1_STORE_P, IRNode.G1_STORE_N, IRNode.G1_ENCODE_P_AND_STORE_N}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"ReduceInitialCardMarks", "false", "UseCompressedOops", "false"}, + counts = {IRNode.G1_STORE_P_WITH_BARRIER_FLAG, POST_ONLY, "2"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIfAnd = {"ReduceInitialCardMarks", "false", "UseCompressedOops", "true"}, + counts = {IRNode.G1_STORE_N_WITH_BARRIER_FLAG, POST_ONLY, "2"}, + phase = CompilePhase.FINAL_CODE) + public static OuterWithFewFields testCloneObjectWithFewFields(OuterWithFewFields o) { + Object o1 = null; + try { + o1 = o.clone(); + } catch (Exception e) {} + return (OuterWithFewFields)o1; + } + + @Test + @IR(applyIf = {"ReduceInitialCardMarks", "true"}, + counts = {IRNode.CALL_OF, "jlong_disjoint_arraycopy", "1"}) + @IR(applyIf = {"ReduceInitialCardMarks", "false"}, + counts = {IRNode.CALL_OF, "G1BarrierSetRuntime::clone", "1"}) + public static OuterWithManyFields testCloneObjectWithManyFields(OuterWithManyFields o) { + Object o1 = null; + try { + o1 = o.clone(); + } catch (Exception e) {} + return (OuterWithManyFields)o1; + } + + @Run(test = {"testCloneArrayOfObjects", + "testCloneObjectWithFewFields", + "testCloneObjectWithManyFields"}) + public void runCloneTests() { + { + Object o1 = new Object(); + Object[] a = new Object[4]; + for (int i = 0; i < 4; i++) { + a[i] = o1; + } + Object[] a1 = testCloneArrayOfObjects(a); + for (int i = 0; i < 4; i++) { + Asserts.assertEquals(o1, a1[i]); + } + } + { + Object a = new Object(); + Object b = new Object(); + OuterWithFewFields o = new OuterWithFewFields(); + o.f1 = a; + o.f2 = b; + OuterWithFewFields o1 = testCloneObjectWithFewFields(o); + Asserts.assertEquals(a, o1.f1); + Asserts.assertEquals(b, o1.f2); + } + { + Object a = new Object(); + Object b = new Object(); + Object c = new Object(); + Object d = new Object(); + Object e = new Object(); + Object f = new Object(); + Object g = new Object(); + Object h = new Object(); + Object i = new Object(); + Object j = new Object(); + OuterWithManyFields o = new OuterWithManyFields(); + o.f1 = a; + o.f2 = b; + o.f3 = c; + o.f4 = d; + o.f5 = e; + o.f6 = f; + o.f7 = g; + o.f8 = h; + o.f9 = i; + o.f10 = j; + OuterWithManyFields o1 = testCloneObjectWithManyFields(o); + Asserts.assertEquals(a, o1.f1); + Asserts.assertEquals(b, o1.f2); + Asserts.assertEquals(c, o1.f3); + Asserts.assertEquals(d, o1.f4); + Asserts.assertEquals(e, o1.f5); + Asserts.assertEquals(f, o1.f6); + Asserts.assertEquals(g, o1.f7); + Asserts.assertEquals(h, o1.f8); + Asserts.assertEquals(i, o1.f9); + Asserts.assertEquals(j, o1.f10); + } + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_COMPARE_AND_EXCHANGE_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_COMPARE_AND_EXCHANGE_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + static Object testCompareAndExchange(Outer o, Object oldVal, Object newVal) { + return fVarHandle.compareAndExchange(o, oldVal, newVal); + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + static boolean testCompareAndSwap(Outer o, Object oldVal, Object newVal) { + return fVarHandle.compareAndSet(o, oldVal, newVal); + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_GET_AND_SET_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_GET_AND_SET_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"}, + phase = CompilePhase.FINAL_CODE) + static Object testGetAndSet(Outer o, Object newVal) { + return fVarHandle.getAndSet(o, newVal); + } + + @Run(test = {"testCompareAndExchange", + "testCompareAndSwap", + "testGetAndSet"}) + public void runAtomicTests() { + { + Outer o = new Outer(); + Object oldVal = new Object(); + o.f = oldVal; + Object newVal = new Object(); + Object oldVal2 = testCompareAndExchange(o, oldVal, newVal); + Asserts.assertEquals(oldVal, oldVal2); + Asserts.assertEquals(o.f, newVal); + } + { + Outer o = new Outer(); + Object oldVal = new Object(); + o.f = oldVal; + Object newVal = new Object(); + boolean b = testCompareAndSwap(o, oldVal, newVal); + Asserts.assertTrue(b); + Asserts.assertEquals(o.f, newVal); + } + { + Outer o = new Outer(); + Object oldVal = new Object(); + o.f = oldVal; + Object newVal = new Object(); + Object oldVal2 = testGetAndSet(o, newVal); + Asserts.assertEquals(oldVal, oldVal2); + Asserts.assertEquals(o.f, newVal); + } + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_LOAD_P_WITH_BARRIER_FLAG, PRE_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_LOAD_N_WITH_BARRIER_FLAG, PRE_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + static Object testLoadSoftReference(SoftReference ref) { + return ref.get(); + } + + @Test + @IR(applyIf = {"UseCompressedOops", "false"}, + counts = {IRNode.G1_LOAD_P_WITH_BARRIER_FLAG, PRE_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + @IR(applyIf = {"UseCompressedOops", "true"}, + counts = {IRNode.G1_LOAD_N_WITH_BARRIER_FLAG, PRE_ONLY, "1"}, + phase = CompilePhase.FINAL_CODE) + static Object testLoadWeakReference(WeakReference ref) { + return ref.get(); + } + + @Run(test = {"testLoadSoftReference", + "testLoadWeakReference"}) + public void runReferenceTests() { + { + Object o1 = new Object(); + SoftReference sref = new SoftReference(o1); + Object o2 = testLoadSoftReference(sref); + Asserts.assertTrue(o2 == o1 || o2 == null); + } + { + Object o1 = new Object(); + WeakReference wref = new WeakReference(o1); + Object o2 = testLoadWeakReference(wref); + Asserts.assertTrue(o2 == o1 || o2 == null); + } + } +} diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java b/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java index 16f56012d3d..a7c61f71050 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java @@ -358,6 +358,11 @@ public class IRNode { beforeMatchingNameRegex(CALL, "Call.*Java"); } + public static final String CALL_OF = COMPOSITE_PREFIX + "CALL_OF" + POSTFIX; + static { + callOfNodes(CALL_OF, "Call.*"); + } + public static final String CALL_OF_METHOD = COMPOSITE_PREFIX + "CALL_OF_METHOD" + POSTFIX; static { callOfNodes(CALL_OF_METHOD, "Call.*Java"); @@ -581,6 +586,92 @@ public class IRNode { vectorNode(FMA_VD, "FmaVD", TYPE_DOUBLE); } + public static final String G1_COMPARE_AND_EXCHANGE_N_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_COMPARE_AND_EXCHANGE_N_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1CompareAndExchangeN\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_COMPARE_AND_EXCHANGE_N_WITH_BARRIER_FLAG, regex); + } + + public static final String G1_COMPARE_AND_EXCHANGE_P_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_COMPARE_AND_EXCHANGE_P_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1CompareAndExchangeP\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_COMPARE_AND_EXCHANGE_P_WITH_BARRIER_FLAG, regex); + } + + public static final String G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1CompareAndSwapN\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, regex); + } + + public static final String G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1CompareAndSwapP\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, regex); + } + + public static final String G1_ENCODE_P_AND_STORE_N = PREFIX + "G1_ENCODE_P_AND_STORE_N" + POSTFIX; + static { + machOnlyNameRegex(G1_ENCODE_P_AND_STORE_N, "g1EncodePAndStoreN"); + } + + public static final String G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1EncodePAndStoreN\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, regex); + } + + public static final String G1_GET_AND_SET_N_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_GET_AND_SET_N_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1GetAndSetN\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_GET_AND_SET_N_WITH_BARRIER_FLAG, regex); + } + + public static final String G1_GET_AND_SET_P_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_GET_AND_SET_P_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1GetAndSetP\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_GET_AND_SET_P_WITH_BARRIER_FLAG, regex); + } + + public static final String G1_LOAD_N = PREFIX + "G1_LOAD_N" + POSTFIX; + static { + machOnlyNameRegex(G1_LOAD_N, "g1LoadN"); + } + + public static final String G1_LOAD_N_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_LOAD_N_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1LoadN\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_LOAD_N_WITH_BARRIER_FLAG, regex); + } + + public static final String G1_LOAD_P_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_LOAD_P_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1LoadP\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_LOAD_P_WITH_BARRIER_FLAG, regex); + } + + public static final String G1_STORE_N = PREFIX + "G1_STORE_N" + POSTFIX; + static { + machOnlyNameRegex(G1_STORE_N, "g1StoreN"); + } + + public static final String G1_STORE_N_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_STORE_N_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1StoreN\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_STORE_N_WITH_BARRIER_FLAG, regex); + } + + public static final String G1_STORE_P = PREFIX + "G1_STORE_P" + POSTFIX; + static { + machOnlyNameRegex(G1_STORE_P, "g1StoreP"); + } + + public static final String G1_STORE_P_WITH_BARRIER_FLAG = COMPOSITE_PREFIX + "G1_STORE_P_WITH_BARRIER_FLAG" + POSTFIX; + static { + String regex = START + "g1StoreP\\S*" + MID + "barrier\\(\\s*" + IS_REPLACED + "\\s*\\)" + END; + machOnly(G1_STORE_P_WITH_BARRIER_FLAG, regex); + } + public static final String IF = PREFIX + "IF" + POSTFIX; static { beforeMatchingNameRegex(IF, "If\\b"); @@ -852,6 +943,11 @@ public class IRNode { vectorNode(LSHIFT_VL, "LShiftVL", TYPE_LONG); } + public static final String MACH_TEMP = PREFIX + "MACH_TEMP" + POSTFIX; + static { + machOnlyNameRegex(MACH_TEMP, "MachTemp"); + } + public static final String MACRO_LOGIC_V = PREFIX + "MACRO_LOGIC_V" + POSTFIX; static { afterBarrierExpansionToBeforeMatching(MACRO_LOGIC_V, "MacroLogicV"); @@ -1148,6 +1244,12 @@ public class IRNode { trapNodes(NULL_CHECK_TRAP, "null_check"); } + public static final String OOPMAP_WITH = COMPOSITE_PREFIX + "OOPMAP_WITH" + POSTFIX; + static { + String regex = "(#\\s*OopMap\\s*\\{.*" + IS_REPLACED + ".*\\})"; + optoOnly(OOPMAP_WITH, regex); + } + public static final String OR_VB = VECTOR_PREFIX + "OR_VB" + POSTFIX; static { vectorNode(OR_VB, "OrV", TYPE_BYTE); diff --git a/test/hotspot/jtreg/compiler/parsing/TestUnsafeArrayAccessWithNullBase.java b/test/hotspot/jtreg/compiler/parsing/TestUnsafeArrayAccessWithNullBase.java new file mode 100644 index 00000000000..28eb4f3c165 --- /dev/null +++ b/test/hotspot/jtreg/compiler/parsing/TestUnsafeArrayAccessWithNullBase.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2024, 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 8320308 + * @summary Unsafe::getShortUnaligned with base null hidden behind CheckCastPP nodes + * @library /test/lib + * @modules java.base/jdk.internal.misc + * @run main/othervm -Xbatch -XX:CompileCommand=quiet -XX:TypeProfileLevel=222 + * -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline + * -XX:CompileCommand=compileonly,compiler.parsing.TestUnsafeArrayAccessWithNullBase::test* + * -XX:-TieredCompilation compiler.parsing.TestUnsafeArrayAccessWithNullBase + * @run main compiler.parsing.TestUnsafeArrayAccessWithNullBase + */ + +package compiler.parsing; + +import java.lang.reflect.*; +import jdk.internal.misc.Unsafe; + +public class TestUnsafeArrayAccessWithNullBase { + + /* + Trigger bug when handling Unsafe.getShortUnaligned with null checks and inlined methods. + The bug appears when the method is incrementally inlined and optimized based on the argument profile information. + + Warmup Phase: By warming up with non-null values, the argument profile for the helper methods records non-null types. + - insert CheckCastPP: speculative=byte[int:>=0] for return of getSmall/getLarge + - insert CheckCastPP: speculative=byte[int:>=0] for argument `Object array` in helperSmall/helperLarge + Trigger Phase: Calling test causes LibraryCallKit::inline_unsafe_access(..) for Unsafe::getShortUnaligned to fail: + Reason: UNSAFE.getShortUnaligned(array, offset) is called with array=null, + but ConP null is now hidden by two CheckCastPP with speculative=byte[int:>=0] in the graph + */ + + private static final Unsafe UNSAFE = Unsafe.getUnsafe(); + + private static final Object byteArray = new byte[1_050_000]; + + public static Object getLarge(boolean useNull) { + return useNull ? null : byteArray; + } + + public static Object getSmall(boolean useNull) { + return useNull ? null : new byte[10]; + } + + // use a helper to delay inlining of UNSAFE.getShortUnaligned + public static int helperLarge(Object array, boolean run) { + // offset >= os::vm_page_size(): LibraryCallKit::classify_unsafe_addr returns Type::AnyPtr + return run ? UNSAFE.getShortUnaligned(array, 1_049_000) : 0; // after warmup CheckCastPP: speculative=byte[int:>=0] + } + + public static int accessLargeArray(boolean useNull, boolean run) { + Object array = getLarge(useNull); // after warmup CheckCastPP: speculative=byte[int:>=0] + // getLarge() ensures null is only visible after helperLarge was (incrementally) inlined + return helperLarge(array, run); + } + + // use a helper to delay inlining of UNSAFE.getShortUnaligned + // warmup adds argument profile information for array: CheckCastPP with type non null + public static int helperSmall(Object array, boolean run) { + // 0 <= offset < os::vm_page_size(): LibraryCallKit::classify_unsafe_addr returns Type::OopPtr + return run ? UNSAFE.getShortUnaligned(array, 1) : 0; // after warmup CheckCastPP: speculative=byte[int:>=0] + } + + public static int accessSmallArray(boolean useNull, boolean run) { + Object array = getSmall(useNull); // after warmup CheckCastPP: speculative=byte[int:>=0] + return helperSmall(array, run); + } + + public static int test1(boolean run) { + return accessLargeArray(true, run); + } + + public static int test2(boolean run) { + return accessSmallArray(true, run); + } + + public static void main(String[] args) { + // Warmup to collect speculative types + for (int i = 0; i < 10_000; i++) { + accessLargeArray(false, true); + accessSmallArray(false, true); + } + + // Trigger Compilation + for (int i = 0; i < 10_000; ++i) { + test1(false); + test2(false); + } + } +} diff --git a/test/hotspot/jtreg/compiler/runtime/safepoints/TestMachTempsAcrossSafepoints.java b/test/hotspot/jtreg/compiler/runtime/safepoints/TestMachTempsAcrossSafepoints.java new file mode 100644 index 00000000000..ecd8f58c5ed --- /dev/null +++ b/test/hotspot/jtreg/compiler/runtime/safepoints/TestMachTempsAcrossSafepoints.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package compiler.runtime.safepoints; + +import compiler.lib.ir_framework.*; +import java.lang.ref.SoftReference; + +/** + * @test + * @summary Test that undefined values generated by MachTemp nodes (in this + * case, derived from G1 barriers) are not included in OopMaps. + * Extracted from java.lang.invoke.LambdaFormEditor::getInCache. + * @key randomness + * @library /test/lib / + * @requires vm.gc.G1 & vm.bits == 64 & vm.opt.final.UseCompressedOops == true + * @run driver compiler.runtime.safepoints.TestMachTempsAcrossSafepoints + */ + +public class TestMachTempsAcrossSafepoints { + + static class RefWithKey extends SoftReference { + final int key; + + public RefWithKey(int key) { + super(new Object()); + this.key = key; + } + + @DontInline + @Override + public boolean equals(Object obj) { + return obj instanceof RefWithKey that && this.key == that.key; + } + } + + public static void main(String[] args) throws Exception { + String inlineCmd = "-XX:CompileCommand=inline,java.lang.ref.SoftReference::get"; + TestFramework.runWithFlags(inlineCmd, "-XX:+StressGCM", "-XX:+StressLCM", "-XX:StressSeed=1"); + TestFramework.runWithFlags(inlineCmd, "-XX:+StressGCM", "-XX:+StressLCM"); + } + + @Test + @IR(counts = {IRNode.G1_LOAD_N, "1"}, phase = CompilePhase.FINAL_CODE) + @IR(counts = {IRNode.MACH_TEMP, ">= 1"}, phase = CompilePhase.FINAL_CODE) + @IR(counts = {IRNode.STATIC_CALL_OF_METHOD, "equals", "2"}) + @IR(failOn = {IRNode.OOPMAP_WITH, "NarrowOop"}) + static private Object test(RefWithKey key, RefWithKey[] refs) { + RefWithKey k = null; + // This loop causes the register allocator to not "rematerialize" all + // MachTemp nodes generated for the reference g1LoadN instruction below. + for (int i = 0; i < refs.length; i++) { + RefWithKey k0 = refs[0]; + if (k0.equals(key)) { + k = k0; + } + } + if (k != null && !key.equals(k)) { + return null; + } + // The MachTemp node implementing the dst TEMP operand in the g1LoadN + // instruction corresponding to k.get() can be scheduled across the + // above call to RefWithKey::equals(), due to an unfortunate interaction + // of inaccurate basic block frequency estimation (emulated in this test + // by randomizing the GCM and LCM heuristics) and call-catch cleanup. + // Since narrow pointer MachTemp nodes are typed as narrow OOPs, this + // causes the oopmap builder to include the MachTemp node definition in + // the RefWithKey::equals() return oopmap. + return (k != null) ? k.get() : null; + } + + @Run(test = "test") + @Warmup(0) + public void run() { + RefWithKey ref = new RefWithKey(42); + test(ref, new RefWithKey[]{ref}); + } +} diff --git a/test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java b/test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java index 0aa16e8479b..20883988347 100644 --- a/test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java +++ b/test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java @@ -38,12 +38,19 @@ * @build EventGeneratorLoop * @run driver TestJcmdWithSideCar */ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.nio.file.Paths; import java.util.Arrays; import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumSet; import java.util.List; +import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import java.util.regex.Pattern; import java.util.stream.Collectors; import jdk.test.lib.Container; import jdk.test.lib.Utils; @@ -60,6 +67,31 @@ public class TestJcmdWithSideCar { private static final long TIME_TO_WAIT_FOR_MAIN_METHOD_START = 50 * 1000; // milliseconds private static final String MAIN_CONTAINER_NAME = "test-container-main"; + private static final String UID = "uid"; + private static final String GID = "gid"; + + private static final Pattern ID_PATTERN = Pattern.compile("uid=(?<" + UID + ">\\d+)\\([^\\)]+\\)\\s+gid=(?<" + GID + ">\\d+).*"); + + private static final Optional USER = ProcessHandle.current().info().user().map( + user -> { + try (var br = new BufferedReader(new InputStreamReader(new ProcessBuilder("id", user).start().getInputStream()))) { + for (final var line : br.lines().toList()) { + final var m = ID_PATTERN.matcher(line); + + if (m.matches()) { + return "--user=" + m.group(UID) + ":" + m.group(GID); + } + } + } catch (IOException e) { + // do nothing... + } + + return null; + } + ); + + private static final String NET_BIND_SERVICE = "--cap-add=NET_BIND_SERVICE"; + public static void main(String[] args) throws Exception { if (!DockerTestUtils.canTestDocker()) { return; @@ -68,24 +100,28 @@ public static void main(String[] args) throws Exception { DockerTestUtils.buildJdkContainerImage(IMAGE_NAME); try { - // Start the loop process in the "main" container, then run test cases - // using a sidecar container. - MainContainer mainContainer = new MainContainer(); - mainContainer.start(); - mainContainer.waitForMainMethodStart(TIME_TO_WAIT_FOR_MAIN_METHOD_START); - - long mainProcPid = testCase01(); - - // Excluding the test case below until JDK-8228850 is fixed - // JDK-8228850: jhsdb jinfo fails with ClassCastException: - // s.j.h.oops.TypeArray cannot be cast to s.j.h.oops.Instance - // mainContainer.assertIsAlive(); - // testCase02(mainProcPid); - - mainContainer.assertIsAlive(); - testCase03(mainProcPid); + for (final boolean elevated : USER.isPresent() ? new Boolean[] { false, true } : new Boolean[] { false }) { + // Start the loop process in the "main" container, then run test cases + // using a sidecar container. + MainContainer mainContainer = new MainContainer(); + mainContainer.start(elevated); + mainContainer.waitForMainMethodStart(TIME_TO_WAIT_FOR_MAIN_METHOD_START); + + for (AttachStrategy attachStrategy : EnumSet.allOf(AttachStrategy.class)) { + long mainProcPid = testCase01(attachStrategy, elevated); + + // Excluding the test case below until JDK-8228850 is fixed + // JDK-8228850: jhsdb jinfo fails with ClassCastException: + // s.j.h.oops.TypeArray cannot be cast to s.j.h.oops.Instance + // mainContainer.assertIsAlive(); + // testCase02(mainProcPid, attachStrategy, elevated); + + mainContainer.assertIsAlive(); + testCase03(mainProcPid, attachStrategy, elevated); + } - mainContainer.waitForAndCheck(TIME_TO_RUN_MAIN_PROCESS * 1000); + mainContainer.waitForAndCheck(TIME_TO_RUN_MAIN_PROCESS * 1000); + } } finally { DockerTestUtils.removeDockerImage(IMAGE_NAME); } @@ -93,21 +129,21 @@ public static void main(String[] args) throws Exception { // Run "jcmd -l" in a sidecar container, find a target process. - private static long testCase01() throws Exception { - OutputAnalyzer out = runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jcmd", "-l") + private static long testCase01(AttachStrategy attachStrategy, boolean elevated) throws Exception { + OutputAnalyzer out = runSideCar(MAIN_CONTAINER_NAME, attachStrategy, elevated, "/jdk/bin/jcmd", "-l") .shouldHaveExitValue(0) .shouldContain("sun.tools.jcmd.JCmd"); long pid = findProcess(out, "EventGeneratorLoop"); if (pid == -1) { - throw new RuntimeException("Could not find specified process"); + throw new RuntimeException(attachStrategy + ": Could not find specified process"); } return pid; } // run jhsdb jinfo (jhsdb uses PTRACE) - private static void testCase02(long pid) throws Exception { - runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jhsdb", "jinfo", "--pid", "" + pid) + private static void testCase02(long pid, AttachStrategy attachStrategy, boolean elevated) throws Exception { + runSideCar(MAIN_CONTAINER_NAME, attachStrategy, elevated, "/jdk/bin/jhsdb", "jinfo", "--pid", "" + pid) .shouldHaveExitValue(0) .shouldContain("Java System Properties") .shouldContain("VM Flags"); @@ -115,11 +151,11 @@ private static void testCase02(long pid) throws Exception { // test jcmd with some commands (help, start JFR recording) // JCMD will use signal mechanism and Unix Socket - private static void testCase03(long pid) throws Exception { - runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jcmd", "" + pid, "help") + private static void testCase03(long pid, AttachStrategy attachStrategy, boolean elevated) throws Exception { + runSideCar(MAIN_CONTAINER_NAME, attachStrategy, elevated, "/jdk/bin/jcmd", "" + pid, "help") .shouldHaveExitValue(0) .shouldContain("VM.version"); - runSideCar(MAIN_CONTAINER_NAME, "/jdk/bin/jcmd", "" + pid, "JFR.start") + runSideCar(MAIN_CONTAINER_NAME, attachStrategy, elevated, "/jdk/bin/jcmd", "" + pid, "JFR.start") .shouldHaveExitValue(0) .shouldContain("Started recording"); } @@ -127,21 +163,36 @@ private static void testCase03(long pid) throws Exception { // JCMD relies on the attach mechanism (com.sun.tools.attach), // which in turn relies on JVMSTAT mechanism, which puts its mapped - // buffers in /tmp directory (hsperfdata_). Thus, in sidecar - // we mount /tmp via --volumes-from from the main container. - private static OutputAnalyzer runSideCar(String mainContainerName, String whatToRun, - String... args) throws Exception { - List cmd = new ArrayList<>(); - String[] command = new String[] { + // buffers in /tmp directory (hsperfdata_). Thus, in the sidecar + // we have two options: + // 1. mount /tmp from the main container using --volumes-from. + // 2. access /tmp from the main container via /proc//root/tmp. + private static OutputAnalyzer runSideCar(String mainContainerName, AttachStrategy attachStrategy, boolean elevated, String whatToRun, String... args) throws Exception { + System.out.println("Attach strategy " + attachStrategy); + + List initialCommands = List.of( Container.ENGINE_COMMAND, "run", "--tty=true", "--rm", "--cap-add=SYS_PTRACE", "--sig-proxy=true", - "--pid=container:" + mainContainerName, - "--volumes-from", mainContainerName, - IMAGE_NAME, whatToRun + "--pid=container:" + mainContainerName + ); + + List attachStrategyCommands = switch (attachStrategy) { + case TMP_MOUNTED_INTO_SIDECAR -> List.of("--volumes-from", mainContainerName); + case ACCESS_TMP_VIA_PROC_ROOT -> List.of(); }; - cmd.addAll(Arrays.asList(command)); + List elevatedOpts = elevated && USER.isPresent() ? List.of(NET_BIND_SERVICE, USER.get()) : Collections.emptyList(); + + List imageAndCommand = List.of( + IMAGE_NAME, whatToRun + ); + + List cmd = new ArrayList<>(); + cmd.addAll(initialCommands); + cmd.addAll(elevatedOpts); + cmd.addAll(attachStrategyCommands); + cmd.addAll(imageAndCommand); cmd.addAll(Arrays.asList(args)); return DockerTestUtils.execute(cmd); } @@ -188,9 +239,15 @@ static class MainContainer { } }; - public Process start() throws Exception { + public Process start(final boolean elevated) throws Exception { // start "main" container (the observee) DockerRunOptions opts = commonDockerOpts("EventGeneratorLoop"); + + if (elevated && USER.isPresent()) { + opts.addDockerOpts(USER.get()); + opts.addDockerOpts(NET_BIND_SERVICE); + } + opts.addDockerOpts("--cap-add=SYS_PTRACE") .addDockerOpts("--name", MAIN_CONTAINER_NAME) .addDockerOpts("--volume", "/tmp") @@ -241,7 +298,7 @@ public void waitForAndCheck(long timeout) throws Exception { try { exitValue = p.exitValue(); } catch(IllegalThreadStateException ex) { - System.out.println("IllegalThreadStateException occured when calling exitValue()"); + System.out.println("IllegalThreadStateException occurred when calling exitValue()"); retryCount--; } } while (exitValue == -1 && retryCount > 0); @@ -253,4 +310,8 @@ public void waitForAndCheck(long timeout) throws Exception { } + private enum AttachStrategy { + TMP_MOUNTED_INTO_SIDECAR, + ACCESS_TMP_VIA_PROC_ROOT + } } diff --git a/test/hotspot/jtreg/gc/z/TestAllocateHeapAtWithHugeTLBFS.java b/test/hotspot/jtreg/gc/z/TestAllocateHeapAtWithHugeTLBFS.java new file mode 100644 index 00000000000..ac647bbd013 --- /dev/null +++ b/test/hotspot/jtreg/gc/z/TestAllocateHeapAtWithHugeTLBFS.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package gc.z; + +/* + * @test TestAllocateHeapAtWithHugeTLBFS + * @requires vm.gc.ZGenerational & os.family == "linux" + * @summary Test ZGC with -XX:AllocateHeapAt and -XX:+UseLargePages + * @library /test/lib + * @run driver gc.z.TestAllocateHeapAtWithHugeTLBFS true + * @run driver gc.z.TestAllocateHeapAtWithHugeTLBFS false + */ + +import jdk.test.lib.process.ProcessTools; +import jtreg.SkippedException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.Path; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.Scanner; + +public class TestAllocateHeapAtWithHugeTLBFS { + static String find_hugetlbfs_mountpoint() { + Pattern pat = Pattern.compile("\\d+ \\d+ \\d+:\\d+ \\S+ (\\S+) [^-]*- hugetlbfs (.+)"); + try (Scanner scanner = new Scanner(new File("/proc/self/mountinfo"))) { + while (scanner.hasNextLine()) { + final Matcher mat = pat.matcher(scanner.nextLine()); + if (mat.matches() && mat.group(2).contains("pagesize=2M")) { + final Path path = Paths.get(mat.group(1)); + if (Files.isReadable(path) && + Files.isWritable(path) && + Files.isExecutable(path)) { + // Found a usable mount point. + return path.toString(); + } + } + } + } catch (FileNotFoundException e) { + System.out.println("Could not open /proc/self/mountinfo"); + } + return null; + } + public static void main(String[] args) throws Exception { + final boolean exists = Boolean.parseBoolean(args[0]); + final String directory = exists ? find_hugetlbfs_mountpoint() + : "non-existing-directory"; + if (directory == null) { + throw new SkippedException("No valid hugetlbfs mount point found"); + } + final String heapBackingFile = "Heap Backing File: " + directory; + final String failedToCreateFile = "Failed to create file " + directory; + + ProcessTools.executeTestJava( + "-XX:+UseZGC", + "-XX:+ZGenerational", + "-Xlog:gc*", + "-Xms32M", + "-Xmx32M", + "-XX:+UseLargePages", + "-XX:AllocateHeapAt=" + directory, + "-version") + .shouldContain(exists ? heapBackingFile : failedToCreateFile) + .shouldNotContain(exists ? failedToCreateFile : heapBackingFile) + .shouldHaveExitValue(exists ? 0 : 1); + } +} diff --git a/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java b/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java index fcf48a7a2d7..01b051af8e5 100644 --- a/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java +++ b/test/hotspot/jtreg/runtime/Unsafe/InternalErrorTest.java @@ -147,7 +147,8 @@ public static void test(MappedByteBuffer buffer, Unsafe unsafe, long mapAddr, lo break; case 1: // testing Unsafe.copySwapMemory, trying to access next page after truncation. - unsafe.copySwapMemory(null, mapAddr + pageSize, new byte[4000], 16, 2000, 2); + int destOffset = Unsafe.ARRAY_BYTE_BASE_OFFSET; + unsafe.copySwapMemory(null, mapAddr + pageSize, new byte[4000], destOffset, 2000, 2); break; case 2: // testing Unsafe.copySwapMemory, trying to access next page after truncation. diff --git a/test/hotspot/jtreg/runtime/cds/appcds/DumpRuntimeClassesTest.java b/test/hotspot/jtreg/runtime/cds/appcds/DumpRuntimeClassesTest.java new file mode 100644 index 00000000000..2e530a8d6dd --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/DumpRuntimeClassesTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024, 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 + * @summary Classes used by CDS at runtime should be in the archived + * @bug 8324259 + * @requires vm.cds + * @library /test/lib + * @compile test-classes/Hello.java + * @run driver DumpRuntimeClassesTest + */ + +import jdk.test.lib.cds.CDSOptions; +import jdk.test.lib.cds.CDSTestUtils; + +public class DumpRuntimeClassesTest { + public static void main(String[] args) throws Exception { + // build The app + String appClass = "Hello"; + String classList = "hello.classlist"; + String archiveName = "hello.jsa"; + JarBuilder.build("hello", appClass); + String appJar = TestCommon.getTestJar("hello.jar"); + + // Dump class list + CDSTestUtils.dumpClassList(classList, "-cp", appJar, appClass); + + // Dump archive + CDSOptions opts = (new CDSOptions()) + .addPrefix("-cp", appJar, "-XX:SharedClassListFile=" + classList) + .setArchiveName(archiveName); + CDSTestUtils.createArchive(opts); + + // Run with archive and ensure all the classes used were in the archive + CDSOptions runOpts = (new CDSOptions()) + .addPrefix("-cp", appJar, "-Xlog:class+load,cds=debug") + .setArchiveName(archiveName) + .setUseVersion(false) + .addSuffix(appClass); + CDSTestUtils.runWithArchive(runOpts) + .shouldNotContain("source: jrt:/java.base"); + } +} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/complexURI/ComplexURITest.java b/test/hotspot/jtreg/runtime/cds/appcds/complexURI/ComplexURITest.java new file mode 100644 index 00000000000..409e37e10a1 --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/complexURI/ComplexURITest.java @@ -0,0 +1,167 @@ +/* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024 JetBrains s.r.o. + * 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 + * @summary Verifies that CDS works with jar located in directories + * with names that need escaping + * @bug 8339460 + * @requires vm.cds + * @requires vm.cds.custom.loaders + * @requires vm.flagless + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds + * @compile mypackage/Main.java mypackage/Another.java + * @run main/othervm ComplexURITest + */ + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.Platform; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; + +public class ComplexURITest { + final static String moduleName = "mymodule"; + + public static void main(String[] args) throws Exception { + System.setProperty("test.noclasspath", "true"); + String jarFile = JarBuilder.build(moduleName, "mypackage/Main", "mypackage/Another"); + + Path subDir = Path.of(".", "dir with space"); + Files.createDirectory(subDir); + Path newJarFilePath = subDir.resolve(moduleName + ".jar"); + Files.move(Path.of(jarFile), newJarFilePath); + jarFile = newJarFilePath.toString(); + + final String listFileName = "test-classlist.txt"; + final String staticArchiveName = "test-static.jsa"; + final String dynamicArchiveName = "test-dynamic.jsa"; + + // Verify static archive creation and use + File fileList = new File(listFileName); + delete(fileList.toPath()); + File staticArchive = new File(staticArchiveName); + delete(staticArchive.toPath()); + + createClassList(jarFile, listFileName); + if (!fileList.exists()) { + throw new RuntimeException("No class list created at " + fileList); + } + + createArchive(jarFile, listFileName, staticArchiveName); + if (!staticArchive.exists()) { + throw new RuntimeException("No shared classes archive created at " + staticArchive); + } + + useArchive(jarFile, staticArchiveName); + + // Verify dynamic archive creation and use + File dynamicArchive = new File(dynamicArchiveName); + delete(dynamicArchive.toPath()); + + createDynamicArchive(jarFile, dynamicArchiveName); + if (!dynamicArchive.exists()) { + throw new RuntimeException("No dynamic archive created at " + dynamicArchive); + } + + testDynamicArchive(jarFile, dynamicArchiveName); + } + + private static void delete(Path path) throws Exception { + if (Files.exists(path)) { + if (Platform.isWindows()) { + Files.setAttribute(path, "dos:readonly", false); + } + Files.delete(path); + } + } + + private static void createClassList(String jarFile, String list) throws Exception { + String[] launchArgs = { + "-XX:DumpLoadedClassList=" + list, + "--module-path", + jarFile, + "--module", + moduleName + "/mypackage.Main"}; + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(launchArgs); + OutputAnalyzer output = TestCommon.executeAndLog(pb, "create-list"); + output.shouldHaveExitValue(0); + } + + private static void createArchive(String jarFile, String list, String archive) throws Exception { + String[] launchArgs = { + "-Xshare:dump", + "-XX:SharedClassListFile=" + list, + "-XX:SharedArchiveFile=" + archive, + "--module-path", + jarFile, + "--module", + moduleName + "/mypackage.Main"}; + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(launchArgs); + OutputAnalyzer output = TestCommon.executeAndLog(pb, "dump-archive"); + output.shouldHaveExitValue(0); + } + + private static void useArchive(String jarFile, String archive) throws Exception { + String[] launchArgs = { + "-Xshare:on", + "-XX:SharedArchiveFile=" + archive, + "--module-path", + jarFile, + "--module", + moduleName + "/mypackage.Main"}; + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(launchArgs); + OutputAnalyzer output = TestCommon.executeAndLog(pb, "use-archive"); + output.shouldHaveExitValue(0); + } + + private static void createDynamicArchive(String jarFile, String archive) throws Exception { + String[] launchArgs = { + "-XX:ArchiveClassesAtExit=" + archive, + "--module-path", + jarFile, + "--module", + moduleName + "/mypackage.Main"}; + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(launchArgs); + OutputAnalyzer output = TestCommon.executeAndLog(pb, "dynamic-archive"); + output.shouldHaveExitValue(0); + } + + private static void testDynamicArchive(String jarFile, String archive) throws Exception { + String[] launchArgs = { + "-XX:SharedArchiveFile=" + archive, + "-XX:+PrintSharedArchiveAndExit", + "--module-path", + jarFile, + "--module", + moduleName + "/mypackage.Main"}; + ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(launchArgs); + OutputAnalyzer output = TestCommon.executeAndLog(pb, "dynamic-archive"); + output.shouldHaveExitValue(0); + output.shouldContain("archive is valid"); + output.shouldContain(": mypackage.Main app_loader"); + output.shouldContain(": mypackage.Another unregistered_loader"); + } +} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/complexURI/mypackage/Another.java b/test/hotspot/jtreg/runtime/cds/appcds/complexURI/mypackage/Another.java new file mode 100644 index 00000000000..106dfd4904c --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/complexURI/mypackage/Another.java @@ -0,0 +1,27 @@ +/* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024 JetBrains s.r.o. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package mypackage; + +public class Another { +} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/complexURI/mypackage/Main.java b/test/hotspot/jtreg/runtime/cds/appcds/complexURI/mypackage/Main.java new file mode 100644 index 00000000000..fdb79e895d2 --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/complexURI/mypackage/Main.java @@ -0,0 +1,37 @@ +/* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024 JetBrains s.r.o. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package mypackage; + +import java.net.URL; +import java.net.URLClassLoader; + +public class Main { + public static void main(String[] args) throws Exception { + URL url1 = Main.class.getProtectionDomain().getCodeSource().getLocation(); + System.out.println("Will load Another from " + url1); + ClassLoader cl = URLClassLoader.newInstance(new URL[] { url1 }, null); + var anotherClass = cl.loadClass("mypackage.Another"); + System.out.println("Class " + anotherClass + " loaded successfully"); + } +} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/MainModuleOnly.java b/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/MainModuleOnly.java index 0dd4af2e450..e74229869ed 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/MainModuleOnly.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/MainModuleOnly.java @@ -213,8 +213,10 @@ public static void doTest(String topArchiveName) throws Exception { "-cp", destJar.toString(), "--module-path", MODS_DIR.toString(), "-m", TEST_MODULE1 + "/" + MAIN_CLASS) - .assertAbnormalExit(output -> { - output.shouldMatch("Error: non-empty directory.*com.simple"); + // After JDK-8328313, non-empty module path directory won't be included + // in the shared paths table. + .assertNormalExit(output -> { + output.shouldNotMatch("Error: non-empty directory.*com.simple"); }); // test module path with very long length diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/MainModuleOnly.java b/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/MainModuleOnly.java index 50191b91e1e..ac9bb5adc00 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/MainModuleOnly.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/MainModuleOnly.java @@ -194,8 +194,10 @@ public static void main(String... args) throws Exception { output = TestCommon.createArchive(destJar.toString(), appClasses, "--module-path", MODS_DIR.toString(), "-m", mainModule); - output.shouldHaveExitValue(1) - .shouldMatch("Error: non-empty directory.*com.simple"); + // After JDK-8328313, non-empty module path directory won't be included + // in the shared paths table. + output.shouldHaveExitValue(0) + .shouldNotMatch("Error: non-empty directory.*com.simple"); // test module path with very long length // diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/ModulePathAndFMG.java b/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/ModulePathAndFMG.java new file mode 100644 index 00000000000..fe777142046 --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/ModulePathAndFMG.java @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2024, 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 8328313 + * @requires vm.cds & !vm.graal.enabled & vm.cds.write.archived.java.heap + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds + * @run driver ModulePathAndFMG + * @summary test module path changes for full module graph handling. + * + */ + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; + +import jdk.test.lib.cds.CDSTestUtils; +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class ModulePathAndFMG { + private static final String JAVA_HOME = System.getProperty("java.home"); + + private static final Path USER_DIR = Paths.get(CDSTestUtils.getOutputDir()); + + private static final String TEST_SRC = System.getProperty("test.src"); + + private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); + private static final Path MODS_DIR = Paths.get("mody"); + private static final Path JMOD_DIR = Paths.get("jmod_dir"); + + // the module name of the test module + private static final String MAIN_MODULE = "com.bars"; + private static final String TEST_MODULE = "com.foos"; + private static final String DUP_MODULE = "com.foos3"; + + // the module main class + private static final String MAIN_CLASS = "com.bars.Main"; + private static final String TEST_CLASS = "com.foos.Test"; + + private static String PATH_LIBS = "modylibs"; + private static String DUP_LIBS = "duplibs"; + private static Path libsDir = null; + private static Path dupDir = null; + private static Path jmodDir = null; + private static Path mainJar = null; + private static Path testJar = null; + private static Path dupJar = null; + private static Path badJar = null; + + private static String CLASS_FOUND_MESSAGE = "com.foos.Test found"; + private static String CLASS_NOT_FOUND_MESSAGE = "java.lang.ClassNotFoundException: com.foos.Test"; + private static String FIND_EXCEPTION_MESSAGE = "java.lang.module.FindException: Module com.foos not found, required by com.bars"; + private static String MODULE_NOT_RECOGNIZED = "Module format not recognized:.*modylibs.*com.bars.JAR"; + private static String OPTIMIZE_ENABLED = "] optimized module handling: enabled"; + private static String OPTIMIZE_DISABLED = "] optimized module handling: disabled"; + private static String FMG_ENABLED = "] full module graph: enabled"; + private static String FMG_DISABLED = "] full module graph: disabled"; + private static String MAIN_FROM_JAR = "class,load.*com.bars.Main.*[.]jar"; + private static String MAIN_FROM_CDS = "class,load.*com.bars.Main.*shared objects file"; + private static String MAIN_FROM_MODULE = "class,load.*com.bars.Main.*mody/com.bars"; + private static String TEST_FROM_JAR = "class,load.*com.foos.Test.*[.]jar"; + private static String TEST_FROM_CDS = "class,load.*com.foos.Test.*shared objects file"; + private static String MAP_FAILED = "Unable to use shared archive"; + private static String PATH_SEPARATOR = File.pathSeparator; + private static String appClasses[] = {MAIN_CLASS, TEST_CLASS}; + private static String prefix[] = {"-Djava.class.path=", "-Xlog:cds,class+load,class+path=info"}; + + public static void buildTestModule() throws Exception { + + // javac -d mods/$TESTMODULE src/$TESTMODULE/** + JarBuilder.compileModule(SRC_DIR.resolve(TEST_MODULE), + MODS_DIR.resolve(TEST_MODULE), + null); + + // javac -d mods/$TESTMODULE --module-path MOD_DIR src/$TESTMODULE/** + JarBuilder.compileModule(SRC_DIR.resolve(MAIN_MODULE), + MODS_DIR.resolve(MAIN_MODULE), + MODS_DIR.toString()); + + libsDir = Files.createTempDirectory(USER_DIR, PATH_LIBS); + mainJar = libsDir.resolve(MAIN_MODULE + ".jar"); + testJar = libsDir.resolve(TEST_MODULE + ".jar"); + + // modylibs contains both modules com.foos.jar, com.bars.jar + // build com.foos.jar + String classes = MODS_DIR.resolve(TEST_MODULE).toString(); + JarBuilder.createModularJar(testJar.toString(), classes, TEST_CLASS); + + // build com.bars.jar + classes = MODS_DIR.resolve(MAIN_MODULE).toString(); + JarBuilder.createModularJar(mainJar.toString(), classes, MAIN_CLASS); + + dupDir = Files.createTempDirectory(USER_DIR, DUP_LIBS); + dupJar = dupDir.resolve(DUP_MODULE + ".jar"); + Files.copy(testJar, dupJar, StandardCopyOption.REPLACE_EXISTING); + + badJar = libsDir.resolve(MAIN_MODULE + ".JAR"); + Files.copy(mainJar, badJar, StandardCopyOption.REPLACE_EXISTING); + } + + public static void buildJmod() throws Exception { + Path jmod = Paths.get(JAVA_HOME, "bin", "jmod"); + jmodDir = Files.createDirectory(Paths.get(USER_DIR.toString() + File.separator + JMOD_DIR.toString())); + OutputAnalyzer output = ProcessTools.executeProcess(jmod.toString(), + "create", + "--class-path", Paths.get(USER_DIR.toString(), MODS_DIR.toString(), TEST_MODULE).toString(), + "--module-version", "1.0", + "--main-class", TEST_CLASS, + jmodDir.toString() + File.separator + TEST_MODULE + ".jmod"); + output.shouldHaveExitValue(0); + } + + public static void main(String... args) throws Exception { + runWithModulePath(); + runWithExplodedModule(); + runWithJmodAndBadJar(); + } + + private static void tty(String... args) { + for (String s : args) { + System.out.print(s + " "); + } + System.out.print("\n"); + } + + public static void runWithModulePath() throws Exception { + // compile the modules and create the modular jar files + buildTestModule(); + // create an archive with the classes in the modules built in the + // previous step + OutputAnalyzer output = TestCommon.createArchive( + null, appClasses, + "--module-path", + libsDir.toString(), + "-m", MAIN_MODULE); + TestCommon.checkDump(output); + + tty("1. run with CDS on, with module path same as dump time"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + libsDir.toString(), // --module-path + MAIN_MODULE) // -m + .assertNormalExit(out -> { + out.shouldNotContain(OPTIMIZE_DISABLED) + .shouldContain(OPTIMIZE_ENABLED) + .shouldNotContain(FMG_DISABLED) + .shouldContain(FMG_ENABLED) + .shouldMatch(MAIN_FROM_CDS) // archived Main class is for module only + .shouldContain(CLASS_FOUND_MESSAGE); + }); + + tty("2. run with CDS on, with jar on path"); + TestCommon.run("-Xlog:cds", + "-Xlog:class+load", + "-cp", mainJar.toString() + PATH_SEPARATOR + testJar.toString(), + MAIN_CLASS) + .assertNormalExit(out -> { + out.shouldContain(CLASS_FOUND_MESSAGE) + .shouldMatch(MAIN_FROM_JAR) + .shouldMatch(TEST_FROM_JAR) + .shouldContain(OPTIMIZE_DISABLED) + .shouldNotContain(OPTIMIZE_ENABLED) + .shouldContain(FMG_DISABLED) + .shouldNotContain(FMG_ENABLED); + }); + + tty("3. run with CDS on, with --module-path, with jar should fail"); + TestCommon.run("-Xlog:cds", + "-Xlog:class+load", + "-p", libsDir.toString(), + "-cp", mainJar.toString(), + MAIN_CLASS) + .assertNormalExit(out -> { + out.shouldContain(CLASS_NOT_FOUND_MESSAGE) + .shouldMatch(MAIN_FROM_JAR) + .shouldNotContain(FMG_ENABLED) + .shouldNotContain(OPTIMIZE_ENABLED); + }); + + final String modularJarPath = mainJar.toString() + PATH_SEPARATOR + testJar.toString(); + + tty("4. run with CDS on, with modular jars specified --module-path, should pass"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + modularJarPath, // --module-path + MAIN_MODULE) // -m + .assertNormalExit(out -> { + out.shouldNotContain(OPTIMIZE_DISABLED) + .shouldContain(OPTIMIZE_ENABLED) + .shouldNotContain(FMG_DISABLED) + .shouldContain(FMG_ENABLED) + .shouldMatch(MAIN_FROM_CDS); // archived Main class is for module only + }); + + final String extraModulePath = libsDir.toString() + PATH_SEPARATOR + dupDir.toString(); + // create an archive with an extra module which is not referenced + output = TestCommon.createArchive( + null, appClasses, + "--module-path", + extraModulePath, + "-m", MAIN_MODULE); + TestCommon.checkDump(output); + + tty("5. run with CDS on, without the extra module specified in dump time, should pass"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + libsDir.toString(), // --module-path + MAIN_MODULE) // -m + .assertNormalExit(out -> { + out.shouldNotContain(OPTIMIZE_DISABLED) + .shouldContain(OPTIMIZE_ENABLED) + .shouldNotContain(FMG_DISABLED) + .shouldContain(FMG_ENABLED) + .shouldMatch(MAIN_FROM_CDS) // archived Main class is for module only + .shouldContain(CLASS_FOUND_MESSAGE); + }); + tty("6. run with CDS on, with the extra module specified in dump time"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + extraModulePath, // --module-path + MAIN_MODULE) // -m + .assertNormalExit(out -> { + out.shouldNotContain(OPTIMIZE_ENABLED) + .shouldContain(OPTIMIZE_DISABLED) + .shouldNotContain(FMG_ENABLED) + .shouldContain(FMG_DISABLED) + .shouldMatch(MAIN_FROM_CDS) // archived Main class is for module only + .shouldContain(CLASS_FOUND_MESSAGE); + }); + + final String extraJarPath = modularJarPath + PATH_SEPARATOR + dupJar.toString(); + + // create an archive by specifying modular jars in the --module-path with an extra module which is not referenced + output = TestCommon.createArchive( + null, appClasses, + "--module-path", + extraJarPath, + "-m", MAIN_MODULE); + TestCommon.checkDump(output); + tty("7. run with CDS on, without the extra module specified in dump time, should pass"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + modularJarPath, // --module-path + MAIN_MODULE) // -m + .assertNormalExit(out -> { + out.shouldNotContain(OPTIMIZE_DISABLED) + .shouldContain(OPTIMIZE_ENABLED) + .shouldNotContain(FMG_DISABLED) + .shouldContain(FMG_ENABLED) + .shouldMatch(MAIN_FROM_CDS) // archived Main class is for module only + .shouldContain(CLASS_FOUND_MESSAGE); + }); + + tty("8. run with CDS on, with the extra module specified in dump time"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + extraJarPath, // --module-path + MAIN_MODULE) // -m + .assertNormalExit(out -> { + out.shouldNotContain(OPTIMIZE_ENABLED) + .shouldContain(OPTIMIZE_DISABLED) + .shouldNotContain(FMG_ENABLED) + .shouldContain(FMG_DISABLED) + .shouldMatch(MAIN_FROM_CDS) // archived Main class is for module only + .shouldContain(CLASS_FOUND_MESSAGE); + }); + tty("9. same as test case 8 but with paths instead of modular jars in the --module-path"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + extraModulePath, // --module-path + MAIN_MODULE) // -m + .assertNormalExit(out -> { + out.shouldNotContain(OPTIMIZE_ENABLED) + .shouldContain(OPTIMIZE_DISABLED) + .shouldNotContain(FMG_ENABLED) + .shouldContain(FMG_DISABLED) + .shouldMatch(MAIN_FROM_CDS) // archived Main class is for module only + .shouldContain(CLASS_FOUND_MESSAGE); + }); + } + + public static void runWithExplodedModule() throws Exception { + // create an archive with an exploded module in the module path. + OutputAnalyzer output = TestCommon.createArchive( + null, appClasses, + "--module-path", + MODS_DIR.toString(), + "-m", MAIN_MODULE + "/" + MAIN_CLASS); + TestCommon.checkDump(output); + + tty("10. run with CDS on, with exploded module in the module path"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + MODS_DIR.toString(), // --module-path + MAIN_MODULE + "/" + MAIN_CLASS) // -m + .assertNormalExit(out -> { + out.shouldContain(FMG_DISABLED) + .shouldMatch(MAIN_FROM_MODULE) // Main class loaded from the exploded module + .shouldContain(CLASS_FOUND_MESSAGE); + }); + } + + public static void runWithJmodAndBadJar() throws Exception { + buildJmod(); + + final String modularJarPath = mainJar.toString() + PATH_SEPARATOR + testJar.toString(); + // create an archive with --module-path com.bars.jar:com.foos.jar + OutputAnalyzer output = TestCommon.createArchive( + null, appClasses, + "--module-path", + modularJarPath, + "-m", MAIN_MODULE); + TestCommon.checkDump(output); + + String runModulePath = mainJar.toString() + PATH_SEPARATOR + + jmodDir.toString() + TEST_MODULE + ".jmod"; + tty("11. run with CDS on, with module path com.bars.jar:com.foos.jmod"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + runModulePath, // --module-path + MAIN_MODULE) // -m + .assertAbnormalExit(out -> { + out.shouldContain(OPTIMIZE_DISABLED) + .shouldNotContain(OPTIMIZE_ENABLED) + .shouldContain(FMG_DISABLED) + .shouldNotContain(FMG_ENABLED) + .shouldContain(FIND_EXCEPTION_MESSAGE); + }); + + runModulePath += PATH_SEPARATOR + testJar.toString(); + tty("12. run with CDS on, with module path com.bars.jar:com.foos.jmod:com.foos.jar"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + runModulePath, // --module-path + MAIN_MODULE) // -m + .assertNormalExit(out -> { + out.shouldNotContain(OPTIMIZE_DISABLED) + .shouldContain(OPTIMIZE_ENABLED) + .shouldNotContain(FMG_DISABLED) + .shouldContain(FMG_ENABLED) + .shouldMatch(TEST_FROM_CDS) + .shouldMatch(MAIN_FROM_CDS) + .shouldContain(CLASS_FOUND_MESSAGE); + }); + + runModulePath = badJar.toString() + PATH_SEPARATOR + testJar.toString(); + tty("13. run with CDS on, with module path com.bars.JAR:com.foos.jar"); + TestCommon.runWithModules(prefix, + null, // --upgrade-module-path + runModulePath, // --module-path + TEST_MODULE) // -m + .assertAbnormalExit(out -> { + out.shouldContain(OPTIMIZE_DISABLED) + .shouldNotContain(OPTIMIZE_ENABLED) + .shouldContain(FMG_DISABLED) + .shouldNotContain(FMG_ENABLED) + .shouldMatch(MODULE_NOT_RECOGNIZED); + }); + } +} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/OptimizeModuleHandlingTest.java b/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/OptimizeModuleHandlingTest.java index aeb5696830d..cf6f4cd7fd3 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/OptimizeModuleHandlingTest.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/jigsaw/modulepath/OptimizeModuleHandlingTest.java @@ -24,7 +24,7 @@ /** * @test - * @requires vm.cds & !vm.graal.enabled + * @requires vm.cds & !vm.graal.enabled & vm.cds.write.archived.java.heap * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds * @run driver OptimizeModuleHandlingTest * @summary test module path changes for optimization of @@ -64,8 +64,8 @@ public class OptimizeModuleHandlingTest { private static String CLASS_FOUND_MESSAGE = "com.foos.Test found"; private static String CLASS_NOT_FOUND_MESSAGE = "java.lang.ClassNotFoundException: com.foos.Test"; - private static String OPTIMIZE_ENABLED = "optimized module handling: enabled"; - private static String OPTIMIZE_DISABLED = "optimized module handling: disabled"; + private static String OPTIMIZE_ENABLED = "] optimized module handling: enabled"; + private static String OPTIMIZE_DISABLED = "] optimized module handling: disabled"; private static String MAIN_FROM_JAR = "class,load.*com.bars.Main.*[.]jar"; private static String MAIN_FROM_CDS = "class,load.*com.bars.Main.*shared objects file"; private static String TEST_FROM_JAR = "class,load.*com.foos.Test.*[.]jar"; @@ -154,14 +154,14 @@ public static void runWithModulePath(String... extraRuntimeArgs) throws Exceptio // Following 5 - 10 test with CDS on tty("5. run with CDS on, with module path"); - String prefix[] = {"-Djava.class.path=", "-Xlog:cds", "-Xlog:class+load"}; + String prefix[] = {"-Djava.class.path=", "-Xlog:cds,class+load,class+path=info"}; TestCommon.runWithModules(prefix, null, // --upgrade-module-path libsDir.toString(), // --module-path MAIN_MODULE) // -m .assertNormalExit(out -> { - out.shouldNotContain(OPTIMIZE_ENABLED) - .shouldContain(OPTIMIZE_DISABLED) + out.shouldNotContain(OPTIMIZE_DISABLED) + .shouldContain(OPTIMIZE_ENABLED) .shouldMatch(MAIN_FROM_CDS) // // archived Main class is for module only .shouldContain(CLASS_FOUND_MESSAGE); }); @@ -174,8 +174,8 @@ public static void runWithModulePath(String... extraRuntimeArgs) throws Exceptio out.shouldContain(CLASS_FOUND_MESSAGE) .shouldMatch(MAIN_FROM_CDS) .shouldMatch(TEST_FROM_CDS) - .shouldContain(OPTIMIZE_DISABLED) - .shouldNotContain(OPTIMIZE_ENABLED); + .shouldContain(OPTIMIZE_ENABLED) + .shouldNotContain(OPTIMIZE_DISABLED); }); tty("7. run with CDS on, with jar on path"); TestCommon.run("-Xlog:cds", @@ -231,7 +231,6 @@ public static void runWithModulePath(String... extraRuntimeArgs) throws Exceptio MAIN_CLASS) .assertAbnormalExit(out -> { out.shouldNotContain(CLASS_FOUND_MESSAGE) - .shouldContain(OPTIMIZE_DISABLED) // mapping info .shouldContain("shared class paths mismatch"); }); } diff --git a/test/hotspot/jtreg/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java b/test/hotspot/jtreg/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java index df4f9063586..d62e286c68d 100644 --- a/test/hotspot/jtreg/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java +++ b/test/hotspot/jtreg/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java @@ -304,7 +304,10 @@ private String[] cmd(long classStart, long classStop) { "-XX:+StressMacroExpansion", "-XX:+StressIncrementalInlining", // StressSeed is uint - "-XX:StressSeed=" + rng.nextInt(Integer.MAX_VALUE))); + "-XX:StressSeed=" + rng.nextInt(Integer.MAX_VALUE), + // Do not fail on huge methods where StressGCM makes register + // allocation allocate lots of memory + "-XX:CompileCommand=memlimit,*.*,0")); for (String arg : CTW_EXTRA_ARGS.split(",")) { Args.add(arg); diff --git a/test/hotspot/jtreg/vmTestbase/jit/escape/LockElision/MatMul/MatMul.java b/test/hotspot/jtreg/vmTestbase/jit/escape/LockElision/MatMul/MatMul.java index cf20b0df8a0..8d1a5fac9ae 100644 --- a/test/hotspot/jtreg/vmTestbase/jit/escape/LockElision/MatMul/MatMul.java +++ b/test/hotspot/jtreg/vmTestbase/jit/escape/LockElision/MatMul/MatMul.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024, 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 @@ -85,7 +85,7 @@ public static void main(String[] args) { } public int run() { - log = new Log(System.out, verbose); + log = new Log(System.out); log.display("Parallel matrix multiplication test"); Matrix a = Matrix.randomMatrix(dim); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/LaunchingConnector/launchnosuspend/launchnosuspend001.java b/test/hotspot/jtreg/vmTestbase/nsk/jdi/LaunchingConnector/launchnosuspend/launchnosuspend001.java index 015643f3a18..142d6387610 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/LaunchingConnector/launchnosuspend/launchnosuspend001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/LaunchingConnector/launchnosuspend/launchnosuspend001.java @@ -73,7 +73,6 @@ private launchnosuspend001 (String args[], PrintStream out) { argHandler = new ArgumentHandler(args); log = new Log(this.out, argHandler); - //log.enableVerbose(true); } private PrintStream out; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/filter_tagged/HeapFilter.java b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/filter_tagged/HeapFilter.java index 91f315ee7a9..b690955307e 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/filter_tagged/HeapFilter.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/IterateThroughHeap/filter_tagged/HeapFilter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -49,7 +49,6 @@ public int runTest(String args[], PrintStream out) { log = new Log(out, argHandler); testObjects = new Object[]{new TaggedClass(), new UntaggedClass()}; - log.enableVerbose(true); log.display("Verifying reachable objects."); status = checkStatus(status); testObjects = null; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryPoolMBean/isCollectionUsageThresholdExceeded/isexceeded001.java b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryPoolMBean/isCollectionUsageThresholdExceeded/isexceeded001.java index 702a5a79379..a9e75bb7cec 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryPoolMBean/isCollectionUsageThresholdExceeded/isexceeded001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryPoolMBean/isCollectionUsageThresholdExceeded/isexceeded001.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024, 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 @@ -40,7 +40,6 @@ public static void main(String[] argv) { public static int run(String[] argv, PrintStream out) { ArgumentHandler argHandler = new ArgumentHandler(argv); Log log = new Log(out, argHandler); - log.enableVerbose(true); monitor = Monitor.getMemoryMonitor(log, argHandler); List pools = monitor.getMemoryPoolMBeans(); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded001.java b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded001.java index 390bfdd6251..a684c03e67a 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryPoolMBean/isUsageThresholdExceeded/isexceeded001.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024, 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 @@ -47,7 +47,6 @@ public static void main(String[] argv) { public static int run(String[] argv, PrintStream out) { ArgumentHandler argHandler = new ArgumentHandler(argv); Log log = new Log(out, argHandler); - log.enableVerbose(true); // show log output MemoryMonitor monitor = Monitor.getMemoryMonitor(log, argHandler); List pools = monitor.getMemoryPoolMBeans(); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/stress/lowmem/lowmem001.java b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/stress/lowmem/lowmem001.java index d698e5aec83..67f0d17f561 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/monitoring/stress/lowmem/lowmem001.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/monitoring/stress/lowmem/lowmem001.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -58,7 +58,7 @@ public static void main(String[] args) { @Override public void run() { - Log log = new Log(System.out, true); + Log log = new Log(System.out); // System.err is duplicated into buffer // it should be empty MyStream stream = new MyStream(System.err); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/Log.java b/test/hotspot/jtreg/vmTestbase/nsk/share/Log.java index e5750182495..99467fc0334 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/Log.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/Log.java @@ -29,22 +29,15 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringReader; -import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.HashSet; import java.util.Vector; -import nsk.share.test.LazyFormatString; /** - * This class helps to print test-execution trace messages - * and filter them when execution mode is not verbose. - *

    - * Verbose mode if defined by providing -verbose command line - * option, handled by ArgumentParser. Use verbose() - * method to determine which mode is used. + * This class helps to print test-execution trace messages. *

    * Log provides with two main methods to print messages: *

      @@ -60,7 +53,6 @@ * To provide printing messages from different sources into one log * with distinct prefixes use internal Log.Logger class. * - * @see #verbose() * @see #complain(String) * @see #display(String) * @see ArgumentParser @@ -72,18 +64,6 @@ public class Log { */ private PrintStream out = null; - /** - * Is log-mode verbose? - * Always enabled. - */ - private final boolean verbose = true; - - /** - * Should log messages prefixed with timestamps? - * Always enabled. - */ - private final boolean timestamp = true; - /** * Names for trace levels */ @@ -188,41 +168,15 @@ public Log(PrintStream stream) { /** * Incarnate new Log for the given stream; and - * either for verbose or for non-verbose mode accordingly to - * the given verbose key. - */ - public Log(PrintStream stream, boolean verbose) { - this(stream); - } - - /** - * Incarnate new Log for the given stream; and - * either for verbose or for non-verbose mode accordingly to * the given argsHandler. */ public Log(PrintStream stream, ArgumentParser argsParser) { - this(stream, argsParser.verbose()); + this(stream); traceLevel = argsParser.getTraceLevel(); } ///////////////////////////////////////////////////////////////// - /** - * Return true if log mode is verbose. - */ - public boolean verbose() { - return verbose; - } - - /** - * Enable or disable verbose mode for printing messages. - */ - public void enableVerbose(boolean enable) { - if (!enable) { - throw new RuntimeException("The non-verbose logging is not supported."); - } - } - public int getTraceLevel() { return traceLevel; } @@ -266,9 +220,6 @@ public static String printExceptionToString(Object prefix, Throwable exception) @Deprecated public synchronized void println(String message) { doPrint(message); - if (!verbose()) { - keepLog(composeLine(message)); - } } /** @@ -282,9 +233,6 @@ public synchronized void println(String message) { */ @Deprecated public synchronized void comment(String message) { - if (!verbose()) { - doPrint(message); - } } /** @@ -314,17 +262,10 @@ public void trace(int level, Object message, Throwable exception) { } /** - * Print message to the assigned output stream, - * if log mode is verbose. The message will be lost, - * if execution mode is non-verbose, and there is no error messages - * printed. + * Print message to the assigned output stream. */ public synchronized void display(Object message) { - if (verbose()) { - doPrint(message.toString()); - } else { - keepLog(composeLine(message.toString())); - } + doPrint(message.toString()); } /** @@ -333,15 +274,6 @@ public synchronized void display(Object message) { * into errorsBuffer. */ public synchronized void complain(Object message) { - if (!verbose()) { - PrintStream stream = findOutStream(); - stream.println("#> "); - stream.println("#> WARNING: switching log to verbose mode,"); - stream.println("#> because error is complained"); - stream.println("#> "); - stream.flush(); - enableVerbose(true); - } String msgStr = message.toString(); printError(msgStr); @@ -406,10 +338,7 @@ private void logExceptionForFailureAnalysis(String msg) { ///////////////////////////////////////////////////////////////// /** - * Redirect log to the given stream, and switch - * log mode to verbose. - * Prints errors summary to current stream, cancel current stream - * and switches to new stream. Turns on verbose mode for new stream. + * Redirect log to the given stream. * * @deprecated This method is obsolete. */ @@ -430,20 +359,6 @@ public synchronized void clearLogBuffer() { logBuffer.clear(); } - /** - * Print all messages from log buffer which were hidden because - * of non-verbose mode, - */ - private synchronized void flushLogBuffer() { - if (!logBuffer.isEmpty()) { - PrintStream stream = findOutStream(); - for (int i = 0; i < logBuffer.size(); i++) { - stream.println(logBuffer.elementAt(i)); - } - stream.flush(); - } - } - /** * Return out stream if defined or Sytem.err otherwise; * print a warning message when System.err is used first time. @@ -468,18 +383,15 @@ private synchronized PrintStream findOutStream() { * Compose line to print possible prefixing it with timestamp. */ private String composeLine(String message) { - if (timestamp) { - long time = System.currentTimeMillis(); - long ms = time % 1000; - time /= 1000; - long secs = time % 60; - time /= 60; - long mins = time % 60; - time /= 60; - long hours = time % 24; - return "[" + hours + ":" + mins + ":" + secs + "." + ms + "] " + message; - } - return message; + long time = System.currentTimeMillis(); + long ms = time % 1000; + time /= 1000; + long secs = time % 60; + time /= 60; + long mins = time % 60; + time /= 60; + long hours = time % 24; + return "[" + hours + ":" + mins + ":" + secs + "." + ms + "] " + message; } /** @@ -513,13 +425,6 @@ private synchronized void printError(String message) { } } - /** - * Keep the given log message into logBuffer. - */ - private synchronized void keepLog(String message) { - logBuffer.addElement(message); - } - /** * This class can be used as a base for each class that use Log * for print messages and errors. diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODTestRunner.java b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODTestRunner.java index bde40cc7e20..9899c762a7a 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODTestRunner.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AODTestRunner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -68,7 +68,7 @@ public class AODTestRunner { protected AODRunnerArgParser argParser; protected AODTestRunner(String[] args) { - log = new Log(System.out, true); + log = new Log(System.out); argParser = createArgParser(args); } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AbstractJarAgent.java b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AbstractJarAgent.java index 3fa3141a8cd..fb02327a422 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AbstractJarAgent.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/AbstractJarAgent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -157,7 +157,7 @@ private void defaultInit(String[] args) { if (name == null) throw new TestBug("Agent name wasn't specified"); - log = new Log(System.out, true); + log = new Log(System.out); } /* diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java index bb726453e9b..c8fb3bf2663 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java @@ -39,7 +39,7 @@ */ public class DummyTargetApplication { - protected Log log = new Log(System.out, true); + protected Log log = new Log(System.out); protected AODTargetArgParser argParser; diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/TargetApplicationWaitingAgents.java b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/TargetApplicationWaitingAgents.java index 6f80033dff5..0b5acfb24ba 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/TargetApplicationWaitingAgents.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/TargetApplicationWaitingAgents.java @@ -213,7 +213,7 @@ private void initTargetApplication(String[] args) { if (targetApplicationInitialized) throw new TestBug("TargetApplication already initialized"); - log = new Log(System.out, true); + log = new Log(System.out); argParser = createArgParser(args); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/Memory.java b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/Memory.java index f5c70671e5e..244bcf423c5 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/Memory.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/Memory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024, 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 @@ -150,12 +150,9 @@ public static int getReferenceObjectSize() { * @return length of array */ public static int getArrayLength(long memory, long objectSize) { - int referenceSize = getReferenceSize(); int arrayExtraSize = getArrayExtraSize(); - return (int) Math.min( - (memory - arrayExtraSize) / (objectSize + referenceSize), - Integer.MAX_VALUE - ); + return (int) Math.min((memory - arrayExtraSize) / objectSize, + Integer.MAX_VALUE); } /** @@ -166,7 +163,7 @@ public static int getArrayLength(long memory, long objectSize) { * @return size of array */ public static long getArraySize(int length, long objectSize) { - return getObjectExtraSize() + length * (objectSize + getReferenceSize()); + return getArrayExtraSize() + length * objectSize; } /** diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/JVMTITest.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/JVMTITest.java index c8d26b6ea1f..d9b847e110d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/JVMTITest.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jvmti/JVMTITest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -87,7 +87,7 @@ static void attachAgent(String[] args) { AgentsAttacher attacher = new AgentsAttacher(Utils.findCurrentVMIdUsingJPS(jdkPath), agents, - new Log(System.out, true)); + new Log(System.out)); attacher.attachAgents(); } } diff --git a/test/hotspot/jtreg/vmTestbase/vm/compiler/coverage/parentheses/Parentheses.java b/test/hotspot/jtreg/vmTestbase/vm/compiler/coverage/parentheses/Parentheses.java index 66546e9b13f..219af51045a 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/compiler/coverage/parentheses/Parentheses.java +++ b/test/hotspot/jtreg/vmTestbase/vm/compiler/coverage/parentheses/Parentheses.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -69,7 +69,7 @@ public static void main(String[] args) throws Exception { public void run() throws IOException, ReflectiveOperationException { - log = new Log(System.out, verbose); + log = new Log(System.out); InstructionSequence instructionSequence = null; for (int i = 0; i < iterations * stressOptions.getIterationsFactor(); i++) { diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 8060792a51f..bf1c9bd31e7 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -121,6 +121,8 @@ java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusToFrontTest.java 6848406 gen java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusSetVisibleTest.java 6848407 generic-all java/awt/Frame/MaximizedUndecorated/MaximizedUndecorated.java 8022302 generic-all java/awt/Frame/RestoreToOppositeScreen/RestoreToOppositeScreen.java 8286840 linux-all +java/awt/Frame/InitialIconifiedTest.java 8203920 macosx-all,linux-all +java/awt/Frame/ShapeNotSetSometimes/ShapeNotSetSometimes.java 8341370 macosx-all java/awt/FileDialog/FileDialogIconTest/FileDialogIconTest.java 8160558 windows-all java/awt/event/MouseWheelEvent/InfiniteRecursion/InfiniteRecursion.java 8060176 windows-all,macosx-all java/awt/event/MouseWheelEvent/InfiniteRecursion/InfiniteRecursion_1.java 8060176 windows-all,macosx-all @@ -797,3 +799,4 @@ java/awt/Frame/SizeMinimizedTest.java 8305915 linux-x64 java/awt/PopupMenu/PopupHangTest.java 8340022 windows-all java/awt/Focus/MinimizeNonfocusableWindowTest.java 8024487 windows-all java/awt/Focus/InactiveFocusRace.java 8023263 linux-all +java/awt/List/HandlingKeyEventIfMousePressedTest.java 6848358 macosx-all,windows-all diff --git a/test/jdk/build/AbsPathsInImage.java b/test/jdk/build/AbsPathsInImage.java index 712f990507d..229094a0920 100644 --- a/test/jdk/build/AbsPathsInImage.java +++ b/test/jdk/build/AbsPathsInImage.java @@ -40,7 +40,7 @@ * @bug 8226346 * @summary Check all output files for absolute path fragments * @requires !vm.debug - * @run main AbsPathsInImage + * @run main/othervm -Xmx900m AbsPathsInImage */ public class AbsPathsInImage { diff --git a/test/jdk/com/sun/tools/attach/java.policy.allow b/test/jdk/com/sun/tools/attach/java.policy.allow index 3e63a207f61..1d4b714c902 100644 --- a/test/jdk/com/sun/tools/attach/java.policy.allow +++ b/test/jdk/com/sun/tools/attach/java.policy.allow @@ -1,6 +1,4 @@ /* - * - * * Policy file used by unit tests for attach API */ grant { @@ -15,7 +13,10 @@ grant { permission java.lang.RuntimePermission "loadLibrary.attach"; permission java.util.PropertyPermission "sun.jvmstat.*", "read"; - /* to read configuration file in META-INF/services, and write/delete .attach_pid */ - permission java.io.FilePermission "<>", "read,write,delete"; + /* + * To read configuration file in META-INF/services, write/delete .attach_pid, + * and read symbolic link of /proc/self/ns/mnt. + */ + permission java.io.FilePermission "<>", "read,write,delete,readlink"; }; diff --git a/test/jdk/java/awt/Button/BadActionEventTest/BadActionEventTest.java b/test/jdk/java/awt/Button/BadActionEventTest/BadActionEventTest.java new file mode 100644 index 00000000000..53aac7ab787 --- /dev/null +++ b/test/jdk/java/awt/Button/BadActionEventTest/BadActionEventTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2001, 2024, 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 4530087 + * @summary Test if double-clicking causes ActionEvent on underlying button + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual BadActionEventTest + */ + +import java.awt.Button; +import java.awt.Color; +import java.awt.FileDialog; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class BadActionEventTest implements ActionListener { + private static Button showBtn; + private static Button listBtn; + + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + 1) Click on 'Show File Dialog' to bring up the FileDialog window. + (If necessary, change to a directory with files (not just directories) in it.) + 2) Move the FileDialog so that one of the file names (again, a file, NOT a directory) in the list is + directly over the 'ActionListener' button. + 3) Double-click on the file name over the button. The FileDialog will disappear. + 4) If the 'ActionListener' button receives an ActionEvent, the test fails and a + message to that effect will be printed. + Otherwise, the test passes. + """; + + PassFailJFrame.builder() + .title("Test Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .testUI(BadActionEventTest::createUI) + .logArea(2) + .build() + .awaitAndCheck(); + } + + private static Frame createUI() { + Frame frame = new Frame("BadActionEventTest"); + frame.setLayout(new GridLayout(1, 2)); + frame.setSize(400, 200); + showBtn = new Button("Show File Dialog"); + listBtn = new Button("ActionListener"); + showBtn.setSize(200, 200); + listBtn.setSize(200, 200); + showBtn.addActionListener(new BadActionEventTest()); + listBtn.addActionListener(new BadActionEventTest()); + frame.add(showBtn); + frame.add(listBtn); + return frame; + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == showBtn) { + FileDialog fd = new FileDialog(new Frame()); + fd.setVisible(true); + } else if (e.getSource() == listBtn) { + listBtn.setBackground(Color.red); + listBtn.setLabel("TEST FAILS!"); + PassFailJFrame.log("*TEST FAILS!* ActionListener got ActionEvent! *TEST FAILS!*"); + } + } +} diff --git a/test/jdk/java/awt/Choice/ChoiceInLWTest/ChoiceInLWTest.java b/test/jdk/java/awt/Choice/ChoiceInLWTest/ChoiceInLWTest.java new file mode 100644 index 00000000000..9d1ad195491 --- /dev/null +++ b/test/jdk/java/awt/Choice/ChoiceInLWTest/ChoiceInLWTest.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 1998, 2024, 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 4130788 + * @summary Choice components move unexpectedly when in lightweight containers + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual ChoiceInLWTest + */ + +import java.awt.BorderLayout; +import java.awt.Choice; +import java.awt.Container; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Label; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.lang.reflect.InvocationTargetException; + +public class ChoiceInLWTest extends Frame implements Runnable { + private final Choice choices; + static final String INSTRUCTIONS = """ + After test starts wait for two seconds and open a choice. + If choice's popup obscures the label above it press Fail. + Otherwise press Pass. + """; + + public ChoiceInLWTest() { + setLayout(new BorderLayout()); + Container lwCont = new Container(); + lwCont.setLayout(new FlowLayout()); + choices = new Choice(); + choices.add("This is just a token item to get a nice width."); + lwCont.add(choices); + add("Center", lwCont); + Label label = new Label("You should see an unobscured Choice below."); + label.setAlignment(Label.CENTER); + add("North", label); + addChoiceItem(); + addWindowListener(new WindowAdapter() { + @Override + public void windowOpened(WindowEvent e) { + super.windowOpened(e); + new Thread(ChoiceInLWTest.this).start(); + } + }); + pack(); + } + + private void addChoiceItem() { + choices.add("Adding an item used to move the Choice!"); + } + + public void run() { + try { + Thread.sleep(1000); + } catch (InterruptedException ignore) { + } + addChoiceItem(); + } + + public static void main(String[] args) throws InterruptedException, + InvocationTargetException { + PassFailJFrame.builder() + .title("Choice in LW Container Test") + .testUI(ChoiceInLWTest::new) + .instructions(INSTRUCTIONS) + .columns(40) + .build() + .awaitAndCheck(); + + } +} diff --git a/test/jdk/java/awt/Choice/MultiItemSelected/MultiItemSelected_DragOut.java b/test/jdk/java/awt/Choice/MultiItemSelected/MultiItemSelected_DragOut.java new file mode 100644 index 00000000000..aed15437745 --- /dev/null +++ b/test/jdk/java/awt/Choice/MultiItemSelected/MultiItemSelected_DragOut.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2005, 2024, 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 6367251 + * @summary 2 items are highlighted when pressing, dragging the mouse inside the choice, XToolkit + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual MultiItemSelected_DragOut + */ + +import java.awt.Choice; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.lang.reflect.InvocationTargetException; + +public class MultiItemSelected_DragOut extends Frame { + static final String INSTRUCTIONS = """ + 1) Open Choice. + 2) Start drag from first item to second or third one. + 3) Without releasing left mouse button + press and release right mouse button. + 4) Release left mouse button. + 5) Open choice again. + 6) If there is only one selection cursor + in the dropdown list press Pass otherwise press Fail. + """; + + public MultiItemSelected_DragOut() { + Choice choice = new Choice(); + + for (int i = 1; i < 10; i++) { + choice.add("item " + i); + } + add(choice); + choice.addItemListener(ie -> System.out.println(ie)); + + setLayout(new FlowLayout()); + setSize(200, 200); + validate(); + } + + public static void main(String[] args) throws InterruptedException, + InvocationTargetException { + PassFailJFrame.builder() + .title("MultiItemSelected Drag Out Test") + .testUI(MultiItemSelected_DragOut::new) + .instructions(INSTRUCTIONS) + .columns(40) + .build() + .awaitAndCheck(); + } +} diff --git a/test/jdk/java/awt/Choice/MultiItemSelected/MultiItemSelected_KeySelect.java b/test/jdk/java/awt/Choice/MultiItemSelected/MultiItemSelected_KeySelect.java new file mode 100644 index 00000000000..9e930f9923b --- /dev/null +++ b/test/jdk/java/awt/Choice/MultiItemSelected/MultiItemSelected_KeySelect.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2005, 2024, 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 6367251 + * @summary 2 items are highlighted when dragging inside and press ESC or ENTER + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual MultiItemSelected_KeySelect + */ + +import java.awt.Choice; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.lang.reflect.InvocationTargetException; + +public class MultiItemSelected_KeySelect extends Frame { + static final String INSTRUCTIONS = """ + 1) Open Choice. + 2) Start drag from first item to another one. + 3) Without releasing the mouse button press ESC key. + 4) Open choice again. + 5) Verify that there is only one + selection cursor in the dropdown list. + 6) Repeat steps 2-5 once again but this time + press ENTER key instead of ESC. + 7) If in both scenarios there is only one selection cursor + press Pass otherwise press Fail. + """; + + public MultiItemSelected_KeySelect() { + Choice choice = new Choice(); + + for (int i = 1; i < 10; i++) { + choice.add("item " + i); + } + add(choice); + choice.addItemListener(ie -> System.out.println(ie)); + setLayout(new FlowLayout()); + setSize(200, 200); + validate(); + } + + public static void main(String[] args) throws InterruptedException, + InvocationTargetException { + PassFailJFrame.builder() + .title("MultiItemSelected Key Select Test") + .testUI(MultiItemSelected_KeySelect::new) + .instructions(INSTRUCTIONS) + .columns(40) + .build() + .awaitAndCheck(); + } +} diff --git a/test/jdk/java/awt/Choice/MultiItemSelected/MultiItemSelected_UpDown.java b/test/jdk/java/awt/Choice/MultiItemSelected/MultiItemSelected_UpDown.java new file mode 100644 index 00000000000..5904d98a908 --- /dev/null +++ b/test/jdk/java/awt/Choice/MultiItemSelected/MultiItemSelected_UpDown.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2005, 2024, 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 6367251 + * @summary 2 items are highlighted when dragging outside and press UP or DOWN + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual MultiItemSelected_UpDown + */ + +import java.awt.Choice; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.lang.reflect.InvocationTargetException; + +public class MultiItemSelected_UpDown extends Frame { + static final String INSTRUCTIONS = """ + 1) Open Choice. + 2) Start drag from first item to another one. + 3) Without interrupting drag + move mouse cursor outside the choice popup. + 4) Press UP, DOWN key several times to position + selection cursor to a different item. + 5) Release mouse button. + 6) If popup is closed upon mouse button release open Choice again. + 7) Verify that there is only one + selection cursor in the dropdown list. + 8) If true then press Pass, otherwise press Fail. + """; + + public MultiItemSelected_UpDown() { + Choice choice = new Choice(); + + for (int i = 1; i < 20; i++) { + choice.add(" item " + i); + } + add(choice); + choice.addItemListener(ie -> System.out.println(ie)); + setLayout(new FlowLayout()); + setSize(200, 200); + validate(); + } + + public static void main(String[] args) throws InterruptedException, + InvocationTargetException { + PassFailJFrame.builder() + .title("MultiItemSelected Up/Down Test") + .testUI(MultiItemSelected_UpDown::new) + .instructions(INSTRUCTIONS) + .columns(40) + .build() + .awaitAndCheck(); + } +} diff --git a/test/jdk/java/awt/Choice/RepaintAfterRemoveLastItemTest/RepaintAfterRemoveLastItemTest.java b/test/jdk/java/awt/Choice/RepaintAfterRemoveLastItemTest/RepaintAfterRemoveLastItemTest.java new file mode 100644 index 00000000000..20acc66b6bd --- /dev/null +++ b/test/jdk/java/awt/Choice/RepaintAfterRemoveLastItemTest/RepaintAfterRemoveLastItemTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2005, 2024, 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 6292186 + * @summary Choice is not refreshed properly when the last item gets removed + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual RepaintAfterRemoveLastItemTest + */ + +import java.awt.Button; +import java.awt.Choice; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.lang.reflect.InvocationTargetException; + +public class RepaintAfterRemoveLastItemTest extends Frame implements ActionListener { + Choice ch = new Choice(); + + static final String INSTRUCTIONS = """ + Press on the 'remove' button after that if the choice does not display + 'only item' press Pass. If 'only item' is still displayed press Fail. + """; + + public RepaintAfterRemoveLastItemTest() { + ch.add("only item"); + add(ch); + + Button b = new Button("remove"); + add(b); + b.addActionListener(this); + setLayout(new FlowLayout()); + setSize(200, 200); + validate(); + } + + public void actionPerformed(ActionEvent ae) { + if (ch.getItemCount() != 0) { + ch.remove(0); + } + } + + public static void main(String[] args) throws InterruptedException, + InvocationTargetException { + PassFailJFrame.builder() + .title("Repaint After Remove Test") + .testUI(RepaintAfterRemoveLastItemTest::new) + .instructions(INSTRUCTIONS) + .columns(40) + .build() + .awaitAndCheck(); + } +} diff --git a/test/jdk/java/awt/Component/BackgroundColorTest/InitialBackgroundSettingTest.java b/test/jdk/java/awt/Component/BackgroundColorTest/InitialBackgroundSettingTest.java new file mode 100644 index 00000000000..3bed6f106c5 --- /dev/null +++ b/test/jdk/java/awt/Component/BackgroundColorTest/InitialBackgroundSettingTest.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 1998, 2024, 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 4148334 + * @summary tests that background color is initially set correctly. + * @requires os.family == "windows" + * @key headful + * @run main InitialBackgroundSettingTest + */ +import java.awt.Button; +import java.awt.Choice; +import java.awt.Color; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.List; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.Scrollbar; +import java.lang.reflect.InvocationTargetException; + +public class InitialBackgroundSettingTest { + Frame frame; + TextField tf; + TextArea ta; + Choice choice; + List list; + Scrollbar bar; + Button button; + + public static void main(String[] args) throws InterruptedException, + InvocationTargetException { + InitialBackgroundSettingTest test= new InitialBackgroundSettingTest(); + try { + EventQueue.invokeAndWait(test::setupGUI); + EventQueue.invokeAndWait(test::test); + } finally { + EventQueue.invokeAndWait(test::dispose); + } + } + + public void setupGUI () { + frame = new Frame("InitialBackgroundSettingTest frame"); + tf = new TextField("I am the TextField"); + ta = new TextArea("I am the TextArea"); + choice = new Choice(); + list = new List(); + bar = new Scrollbar(Scrollbar.HORIZONTAL); + button = new Button("I am the button"); + frame.setBackground(Color.red); + frame.setLayout(new GridLayout(7, 1)); + frame.add(button); + frame.add(bar); + frame.add(choice); + frame.add(list); + frame.add(tf); + frame.add(ta); + frame.setVisible(true); + frame.setBounds (400, 0, 300, 300); + } + + public void test() { + boolean passed = true; + System.out.println("Button background color is:" + + button.getBackground()); + if (Color.red.equals(button.getBackground())) { + System.err.println("Button background is red"); + passed = false; + } + System.out.println("Scrollbar background color is:" + + bar.getBackground()); + if (Color.red.equals(bar.getBackground())) { + System.err.println("ScrollBar background is red"); + passed = false; + } + System.out.println("Choice background color is:" + + choice.getBackground()); + if (Color.red.equals(choice.getBackground())) { + System.err.println("Choice background is red"); + passed = false; + } + System.out.println("List background color is:" + + list.getBackground()); + if (Color.red.equals(list.getBackground())) { + System.err.println("List background is red"); + passed = false; + } + System.out.println("TextField background color is:" + + tf.getBackground()); + if (Color.red.equals(tf.getBackground())) { + System.err.println("TextField background is red"); + passed = false; + } + System.out.println("TextArea background color is:" + + ta.getBackground()); + if (Color.red.equals(ta.getBackground())) { + System.err.println("TextArea background is red"); + passed = false; + } + + if (!passed) { + throw new RuntimeException("One or more component inherited" + + " background from a Frame"); + } + } + + public void dispose() { + frame.dispose(); + } +} diff --git a/test/jdk/java/awt/Component/ComponentEventTest.java b/test/jdk/java/awt/Component/ComponentEventTest.java new file mode 100644 index 00000000000..bfbfed336a0 --- /dev/null +++ b/test/jdk/java/awt/Component/ComponentEventTest.java @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2024, 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. + */ + +import java.awt.Button; +import java.awt.Checkbox; +import java.awt.Choice; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Label; +import java.awt.List; +import java.awt.Panel; +import java.awt.Point; +import java.awt.Robot; +import java.awt.Scrollbar; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.InputEvent; +import java.lang.reflect.InvocationTargetException; + +import jdk.test.lib.Platform; + +/* + * @test + * @key headful + * @bug 8333403 + * @summary Test performs various operations to check components events are triggered properly. + * @library /test/lib + * @build jdk.test.lib.Platform + * @run main ComponentEventTest + */ +public class ComponentEventTest { + + private static final int DELAY = 500; + + private static Frame frame; + private static Robot robot; + + private static Component[] components; + + private static volatile Point centerPoint; + + private static volatile boolean componentHidden; + private static volatile boolean componentShown; + private static volatile boolean componentMoved; + private static volatile boolean componentResized; + + private static final ComponentListener componentListener = + new ComponentListener() { + + @Override + public void componentShown(ComponentEvent e) { + System.out.println("ComponentShown: " + e.getSource()); + componentShown = true; + } + + @Override + public void componentResized(ComponentEvent e) { + System.out.println("ComponentResized: " + e.getSource()); + componentResized = true; + } + + @Override + public void componentMoved(ComponentEvent e) { + System.out.println("ComponentMoved: " + e.getSource()); + componentMoved = true; + } + + @Override + public void componentHidden(ComponentEvent e) { + System.out.println("ComponentHidden: " + e.getSource()); + componentHidden = true; + } + }; + + private static void initializeGUI() { + frame = new Frame("Component Event Test"); + frame.setLayout(new FlowLayout()); + + Panel panel = new Panel(); + Button button = new Button("Button"); + Label label = new Label("Label"); + List list = new List(); + list.add("One"); + list.add("Two"); + list.add("Three"); + Choice choice = new Choice(); + choice.add("Red"); + choice.add("Orange"); + choice.add("Yellow"); + Checkbox checkbox = new Checkbox("Checkbox"); + Scrollbar scrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 255); + TextField textfield = new TextField(15); + TextArea textarea = new TextArea(5, 15); + + components = new Component[] { panel, button, label, list, choice, + checkbox, scrollbar, textfield, textarea, frame }; + + for (int i = 0; i < components.length - 1; i++) { + components[i].addComponentListener(componentListener); + frame.add(components[i]); + } + frame.addComponentListener(componentListener); + + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + public static void main(String[] args) throws Exception { + try { + robot = new Robot(); + robot.setAutoWaitForIdle(true); + + EventQueue.invokeAndWait(ComponentEventTest::initializeGUI); + robot.waitForIdle(); + robot.delay(DELAY); + + doTest(); + + System.out.println("Test PASSED"); + } finally { + EventQueue.invokeAndWait(ComponentEventTest::disposeFrame); + } + } + + private static void doTest() + throws InvocationTargetException, InterruptedException { + // Click the frame to ensure it gains focus + clickFrame(); + + robot.delay(DELAY); + + for (int i = 0; i < components.length; i++) { + for (boolean state : new boolean[] { true, false }) { + doTest(components[i], state); + } + } + + robot.delay(DELAY); + + System.out.println("Iconify frame"); + resetValues(); + testIconifyFrame(); + + System.out.println("Deiconify frame"); + resetValues(); + testDeiconifyFrame(); + } + + private static void clickFrame() + throws InvocationTargetException, InterruptedException { + EventQueue.invokeAndWait(() -> { + Point location = frame.getLocationOnScreen(); + Dimension size = frame.getSize(); + centerPoint = new Point(location.x + size.width / 2, + location.y + size.height / 2); + }); + + robot.mouseMove(centerPoint.x, centerPoint.y); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + } + + private static void testIconifyFrame() + throws InvocationTargetException, InterruptedException { + EventQueue.invokeAndWait(() -> frame.setExtendedState(Frame.ICONIFIED)); + + robot.waitForIdle(); + robot.delay(DELAY); + if (componentShown || componentHidden || componentMoved + || componentResized) { + throw new RuntimeException( + "ComponentEvent triggered when frame is iconified"); + } + } + + private static void testDeiconifyFrame() + throws InvocationTargetException, InterruptedException { + EventQueue.invokeAndWait(() -> frame.setExtendedState(Frame.NORMAL)); + + robot.waitForIdle(); + robot.delay(DELAY); + + /* + * Because of the different behavior between MS Windows and other OS, we + * receive native events WM_SIZE and WM_MOVE on Windows when the frame + * state changes from iconified to normal. AWT sends these events to + * components when it receives the events from the native system. See + * JDK-6754618 for more information. + */ + + if (componentShown || componentHidden) { + throw new RuntimeException( + "FAIL: componentShown or componentHidden triggered " + + "when frame set to normal"); + } + + if (Platform.isWindows() && (!componentMoved || !componentResized)) { + throw new RuntimeException( + "FAIL: componentMoved or componentResized wasn't triggered " + + "when frame set to normal"); + } + if (!Platform.isWindows() && (componentMoved || componentResized)) { + throw new RuntimeException( + "FAIL: componentMoved or componentResized triggered " + + "when frame set to normal"); + } + } + + private static void doTest(final Component currentComponent, boolean enable) + throws InvocationTargetException, InterruptedException { + + System.out.println("Component " + currentComponent); + System.out.println(" enabled " + enable); + + EventQueue.invokeAndWait(() -> { + currentComponent.setEnabled(enable); + revalidateFrame(); + }); + + robot.delay(DELAY); + + resetValues(); + EventQueue.invokeAndWait(() -> { + currentComponent.setVisible(false); + revalidateFrame(); + }); + + robot.delay(DELAY); + if (!componentHidden) { + throw new RuntimeException("FAIL: ComponentHidden not triggered for" + + currentComponent.getClass()); + } + + resetValues(); + EventQueue.invokeAndWait(() -> { + currentComponent.setVisible(false); + revalidateFrame(); + }); + + robot.delay(DELAY); + if (componentHidden) { + throw new RuntimeException("FAIL: ComponentHidden triggered when " + + "setVisible(false) called for a hidden " + + currentComponent.getClass()); + } + + resetValues(); + EventQueue.invokeAndWait(() -> { + currentComponent.setVisible(true); + revalidateFrame(); + }); + + robot.delay(DELAY); + if (!componentShown) { + throw new RuntimeException("FAIL: ComponentShown not triggered for " + + currentComponent.getClass()); + } + + resetValues(); + EventQueue.invokeAndWait(() -> { + currentComponent.setVisible(true); + revalidateFrame(); + }); + + robot.delay(DELAY); + if (componentShown) { + throw new RuntimeException("FAIL: ComponentShown triggered when " + + "setVisible(true) called for a shown " + + currentComponent.getClass()); + } + + resetValues(); + EventQueue.invokeAndWait(() -> { + currentComponent.setLocation(currentComponent.getLocation().x + 1, + currentComponent.getLocation().y); + revalidateFrame(); + }); + + robot.delay(DELAY); + if (!componentMoved) { + throw new RuntimeException("FAIL: ComponentMoved not triggered for " + + currentComponent.getClass()); + } + + resetValues(); + EventQueue.invokeAndWait(() -> { + currentComponent.setSize(currentComponent.getSize().width + 1, + currentComponent.getSize().height); + revalidateFrame(); + }); + + robot.delay(DELAY); + if (!componentResized) { + throw new RuntimeException("FAIL: ComponentResized not triggered " + + "when size increases for " + currentComponent.getClass()); + } + + resetValues(); + EventQueue.invokeAndWait(() -> { + currentComponent.setSize(currentComponent.getSize().width - 1, + currentComponent.getSize().height); + revalidateFrame(); + }); + + robot.delay(DELAY); + if (!componentResized) { + throw new RuntimeException("FAIL: ComponentResized not triggered " + + "when size decreases for " + currentComponent.getClass()); + } + + System.out.println("\n"); + } + + private static void revalidateFrame() { + frame.invalidate(); + frame.validate(); + } + + private static void resetValues() { + componentShown = false; + componentHidden = false; + componentMoved = false; + componentResized = false; + } + + private static void disposeFrame() { + if (frame != null) { + frame.dispose(); + } + } +} diff --git a/test/jdk/java/awt/Component/ComponentLeakTest/ComponentLeakTest.java b/test/jdk/java/awt/Component/ComponentLeakTest/ComponentLeakTest.java new file mode 100644 index 00000000000..2936880dde6 --- /dev/null +++ b/test/jdk/java/awt/Component/ComponentLeakTest/ComponentLeakTest.java @@ -0,0 +1,769 @@ +/* + * Copyright (c) 1997, 2024, 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 + * @key headful + * @requires (os.family != "linux") + * @bug 4119609 4149812 4136116 4171960 4170095 4294016 4343272 + * @summary This test verifies that java.awt objects are being garbage + * collected correctly. That is, it ensures that unneeded + * references (such as JNI global refs or refs in static arrays) + * do not remain after the object is disposed. + * @run main/othervm ComponentLeakTest + */ + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Canvas; +import java.awt.CardLayout; +import java.awt.Checkbox; +import java.awt.CheckboxGroup; +import java.awt.CheckboxMenuItem; +import java.awt.Choice; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.FileDialog; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.GraphicsConfiguration; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Label; +import java.awt.LayoutManager; +import java.awt.List; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.MenuShortcut; +import java.awt.Panel; +import java.awt.PopupMenu; +import java.awt.ScrollPane; +import java.awt.Scrollbar; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.Window; +import java.awt.dnd.DropTarget; +import java.awt.dnd.DropTargetDragEvent; +import java.awt.dnd.DropTargetDropEvent; +import java.awt.dnd.DropTargetEvent; +import java.awt.dnd.DropTargetListener; +import java.lang.ref.PhantomReference; +import java.lang.ref.Reference; +import java.lang.ref.ReferenceQueue; +import java.util.Map; +import java.util.HashMap; + +public class ComponentLeakTest { + + public static void main(String[] args) { + final int iter = 5; + + for(int count = 0; count < iter; count++) { + MainFrame f = new MainFrame(); + MainWindow w = new MainWindow(f); + MainDialog d = new MainDialog(f); + TestFileDialog fd = new TestFileDialog(f, "TestFileDialog"); + fd.addNotify(); // fd.show() hangs + + fd.dispose(); + d.dispose(); + w.dispose(); + f.dispose(); + } + + // Test layout managers + Frame border = new Frame(); + border.setLayout(new BorderLayout()); + Frame card = new Frame(); + card.setLayout(new CardLayout()); + Frame flow = new Frame(); + flow.setLayout(new FlowLayout()); + Frame gridBag = new Frame(); + gridBag.setLayout(new GridBagLayout()); + Frame grid = new Frame(); + grid.setLayout(new GridLayout(1, 2)); + + for (int count = 0; count < iter; count++) { + border.add(new BorderTestButton("BorderTest"), + BorderLayout.WEST); + border.add(new BorderTestButton("BorderTest"), + BorderLayout.EAST); + card.add(new CardTestButton("CardTest"), "card0"); + card.add(new CardTestButton("CardTest"), "card1"); + flow.add(new FlowTestButton()); + flow.add(new FlowTestButton()); + gridBag.add(new GridBagTestButton(), new GridBagConstraints()); + gridBag.add(new GridBagTestButton(), new GridBagConstraints()); + grid.add(new GridTestButton()); + grid.add(new GridTestButton()); + + border.removeAll(); + card.removeAll(); + flow.removeAll(); + gridBag.removeAll(); + grid.removeAll(); + } + + gc(5); + try { + Thread.sleep(1000); + } catch (InterruptedException ie) { + } + + freeReferences(); + reportLeaks(); + System.err.println("Test passed."); + } + + public static void initWindow(Window w) { + w.setSize(600, 400); + w.setLayout(new FlowLayout()); + + // peered components + w.add(new TestButton("Button")); + w.add(new TestCanvas()); + w.add(new TestCheckbox("Checkbox", true)); + TestChoice choice = new TestChoice(); + choice.add("Choice 1"); + choice.add("Choice Two"); + w.add(choice); + w.add(new TestLabel("Label")); + TestList list = new TestList(); + list.add("List 1"); + list.add("List Two"); + w.add(list); + w.add(new TestScrollbar(Scrollbar.VERTICAL)); + w.add(new TestScrollbar(Scrollbar.HORIZONTAL)); + TestScrollPane scrollpane = new TestScrollPane(); + scrollpane.add(new TestButton("Button in a scrollpane")); + w.add(scrollpane); + w.add(new TestTextArea("TextArea", 3, 30)); + w.add(new TestTextField("TextField")); + + // nested components + TestPanel panel1 = new TestPanel(); + panel1.setLayout(new FlowLayout()); + panel1.setBackground(Color.red); + w.add(panel1); + + panel1.add(new TestButton("level 2")); + + Panel panel2 = new Panel(); + panel2.setLayout(new FlowLayout()); + panel2.setBackground(Color.green); + panel1.add(panel2); + + panel2.add(new TestButton("level 3")); + + w.add(new TestLightweight("Lightweight")); + } + + private static ReferenceQueue queue = new ReferenceQueue(); + private static Map refs = new HashMap(); + + public static void register(Object obj) { + PhantomReference ref = new PhantomReference(obj, queue); + refs.put(ref, obj.getClass().getName()); + } + + private static void gc() { + System.gc(); + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + throw new RuntimeException("Test was interrupted"); + } + } + + private static void gc(int num) { + for (; num > 0; num--) { + gc(); + } + } + + public static void freeReferences() { + System.err.println("Total references: " + refs.size()); + boolean wasFreed = false; + do { + Object[] arr = new Object[2000]; + gc(5); + Reference ref = null; + wasFreed = false; + while ((ref = queue.poll()) != null) { + refs.remove(ref); + wasFreed = true; + gc(); + } + } while (wasFreed); + } + + public static void reportLeaks() { + for (Reference ref : refs.keySet()) { + System.err.println("Leaked " + refs.get(ref)); + } + + if (refs.size() > 0) { + throw new RuntimeException("Some references remained: " + refs.size()); + } + } +} + +class TestFrame extends Frame { + public TestFrame() { + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestFrame(String title) { + super(title); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestWindow extends Window { + public TestWindow(Frame owner) { + super(owner); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestWindow(Window owner) { + super(owner); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestDialogL extends Dialog { + public TestDialogL(Frame owner) { + super(owner); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestDialogL(Frame owner, boolean modal) { + super(owner, modal); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestDialogL(Frame owner, String title) { + super(owner, title); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestDialogL(Frame owner, String title, boolean modal) { + super(owner, title, modal); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestDialogL(Dialog owner) { + super(owner); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestDialogL(Dialog owner, String title) { + super(owner, title); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestDialogL(Dialog owner, String title, boolean modal) { + super(owner, title, modal); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestFileDialog extends FileDialog { + public TestFileDialog(Frame parent) { + super(parent); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestFileDialog(Frame parent, String title) { + super(parent, title); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestFileDialog(Frame parent, String title, int mode) { + super(parent, title, mode); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestButton extends Button { + public TestButton() { + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestButton(String title) { + super(title); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestCanvas extends Canvas { + int width = 100; + int height = 100; + + public TestCanvas() { + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestCanvas(GraphicsConfiguration config) { + super(config); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public void paint(Graphics g) { + g.setColor(Color.blue); + g.fillRoundRect(10, 10, 50, 50, 15, 30); + g.setColor(Color.red); + g.fillOval(70, 70, 25, 25); + } + + public Dimension getPreferredSize() { + return new Dimension(width, height); + } +} + +class TestCheckbox extends Checkbox { + public TestCheckbox() { + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestCheckbox(String label) { + super(label); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestCheckbox(String label, boolean state) { + super(label, state); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestCheckbox(String label, boolean state, CheckboxGroup group) { + super(label, state, group); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestCheckbox(String label, CheckboxGroup group, boolean state) { + super(label, group, state); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestChoice extends Choice { + public TestChoice() { + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestLabel extends Label { + public TestLabel() { + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestLabel(String text) { + super(text); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestLabel(String text, int align) { + super(text, align); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestList extends List { + public TestList() { + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestList(int rows) { + super(rows); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestList(int rows, boolean multipleMode) { + super(rows, multipleMode); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestScrollbar extends Scrollbar { + public TestScrollbar() { + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestScrollbar(int orientation) { + super(orientation); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestScrollbar(int orient, int val, int visible, int min, int max) { + super(orient, val, visible, min, max); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestScrollPane extends ScrollPane { + public TestScrollPane() { + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestScrollPane(int policy) { + super(policy); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestTextField extends TextField { + public TestTextField() { + ComponentLeakTest.register(this); + requestFocus(); + setDropTarget(new TestDropTarget(this)); + } + + public TestTextField(String text) { + super(text); + ComponentLeakTest.register(this); + requestFocus(); + setDropTarget(new TestDropTarget(this)); + } + + public TestTextField(int columns) { + super(columns); + ComponentLeakTest.register(this); + requestFocus(); + setDropTarget(new TestDropTarget(this)); + } + + public TestTextField(String text, int columns) { + super(text, columns); + ComponentLeakTest.register(this); + requestFocus(); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestTextArea extends TextArea { + public TestTextArea() { + ComponentLeakTest.register(this); + requestFocus(); + setDropTarget(new TestDropTarget(this)); + } + + public TestTextArea(String text) { + super(text); + ComponentLeakTest.register(this); + requestFocus(); + setDropTarget(new TestDropTarget(this)); + } + + public TestTextArea(int rows, int columns) { + super(rows, columns); + ComponentLeakTest.register(this); + requestFocus(); + setDropTarget(new TestDropTarget(this)); + } + + public TestTextArea(String text, int rows, int columns) { + super(text, rows, columns); + ComponentLeakTest.register(this); + requestFocus(); + setDropTarget(new TestDropTarget(this)); + } + + public TestTextArea(String text, int rows, int columns, int bars) { + super(text, rows, columns, bars); + ComponentLeakTest.register(this); + requestFocus(); + setDropTarget(new TestDropTarget(this)); + } +} + +class TestPanel extends Panel { + public TestPanel() { + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } + + public TestPanel(LayoutManager layout) { + super(layout); + ComponentLeakTest.register(this); + setDropTarget(new TestDropTarget(this)); + } +} +class TestMenu extends Menu { + public TestMenu() { + ComponentLeakTest.register(this); + } + + public TestMenu(String label) { + super(label); + ComponentLeakTest.register(this); + } + + public TestMenu(String label, boolean tearOff) { + super(label, tearOff); + ComponentLeakTest.register(this); + } +} + +class TestMenuItem extends MenuItem { + public TestMenuItem() { + ComponentLeakTest.register(this); + } + public TestMenuItem(String label) { + super(label); + ComponentLeakTest.register(this); + } + + public TestMenuItem(String label, MenuShortcut s) { + super(label, s); + ComponentLeakTest.register(this); + } +} + +class TestMenuBar extends MenuBar { + public TestMenuBar() { + ComponentLeakTest.register(this); + } +} + +class TestPopupMenu extends PopupMenu { + public TestPopupMenu() { + ComponentLeakTest.register(this); + } + + public TestPopupMenu(String label) { + super(label); + ComponentLeakTest.register(this); + } +} + +class TestCheckboxMenuItem extends CheckboxMenuItem { + public TestCheckboxMenuItem() { + ComponentLeakTest.register(this); + } + + public TestCheckboxMenuItem(String label) { + super(label); + ComponentLeakTest.register(this); + } + + public TestCheckboxMenuItem(String label, boolean state) { + super(label, state); + ComponentLeakTest.register(this); + } +} + +class BorderTestButton extends Button { + public BorderTestButton() { + ComponentLeakTest.register(this); + } + + public BorderTestButton(String title) { + super(title); + ComponentLeakTest.register(this); + } +} + +class CardTestButton extends Button { + public CardTestButton() { + ComponentLeakTest.register(this); + } + + public CardTestButton(String title) { + super(title); + ComponentLeakTest.register(this); + } +} + +class FlowTestButton extends Button { + public FlowTestButton() { + ComponentLeakTest.register(this); + } + + public FlowTestButton(String title) { + super(title); + ComponentLeakTest.register(this); + } +} + +class GridBagTestButton extends Button { + public GridBagTestButton() { + ComponentLeakTest.register(this); + } + + public GridBagTestButton(String title) { + super(title); + ComponentLeakTest.register(this); + } +} + +class GridTestButton extends Button { + public GridTestButton() { + ComponentLeakTest.register(this); + } + + public GridTestButton(String title) { + super(title); + ComponentLeakTest.register(this); + } +} + +class TestLightweight extends Component { + String label; + int width = 100; + int height = 30; + + public TestLightweight(String label) { + this.label = label; + ComponentLeakTest.register(this); + } + + public void paint(Graphics g) { + Dimension d = getSize(); + g.setColor(Color.orange); + g.fillRect(0, 0, d.width, d.height); + g.setColor(Color.black); + int x = 5; + int y = (d.height - 5); + g.drawString(label, x, y); + } + + public Dimension getPreferredSize() { + return new Dimension(width,height); + } +} + +class TestDropTarget extends DropTarget { + public TestDropTarget(Component comp) { + super(comp, new DropTargetListener() { + public void dragEnter(DropTargetDragEvent dtde) {} + public void dragOver(DropTargetDragEvent dtde) {} + public void dropActionChanged(DropTargetDragEvent dtde) {} + public void dragExit(DropTargetEvent dte) {} + public void drop(DropTargetDropEvent dtde) {} + }); + ComponentLeakTest.register(this); + } +} + +class MainWindow extends TestWindow { + public MainWindow(Frame f) { + super(f); + ComponentLeakTest.initWindow(this); + setVisible(true); + + TestPopupMenu popup = new TestPopupMenu("hi"); + add(popup); + popup.show(this, 5, 5); + } +} + +class MainDialog extends TestDialogL { + public MainDialog(Frame f) { + super(f, "MainDialog", false); + ComponentLeakTest.initWindow(this); + setVisible(true); + + TestPopupMenu popup = new TestPopupMenu("hi"); + add(popup); + popup.show(this, 5, 5); + } +} + +class MainFrame extends TestFrame { + public MainFrame(){ + super("Component Leak Test MainFrame"); + + ComponentLeakTest.initWindow(this); + + TestMenu menu = new TestMenu("Print"); + TestMenu menu2 = new TestMenu("File"); + TestMenu menu3 = new TestMenu("Edit"); + TestMenu menu4 = new TestMenu("ReallyReallyReallyReallyReallyReallyReallyReally" + + "ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLong"); + menu2.setFont(new Font("SansSerif", Font.BOLD, 20)); + menu2.setEnabled(false); + menu3.setFont(new Font("Monospaced", Font.ITALIC, 18)); + menu3.setEnabled(false); + menu4.setEnabled(false); + TestMenuItem itemPrinter = new TestMenuItem("foobar"); + TestMenuItem itemScreen = new TestMenuItem("baz"); + TestCheckboxMenuItem itemCheck = new TestCheckboxMenuItem("yep"); + menu.add(itemPrinter); + menu.add(itemScreen); + menu.add(itemCheck); + TestMenuBar menuBar = new TestMenuBar(); + menuBar.add( menu ); + menuBar.add( menu2 ); + menuBar.add( menu3 ); + menuBar.add( menu4 ); + setMenuBar(menuBar); + + setVisible(true); + + TestPopupMenu popup = new TestPopupMenu("hi"); + add(popup); + popup.show(this, 5, 5); + } +} diff --git a/test/jdk/java/awt/Component/ComponentSerializationTest/ComponentSerializationTest.java b/test/jdk/java/awt/Component/ComponentSerializationTest/ComponentSerializationTest.java new file mode 100644 index 00000000000..ddf7efffdbd --- /dev/null +++ b/test/jdk/java/awt/Component/ComponentSerializationTest/ComponentSerializationTest.java @@ -0,0 +1,354 @@ +/* + * Copyright (c) 1998, 2024, 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 4146452 + * @summary Tests serialization of peered and lightweight Components. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual ComponentSerializationTest + */ + +import java.awt.Button; +import java.awt.Canvas; +import java.awt.Checkbox; +import java.awt.CheckboxMenuItem; +import java.awt.Choice; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.FileDialog; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Label; +import java.awt.List; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.Panel; +import java.awt.ScrollPane; +import java.awt.Scrollbar; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import javax.swing.JPanel; + +public class ComponentSerializationTest extends JPanel { + private MainFrame mf; + private MainWindow mw; + private MainDialog md; + private MainFileDialog mfd; + private static final String INSTRUCTIONS = """ + A Frame, a Window, and a Dialog should appear. From the Frame's + "Serialize" menu, select "Serialize!". Another Frame, Window, and + Dialog should appear exactly on top of the existing ones. The state + and functionality of the two sets of Windows should be identical. If + any errors or exceptions appear in the log area, or if the second set of + Windows is different from the first, the test fails. Otherwise, the + test passes. + """; + + private static final ArrayList toDispose = new ArrayList<>(); + + public ComponentSerializationTest() { + mf = new MainFrame(); + toDispose.add(mf); + mw = new MainWindow(mf); + toDispose.add(mw); + md = new MainDialog(mf); + toDispose.add(md); + mfd = new MainFileDialog(mf); + toDispose.add(mfd); + } + + public static void main(String[] argc) throws InterruptedException, + InvocationTargetException { + PassFailJFrame.builder() + .title("Component Serialization Test") + .splitUI(ComponentSerializationTest::new) + .instructions(INSTRUCTIONS) + .columns(40) + .logArea() + .build() + .awaitAndCheck(); + for (Window w : toDispose) { + if (w != null) { + EventQueue.invokeAndWait(w::dispose); + } + } + } + + private void initWindow(Window w) { + w.setSize(600, 400); + w.setLayout(new FlowLayout()); + + // peered components + w.add(new Button("Button")); + w.add(new TestCanvas()); + w.add(new Checkbox("Checkbox", true)); + Choice choice = new Choice(); + choice.add("Choice 1"); + choice.add("Choice Two"); + w.add(choice); + w.add(new Label("Label")); + List list = new List(); + list.add("List 1"); + list.add("List Two"); + w.add(list); + w.add(new Scrollbar(Scrollbar.VERTICAL)); + w.add(new Scrollbar(Scrollbar.HORIZONTAL)); + ScrollPane scrollpane = new ScrollPane(); + scrollpane.add(new Button("Button in a scrollpane")); + w.add(scrollpane); + w.add(new TextArea("TextArea", 3, 30)); + w.add(new TextField("TextField")); + + // nested components + Panel panel1 = new Panel(); + panel1.setLayout(new FlowLayout()); + panel1.setBackground(Color.red); + w.add(panel1); + + panel1.add(new Button("level 2")); + + Panel panel2 = new Panel(); + panel2.setLayout(new FlowLayout()); + panel2.setBackground(Color.green); + panel1.add(panel2); + + panel2.add(new Button("level 3")); + + // lightweight components + w.add(new LWButton("LWbutton") ); + + // overlapping components + w.add(new ZOrderPanel()); + } + + class MainWindow extends Window { + public MainWindow(Frame f) { + super(f); + initWindow(this); + setLocation(650, 0); + setVisible(true); + } + } + + class MainDialog extends Dialog { + public MainDialog(Frame f) { + super(f, "MainDialog", false); + initWindow(this); + setLocation(0, 450); + setVisible(true); + } + } + + class MainFileDialog extends FileDialog { + public MainFileDialog(Frame f) { + super(f, "MainFileDialog", FileDialog.SAVE); + setLocation(650, 450); + addNotify(); + } + } + + class MainFrame extends Frame { + public MainFrame() { + super("ComponentSerializationTest"); + initWindow(this); + + Menu menu = new Menu("Serialize"); + Menu menu2 = new Menu("File"); + Menu menu3 = new Menu("Edit"); + Menu menu4 = new Menu("ReallyReallyReallyReallyReallyReallyReallyReally" + + "ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLong"); + menu2.setFont(new Font("SansSerif", Font.BOLD, 20)); + menu2.setEnabled(false); + menu3.setFont(new Font("Monospaced", Font.ITALIC, 18)); + menu3.setEnabled(false); + menu4.setEnabled(false); + MenuItem itemSerialize = new MenuItem("Serialize!"); + CheckboxMenuItem itemCheck = new CheckboxMenuItem("Check me"); + menu.add(itemSerialize); + menu.add(itemCheck); + MenuBar menuBar = new MenuBar(); + menuBar.add(menu); + menuBar.add(menu2); + menuBar.add(menu3); + menuBar.add(menu4); + setMenuBar(menuBar); + + itemSerialize.addActionListener(new ActionSerialize()); + + setLocation(0, 0); + setVisible(true); + } + } + + class ActionSerialize implements ActionListener { + public void actionPerformed(ActionEvent ev) { + Frame f2 = null; + Window w2 = null; + Dialog d2 = null; + FileDialog fd2 = null; + + try { + FileOutputStream fos = new FileOutputStream("tmp"); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(mf); + oos.writeObject(mw); + oos.writeObject(md); + oos.writeObject(mfd); + oos.flush(); + + FileInputStream fis = new FileInputStream("tmp"); + ObjectInputStream ois = new ObjectInputStream(fis); + f2 = (Frame)ois.readObject(); + w2 = (Window)ois.readObject(); + d2 = (Dialog)ois.readObject(); + fd2= (FileDialog)ois.readObject(); + } catch (Exception e) { + PassFailJFrame.log(e.getMessage()); + } + + if (f2 == null || w2 == null || d2 == null || fd2 == null) { + PassFailJFrame.log("ERROR: one of the components was not deserialized."); + PassFailJFrame.log("frame = " + f2); + PassFailJFrame.log("window = " + w2); + PassFailJFrame.log("dialog = " + d2); + PassFailJFrame.log("file dalog = " + fd2); + } + + if (f2 != null) { + toDispose.add(f2); + f2.setVisible(true); + } + if (w2 != null) { + toDispose.add(w2); + w2.setVisible(true); + } + if (d2 != null) { + toDispose.add(d2); + d2.setVisible(true); + } + if (fd2 != null) { + toDispose.add(fd2); + fd2.addNotify(); + } + } + } + + class LWButton extends Component { + String label; + int width = 100; + int height = 30; + + public LWButton(String label) { + super(); + this.label = label; + } + + public void paint(Graphics g) { + Dimension d = getSize(); + g.setColor(Color.orange); + g.fillRect(0, 0, d.width, d.height); + g.setColor(Color.black); + int x = 5; + int y = (d.height - 5); + g.drawString(label, x, y); + } + + public Dimension getPreferredSize() { + return new Dimension(width, height); + } + } + + class TestCanvas extends Canvas { + int width = 100; + int height = 100; + + public void paint(Graphics g) { + g.setColor(Color.blue); + g.fillRoundRect(10, 10, 50, 50, 15, 30); + g.setColor(Color.red); + g.fillOval(70, 70, 25, 25); + } + public Dimension getPreferredSize() { + return new Dimension(width, height); + } + } + + class ZOrderPanel extends Panel { + public ZOrderPanel() { + setLayout(null); + + Component first, second, third, fourth; + + show(); + first = makeBox("Second", Color.blue, -1); + second = makeBox("First", Color.yellow, 0); + fourth = makeBox("Fourth", Color.red, 2); + third = makeBox("Third", Color.green, 3); + remove(third); + add(third, 2); + validate(); + add(new LWButton("LWButton"), 0); + } + + public Dimension preferredSize() { + return new Dimension(260, 80); + } + + public void layout() { + int i, n; + Insets ins = insets(); + n = countComponents(); + for (i = n - 1; i >= 0; i--) { + Component p = getComponent(i); + p.reshape(ins.left + 40 * i, ins.top + 5 * i, 60, 60); + } + } + + public Component makeBox(String s, Color c, int index) { + Label l = new Label(s); + l.setBackground(c); + l.setAlignment(Label.RIGHT); + add(l, index); + validate(); + return l; + } + } +} diff --git a/test/jdk/java/awt/Component/FlickeringOnScroll/FlickeringOnScroll.java b/test/jdk/java/awt/Component/FlickeringOnScroll/FlickeringOnScroll.java new file mode 100644 index 00000000000..2119ae7bcc0 --- /dev/null +++ b/test/jdk/java/awt/Component/FlickeringOnScroll/FlickeringOnScroll.java @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2005, 2024, 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 6347994 + * @summary REG: Scrollbar, Choice, Checkbox flickers and grays out when scrolling, XToolkit + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FlickeringOnScroll + */ + +import java.awt.BorderLayout; +import java.awt.Checkbox; +import java.awt.Choice; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.MenuItem; +import java.awt.Panel; +import java.awt.PopupMenu; +import java.awt.Scrollbar; +import java.awt.TextArea; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.lang.reflect.InvocationTargetException; + +public class FlickeringOnScroll extends Frame { + + static final String INSTRUCTIONS = """ + There are five components in the frame: + Scrollbars(vertical and horizontal), a Choice, + a Checkbox and a TextArea + 1) Drag the thumbs of each Scrollbar. + 2) Do the same with Choice's scrollbar. + 3) Focus on Checkbox and press left mouse button or SPACE repeatedly. + 4) Right click inside TextArea and navigate through all menu items + in PopupMenu using the arrow keys. + If you notice some component or its scrollbar flickers on + key/mouse press or drag, press Fail. Otherwise press Pass. + """; + + public FlickeringOnScroll() { + Choice ch = new Choice(); + ch.add("Praveen"); + ch.add("Mohan"); + ch.add("Rakesh"); + ch.add("Menon"); + ch.add("Girish"); + ch.add("Ramachandran"); + ch.add("Elancheran"); + ch.add("Subramanian"); + ch.add("Raju"); + ch.add("Pallath"); + ch.add("Mayank"); + ch.add("Joshi"); + ch.add("Sundar"); + ch.add("Srinivas"); + ch.add("Mandalika"); + Checkbox chb = new Checkbox ("Checkbox", false); + TextArea ta = new TextArea("Text Area"); + Panel panel = new Panel(); + PopupMenu popup = new PopupMenu("Popup"); + MenuItem mi1 = new MenuItem("mi1"); + MenuItem mi2 = new MenuItem("mi2"); + MenuItem mi3 = new MenuItem("mi3"); + MenuItem mi4 = new MenuItem("mi4"); + + setTitle("Flickering Scroll Area Testing Frame"); + setLayout(new FlowLayout()); + add(ch); + add(chb); + add(ta); + + panel.setLayout(new BorderLayout()); + panel.setPreferredSize(new Dimension(200, 200)); + add(panel); + panel.add("Center",new java.awt.Label("Scrollbar flickering test..." ,java.awt.Label.CENTER)); + panel.add("South",new Scrollbar(Scrollbar.HORIZONTAL, 0, 100, 0, 255)); + panel.add("East",new Scrollbar(Scrollbar.VERTICAL, 0, 100, 0, 255)); + + ta.add(popup); + popup.add (mi1); + popup.add (mi2); + popup.add (mi3); + popup.add (mi4); + + ta.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent me) { + if (me.isPopupTrigger()) { + if (popup != null) { + popup.show(me.getComponent(), me.getX(), me.getY()); + } + } + } + public void mouseReleased(MouseEvent me) { + if (me.isPopupTrigger()) { + if (popup != null) { + popup.show(me.getComponent(), me.getX(), me.getY()); + } + } + } + }); + + pack(); + } + + public static void main(String[] args) throws InterruptedException, + InvocationTargetException { + PassFailJFrame.builder() + .title("Scroll Area Flickering Repaint") + .testUI(FlickeringOnScroll::new) + .instructions(INSTRUCTIONS) + .columns(40) + .logArea() + .build() + .awaitAndCheck(); + } +} diff --git a/test/jdk/java/awt/Component/FocusRepaintTest/FocusRepaintTest.java b/test/jdk/java/awt/Component/FocusRepaintTest/FocusRepaintTest.java new file mode 100644 index 00000000000..ecffdfda613 --- /dev/null +++ b/test/jdk/java/awt/Component/FocusRepaintTest/FocusRepaintTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 1997, 2024, 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 4079435 + * @summary Calling repaint() in focus handlers messes up the window. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FocusRepaintTest + */ + +import java.awt.Button; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.lang.reflect.InvocationTargetException; + +public class FocusRepaintTest extends Frame implements FocusListener { + static final String INSTRUCTIONS = """ + Hit the tab key repeatedly in the Test window. + If any of the buttons disappear press Fail, otherwise press Pass. + """; + + public FocusRepaintTest() { + setTitle("Test"); + setLayout(new FlowLayout()); + setSize(200, 100); + Button b1 = new Button("Close"); + Button b2 = new Button("Button"); + add(b1); + add(b2); + b1.setSize(50, 30); + b2.setSize(50, 30); + b1.addFocusListener(this); + b2.addFocusListener(this); + } + + public void focusGained(FocusEvent e) { + Button b = (Button) e.getSource(); + PassFailJFrame.log("Focus gained for " + b.getLabel()); + b.repaint(); + } + + public void focusLost(FocusEvent e) { + Button b = (Button) e.getSource(); + PassFailJFrame.log("Focus lost for " + b.getLabel()); + b.repaint(); + } + + public static void main(String[] args) throws InterruptedException, + InvocationTargetException { + PassFailJFrame.builder() + .title("Focus Repaint") + .testUI(FocusRepaintTest::new) + .instructions(INSTRUCTIONS) + .columns(40) + .logArea() + .build() + .awaitAndCheck(); + } +} diff --git a/test/jdk/java/awt/Component/ListDoubleIndentTest/ListDoubleIndentTest.java b/test/jdk/java/awt/Component/ListDoubleIndentTest/ListDoubleIndentTest.java new file mode 100644 index 00000000000..4c6c1248950 --- /dev/null +++ b/test/jdk/java/awt/Component/ListDoubleIndentTest/ListDoubleIndentTest.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 1998, 2024, 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 4185460 + * @summary Container list the indentation is 2x the indent param value + * @key headful + * @run main ListDoubleIndentTest + */ + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.EventQueue; +import java.awt.Frame; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.PipedInputStream; +import java.io.PrintStream; +import java.io.PipedOutputStream; + +import java.lang.reflect.InvocationTargetException; +import java.util.Vector; + +public class ListDoubleIndentTest { + public static void main(final String[] args) throws InterruptedException, + InvocationTargetException { + EventQueue.invokeAndWait(new ListDoubleIndentTest()::performTest); + } + + public void performTest() { + boolean bReturn = false; + int iCompCount = 0; + int iNotEqual = 0; + int iIndentWrong = 0; + System.out.println("Test: Check indentation"); + Vector v = new Vector(); + String sLine; + String sReturn; + String sExpTrim; + Button b1, b2, b3, b4, b5; + Frame f = null; + + try { + f = new Frame("ListDoubleIndentTest"); + + f.add(b1 = new Button("North"), BorderLayout.NORTH, 0); + f.add(b2 = new Button("South"), BorderLayout.SOUTH, 1); + f.add(b3 = new Button("East"), BorderLayout.EAST, 2); + f.add(b4 = new Button("West"), BorderLayout.WEST, 3); + f.add(b5 = new Button("Center"), BorderLayout.CENTER, -1); + + String[] sExpected = {f.toString(), b1.toString(), b2.toString(), + b3.toString(), b4.toString(), b5.toString()}; + + iCompCount = f.getComponentCount(); + System.out.println("Component count: " + iCompCount); + + for (int j = 0; j <= 10; j++) { + PipedInputStream pin = new PipedInputStream(); + PrintStream output = new PrintStream(new PipedOutputStream(pin), true); + BufferedReader input = new BufferedReader(new InputStreamReader(pin)); + + f.list(output, j); + + output.flush(); + output.close(); + + while ((sLine = input.readLine()) != null) { + v.addElement(sLine); + } + + for (int i = 0; i < v.size(); i++) { + sReturn = (String)v.elementAt(i); + sExpTrim = sExpected[i].trim(); + + if (!(sExpTrim.equals(sReturn.trim()))) { + System.out.println("iNotEqual"); + ++iNotEqual; + } + + int iSpace = sReturn.lastIndexOf(' ') + 1; + + if (i == 0) { + System.out.println("Indent set at: " + j); + System.out.println("Indent return: " + iSpace); + if (iSpace != j) { + System.out.println("iIndentWrong1"); + ++iIndentWrong; + } + } else { + if (iSpace != (j + 1)) { + System.out.println(iSpace + "; " + j); + ++iIndentWrong; + } + } + System.out.println(sReturn); + } + v.removeAllElements(); + v.trimToSize(); + } + + if (iNotEqual == 0 && iIndentWrong == 0) { + bReturn = true; + } else { + bReturn = false; + } + + } catch(IOException e) { + bReturn = false; + System.out.println ("Unexpected Exception thrown: " + e.getMessage()); + e.printStackTrace(); + } finally { + if (f != null) { + f.dispose(); + } + } + + if (bReturn) { + System.out.println("Test for Container.list Passed"); + } else { + System.out.println("Test for Container.list Failed"); + throw new RuntimeException("Test FAILED"); + } + } +} diff --git a/test/jdk/java/awt/Component/MinMaxSizeDefensive/GetSizesTest.java b/test/jdk/java/awt/Component/MinMaxSizeDefensive/GetSizesTest.java new file mode 100644 index 00000000000..2b495487938 --- /dev/null +++ b/test/jdk/java/awt/Component/MinMaxSizeDefensive/GetSizesTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2003, 2024, 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 4783989 + @summary get(Preferred|Minimum|Maximum)Size() must not return a reference. + The object copy of Dimension class needed. + @key headful + @run main GetSizesTest +*/ + +import java.awt.Button; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Frame; +import java.lang.reflect.InvocationTargetException; + +public class GetSizesTest extends Frame { + Button b; + + public static void main(final String[] args) throws InterruptedException, + InvocationTargetException { + GetSizesTest app = new GetSizesTest(); + EventQueue.invokeAndWait(() -> { + try { + app.init(); + app.start(); + } finally { + app.dispose(); + } + }); + } + + public void init() { + b = new Button("button"); + add(b); + } + + public void start () { + setSize(200, 200); + setLocationRelativeTo(null); + setVisible(true); + validate(); + + System.out.println("Test set for Container (Frame)."); + + Dimension dimPref = getPreferredSize(); + dimPref.setSize(101, 101); + if (getPreferredSize().equals(new Dimension(101, 101))) { + throw new RuntimeException("Test Failed for: " + dimPref); + } + System.out.println("getPreferredSize() Passed."); + + Dimension dimMin = getMinimumSize(); + dimMin.setSize(101, 101); + if (getMinimumSize().equals(new Dimension(101, 101))) { + throw new RuntimeException("Test Failed for: " + dimMin); + } + System.out.println("getMinimumSize() Passed."); + + Dimension dimMax = getMaximumSize(); + dimMax.setSize(101, 101); + if (getMaximumSize().equals(new Dimension(101, 101))) { + throw new RuntimeException("Test Failed for: " + dimMax); + } + System.out.println("getMaximumSize() Passed."); + + System.out.println("Test set for Component (Button)."); + + dimPref = b.getPreferredSize(); + dimPref.setSize(33, 33); + if (b.getPreferredSize().equals(new Dimension(33, 33))) { + throw new RuntimeException("Test Failed for: " + dimPref); + } + System.out.println("getPreferredSize() Passed."); + + dimMin = b.getMinimumSize(); + dimMin.setSize(33, 33); + if (b.getMinimumSize().equals(new Dimension(33, 33))) { + throw new RuntimeException("Test Failed for: " + dimMin); + } + System.out.println("getMinimumSize() Passed."); + + dimMax = b.getMaximumSize(); + dimMax.setSize(33, 33); + if (b.getMaximumSize().equals(new Dimension(33, 33))) { + throw new RuntimeException("Test Failed for: " + dimMax); + } + System.out.println("getMaximumSize() Passed."); + System.out.println("GetSizesTest Succeeded."); + } +} diff --git a/test/jdk/java/awt/Component/ZOrderTest/ZOrderTest.java b/test/jdk/java/awt/Component/ZOrderTest/ZOrderTest.java new file mode 100644 index 00000000000..15003f753a6 --- /dev/null +++ b/test/jdk/java/awt/Component/ZOrderTest/ZOrderTest.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 1997, 2024, 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 4059430 + * @summary Test for component z-ordering consistency + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual ZOrderTest + */ + +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.Insets; +import java.awt.Label; +import java.awt.Panel; +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +public class ZOrderTest { + public final static String INSTRUCTIONS = """ + The ZOrderTest creates two frames. + - Frame 1 has components added to an intermediate panel + - Frame 2 has components added directly to the frame itself + Verify that the components are in the correct z-order. Lower numbered + components should overlap higher numbered ones (e.g. component zero should + appear on top of component one). + Both frames should have the same component ordering, and this ordering should + be the same on all supported operating systems. + """; + + public static void main(String [] args) throws InterruptedException, + InvocationTargetException { + PassFailJFrame.builder() + .title("Component ZOrder Test") + .testUI(ZOrderTest::makeFrames) + .instructions(INSTRUCTIONS) + .columns(40) + .logArea() + .build() + .awaitAndCheck(); + } + + private static List makeFrames() { + Frame frame, frame2; + + // test adding components to panel on a frame + frame = new Frame("ZOrderTest(1) for 4059430"); + frame.pack(); + frame.show(); + Panel panel = new ZOrderPanel(); + frame.setBounds(0, 0, 500, 350); + frame.setLayout(new GridLayout()); + frame.add(panel); + doTest(panel); + + // test adding components directly to frame + frame2 = new ZOrderTestFrame("ZOrderTest(2) for 4059430"); + frame2.pack(); + frame2.show(); + frame2.setBounds(80, 80, 500, 350); + doTest(frame2); + + return List.of(frame, frame2); + } + + /* + * This tests various boundary conditions with z-ordering + * - inserting at the top of the z-order + * - inserting at the bottom of the z-order + * - inserting in the middle of the z-order + */ + private static void doTest(Container cont) { + Component compZero, compOne, compTwo, compThree, compFour; + + compZero = makeBox(cont, "Comp One", Color.blue, -1); + // insert on top + compOne = makeBox(cont, "Comp Zero", Color.yellow, 0); + // put at the back + compThree = makeBox(cont, "Comp Three", Color.red, 2); + // insert in last position + compTwo = makeBox(cont, "Comp Two", Color.green, 3); + // swap compTwo and compThree to correct positions + cont.remove(compTwo); + cont.add(compTwo, 2); + // one more test of adding to the end + compFour = makeBox(cont, "Comp Four", Color.magenta, -1); + // re-validate so components cascade into proper place + cont.validate(); + } + + private static Component makeBox(Container cont, String s, Color c, int index) { + Label l = new Label(s); + l.setBackground(c); + l.setAlignment(Label.RIGHT); + if (index == -1) { + cont.add(l); // semantically equivalent to -1, but why not test this too + } else { + cont.add(l, index); + } + cont.validate(); + return l; + } + + /** + * Cascades components across the container so + * that they overlap, demonstrating their z-ordering + */ + static void doCascadeLayout(Container cont) { + int i, n; + Insets ins = cont.insets(); + n = cont.countComponents(); + for (i = n - 1; i >= 0; i--) { + Component comp = cont.getComponent(i); + comp.reshape(ins.left + 75 * i, ins.top + 30 * i, 100, 100); + } + } +} + +class ZOrderPanel extends Panel { + public void layout() { + ZOrderTest.doCascadeLayout(this); + } +} + +class ZOrderTestFrame extends Frame +{ + public ZOrderTestFrame(String title) { + super(title); + } + + public void layout() { + ZOrderTest.doCascadeLayout(this); + } +} diff --git a/test/jdk/java/awt/DesktopProperties/FontSmoothing.java b/test/jdk/java/awt/DesktopProperties/FontSmoothing.java new file mode 100644 index 00000000000..d3879d4893f --- /dev/null +++ b/test/jdk/java/awt/DesktopProperties/FontSmoothing.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2003, 2024, 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. + */ + +import java.awt.Frame; +import java.awt.Toolkit; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +/* + * @test + * @bug 4808569 + * @requires (os.family == "windows") + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @summary add desktop property for the Windows XP or later font smoothing settings + * @run main/manual FontSmoothing + */ + +public class FontSmoothing { + + private static final String PROP_NAME = "win.text.fontSmoothingType"; + + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + This test should be run on Windows XP or later. + + On Windows 11: + 1. Open Run dialog by typing 'run' in search bar. + 2. Type 'cttune' and press Ok. + 3. Uncheck the "Turn On ClearType" checkbox and follow next instructions on screen. + 4. Repeat Step 1-2. + 5. Check the "Turn On ClearType" checkbox and follow next instructions on screen. + 6. Take a look at the output window to determine if the test passed or failed. + """; + + PassFailJFrame.builder() + .title("FontSmoothing Test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(40) + .testTimeOut(5) + .testUI(FontSmoothing::createUI) + .logArea(8) + .build() + .awaitAndCheck(); + } + + private static Frame createUI() { + Frame f = new Frame("FontSmoothing Test"); + f.setSize(50, 50); + + Object value = Toolkit.getDefaultToolkit().getDesktopProperty(PROP_NAME); + PassFailJFrame.log("toolkit.getDesktopProperty: " + PROP_NAME + " = " + value + "\n"); + + Toolkit.getDefaultToolkit().addPropertyChangeListener(PROP_NAME, new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent e) { + PassFailJFrame.log("PropertyChangeEvent: " + e.getPropertyName() + + "\n old value=" + e.getOldValue() + + "\n new value=" + e.getNewValue()); + + Integer value = (Integer) Toolkit.getDefaultToolkit().getDesktopProperty(PROP_NAME); + PassFailJFrame.log("toolkit.getDesktopProperty:" + PROP_NAME + "=" + value); + + if (value.equals((Integer) e.getNewValue())) { + PassFailJFrame.log("test PASSED"); + } else { + PassFailJFrame.log("test FAILED"); + } + } + }); + return f; + } +} diff --git a/test/jdk/java/awt/DesktopProperties/ThreeDBackgroundColor.java b/test/jdk/java/awt/DesktopProperties/ThreeDBackgroundColor.java new file mode 100644 index 00000000000..26792e79a92 --- /dev/null +++ b/test/jdk/java/awt/DesktopProperties/ThreeDBackgroundColor.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2000, 2024, 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. + */ + +import java.awt.Color; +import java.awt.Frame; +import java.awt.Toolkit; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +/* + * @test + * @bug 4368193 + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @requires (os.family == "windows") + * @summary Toolkit's getDesktopProperty returns stale values on Microsoft Windows + * @run main/manual ThreeDBackgroundColor + */ + +public class ThreeDBackgroundColor { + + private static final String PROP_NAME = "win.3d.backgroundColor"; + + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + On Windows 10: + 1. Open Windows Settings, in the search bar type + 'high contrast', in the list of suggestions choose option + 'Turn high contrast on or off' + 2. In the High contrast control panel click on the on/off switch + to initialize High contrast mode + 3. Wait for the High contrast mode to finish initialization + 4. Click on the same switch again to turn off High contrast mode + + On Windows 11: + 1. Open Windows settings, in the search bar type + 'Contrast Theme'. + 2. Select any value from 'Contrast themes' dropdown menu and press 'Apply'. + 3. Wait for the High contrast mode to finish initialization + 4. Select 'None' from 'Contrast themes' dropdown menu to revert the changes. + + Take a look at the output window to determine if the test passed or failed."""; + + PassFailJFrame.builder() + .title("ThreeDBackgroundColor Test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(40) + .testTimeOut(5) + .testUI(ThreeDBackgroundColor::createUI) + .logArea(8) + .build() + .awaitAndCheck(); + } + + private static Frame createUI() { + Frame f = new Frame("ThreeDBackgroundColor Test"); + f.setSize(50, 50); + + Object value = Toolkit.getDefaultToolkit().getDesktopProperty(PROP_NAME); + PassFailJFrame.log("toolkit.getDesktopProperty:" + PROP_NAME + "=" + value); + + Toolkit.getDefaultToolkit().addPropertyChangeListener(PROP_NAME, new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent e) { + PassFailJFrame.log("PropertyChangeEvent: " + e.getPropertyName() + + "\n old value=" + e.getOldValue() + + "\n new value=" + e.getNewValue()); + + Color value = (Color) Toolkit.getDefaultToolkit().getDesktopProperty(PROP_NAME); + PassFailJFrame.log("toolkit.getDesktopProperty:" + PROP_NAME + "=" + value); + if (value.equals((Color) e.getNewValue())) { + PassFailJFrame.log("test PASSED"); + } else { + PassFailJFrame.log("test FAILED"); + } + } + }); + return f; + } +} diff --git a/test/jdk/java/awt/FileDialog/KeyboardInteractionTest.java b/test/jdk/java/awt/FileDialog/KeyboardInteractionTest.java new file mode 100644 index 00000000000..f919a8a338a --- /dev/null +++ b/test/jdk/java/awt/FileDialog/KeyboardInteractionTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2005, 2024, 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. + */ + +import java.awt.Button; +import java.awt.FileDialog; +import java.awt.Frame; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/* + * @test + * @bug 6259434 + * @summary PIT: Choice in FileDialog is not responding to keyboard interactions, XToolkit + * @requires (os.family == "linux") + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual KeyboardInteractionTest + */ + +public class KeyboardInteractionTest { + public static void main(String[] args) throws Exception { + System.setProperty("sun.awt.disableGtkFileDialogs", "true"); + String INSTRUCTIONS = """ + 1) Click on 'Show File Dialog' button to bring up the FileDialog window. + A file dialog will come up. + 2) You will see a text field 'Enter full path or filename'. + Right next to it, you will see a button. + Transfer the focus on this button using 'TAB'. + Make sure that the popup choice is not shown. + 3) Press 'ESC'. If file dialog isn't disposed, then the test failed. + 4) Again, click on 'Show File Dialog' to bring up the file dialog. + A file dialog will come up. + 5) You will see a text field 'Enter full path or filename'. + Right next to it, you will see a button. + Click on this button. The popup choice will appear. + 6) Look at the popup choice. Change the current item in the popup + choice by the arrow keys. + If the text in the 'Enter full path or filename' text field isn't + changed, then the test failed. + 7) The test passed. + """; + + PassFailJFrame.builder() + .title("KeyboardInteractionTest Instruction") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(KeyboardInteractionTest::createUI) + .build() + .awaitAndCheck(); + } + + public static Frame createUI() { + Frame f = new Frame("KeyboardInteractionTest Test"); + Button b = new Button("Show File Dialog"); + FileDialog fd = new FileDialog(f); + b.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + fd.setVisible(true); + } + }); + f.add(b); + f.setSize(300, 200); + return f; + } +} diff --git a/test/jdk/java/awt/FileDialog/PathChoiceDisposeTest.java b/test/jdk/java/awt/FileDialog/PathChoiceDisposeTest.java new file mode 100644 index 00000000000..267b2a807cf --- /dev/null +++ b/test/jdk/java/awt/FileDialog/PathChoiceDisposeTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2005, 2024, 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. + */ + +import java.awt.Button; +import java.awt.FileDialog; +import java.awt.Frame; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/* + * @test + * @bug 6240084 + * @summary Test that disposing unfurled list by the pressing ESC + * in FileDialog is working properly on XToolkit + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual PathChoiceDisposeTest + */ + +public class PathChoiceDisposeTest { + public static void main(String[] args) throws Exception { + System.setProperty("sun.awt.disableGtkFileDialogs", "true"); + String INSTRUCTIONS = """ + 1) Click on 'Show File Dialog' button to bring up the FileDialog window. + 2) Open the directory selection choice by clicking button next to + 'Enter Path or Folder Name'. A drop-down will appear. + 3) Press 'ESC'. + 4) If you see that the dialog gets disposed and the popup + still remains on the screen, the test failed, otherwise passed. + """; + + PassFailJFrame.builder() + .title("PathChoiceDisposeTest Instruction") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(PathChoiceDisposeTest::createUI) + .build() + .awaitAndCheck(); + } + + public static Frame createUI() { + Frame f = new Frame("PathChoiceDisposeTest Test"); + Button b = new Button("Show File Dialog"); + FileDialog fd = new FileDialog(f); + b.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + fd.setVisible(true); + } + }); + f.add(b); + f.setSize(300, 200); + return f; + } +} diff --git a/test/jdk/java/awt/FileDialog/PathChoiceWorkArrowsTest.java b/test/jdk/java/awt/FileDialog/PathChoiceWorkArrowsTest.java new file mode 100644 index 00000000000..17aee8abb80 --- /dev/null +++ b/test/jdk/java/awt/FileDialog/PathChoiceWorkArrowsTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2005, 2024, 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. + */ + +import java.awt.Button; +import java.awt.FileDialog; +import java.awt.Frame; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/* + * @test + * @bug 6240074 + * @summary Test that file drop-down field in FileDialog is working properly on XToolkit + * @requires (os.family == "linux") + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual PathChoiceWorkArrowsTest + */ + +public class PathChoiceWorkArrowsTest { + public static void main(String[] args) throws Exception { + System.setProperty("sun.awt.disableGtkFileDialogs", "true"); + String INSTRUCTIONS = """ + This is only XAWT test. + + 1) Click on 'Show File Dialog' to bring up the FileDialog window. + A file dialog would come up. + 2) Click on the button next to 'Enter folder name' field. + A drop-down will appear. After this, there are 2 scenarios. + 3) Press the down arrow one by one. You will see a '/' being + appended as soon as the current entry is removed. + Keep pressing till the last entry is reached. Now the drop-down + will stop responding to arrow keys. If yes, the test failed. + 4) Press the up arrow. The cursor will directly go to the last + entry ('/') and navigation will stop there. You will see 2 + entries being selected at the same time. + If yes, the test failed. + """; + + PassFailJFrame.builder() + .title("PathChoiceWorkArrowsTest Instruction") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(PathChoiceWorkArrowsTest::createUI) + .build() + .awaitAndCheck(); + } + + public static Frame createUI() { + Frame f = new Frame("PathChoiceWorkArrowsTest Test"); + Button b = new Button("Show File Dialog"); + FileDialog fd = new FileDialog(f); + b.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + fd.setSize(200, 200); + fd.setLocation(200, 200); + fd.setVisible(true); + } + }); + f.add(b); + f.setSize(300, 200); + return f; + } +} diff --git a/test/jdk/java/awt/FileDialog/SavedDirInitTest.java b/test/jdk/java/awt/FileDialog/SavedDirInitTest.java new file mode 100644 index 00000000000..7a3b33f55fe --- /dev/null +++ b/test/jdk/java/awt/FileDialog/SavedDirInitTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2005, 2024, 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. + */ + +import java.awt.Button; +import java.awt.FileDialog; +import java.awt.Frame; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/* + * @test + * @bug 6260650 + * @summary FileDialog.getDirectory() does not return null when file dialog is cancelled + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual SavedDirInitTest + */ + +public class SavedDirInitTest { + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + Click on 'Show File Dialog' button to bring up the FileDialog window. + 1) A file dialog will come up. + 2) Press 'Cancel' button to cancel the file dialog. + 3) The result (passed or failed) will be shown in the message window below. + """; + + PassFailJFrame.builder() + .title("SavedDirInitTest Instruction") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(SavedDirInitTest::createUI) + .logArea(2) + .build() + .awaitAndCheck(); + } + + public static Frame createUI() { + Frame f = new Frame("SavedDirInitTest Test"); + Button b = new Button("Show File Dialog"); + FileDialog fd = new FileDialog(f); + b.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + fd.setVisible(true); + if (fd.getDirectory() == null && fd.getFile() == null) { + PassFailJFrame.log("TEST PASSED"); + } else { + PassFailJFrame.log("TEST FAILED. dir = " + fd.getDirectory() + + " , file = " + fd.getFile()); + } + } + }); + f.add(b); + f.setSize(300, 200); + return f; + } +} diff --git a/test/jdk/java/awt/Frame/DefaultFrameIconTest.java b/test/jdk/java/awt/Frame/DefaultFrameIconTest.java new file mode 100644 index 00000000000..f8b48c6df2c --- /dev/null +++ b/test/jdk/java/awt/Frame/DefaultFrameIconTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.Window; +import java.util.List; + +/* + * @test + * @bug 4240766 8259023 + * @summary Frame Icon is wrong - should be Coffee Cup or Duke image icon + * @requires (os.family == "windows") + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual DefaultFrameIconTest +*/ + +public class DefaultFrameIconTest { + + private static final String INSTRUCTIONS = """ + You should see a dialog and a frame. + If both have Coffee Cup or Duke image icon in the upper left corner, + the test passes, otherwise it fails. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("DefaultFrameIconTest Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .testUI(DefaultFrameIconTest::createAndShowUI) + .positionTestUIRightRow() + .build() + .awaitAndCheck(); + } + + private static List createAndShowUI() { + Frame testFrame = new Frame("Frame DefaultFrameIconTest"); + Dialog testDialog = new Dialog(testFrame, "Dialog DefaultFrameIconTest"); + + testDialog.setSize(250, 100); + + testFrame.setSize(250, 100); + return List.of(testFrame, testDialog); + } +} diff --git a/test/jdk/java/awt/Frame/DeiconifyClipTest.java b/test/jdk/java/awt/Frame/DeiconifyClipTest.java new file mode 100644 index 00000000000..c650355f3ec --- /dev/null +++ b/test/jdk/java/awt/Frame/DeiconifyClipTest.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2003, 2024, 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. + */ + +/* + * DeiconifyClipTest.java + * + * summary: + * + * What happens is that we call AwtWindow::UpdateInsets when + * processing WM_NCCALCSIZE delivered on programmatic deiconification. + * At this point IsIconic returns false (so UpdateInsets proceeds), + * but the rect sizes still seems to be those weird of the iconic + * state. Based on them we compute insets with top = left = 0 (and + * bottom and right that are completely bogus) and pass them to + * PaintUpdateRgn which results in incorrect clip origin. Immediately + * after that we do UpdateInsets again during WM_SIZE processing and + * get real values. + */ + +import javax.swing.BoxLayout; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Insets; + +/* + * @test + * @bug 4792958 + * @summary Incorrect clip region after programmatic restore + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual DeiconifyClipTest +*/ + +public class DeiconifyClipTest { + private static final String INSTRUCTIONS = """ + This test creates a frame that is automatically iconified/deiconified + in a cycle. + + The test FAILS if after deiconfication the frame has a greyed-out area + in the lower-right corner. + If the frame contents is drawn completely - the test PASSES. + + Press PASS or FAIL button accordingly. + """; + + static TestFrame testFrame; + static volatile boolean shouldContinue = true; + + public static void main(String[] args) throws Exception { + PassFailJFrame passFailJFrame = PassFailJFrame.builder() + .title("DeiconifyClipTest Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .testUI(DeiconifyClipTest::createAndShowUI) + .build(); + try { + runThread(); + } finally { + passFailJFrame.awaitAndCheck(); + shouldContinue = false; + } + } + + private static void runThread() { + new Thread(() -> { + for (int i = 0; i < 1000 && shouldContinue; ++i) { + try { + Thread.sleep(3000); + SwingUtilities.invokeAndWait(() -> { + if ((testFrame.getExtendedState() & Frame.ICONIFIED) + != 0) { + testFrame.setExtendedState(Frame.NORMAL); + } else { + testFrame.setState(Frame.ICONIFIED); + } + }); + } catch (Exception ignored) { + } + } + }).start(); + } + + static Frame createAndShowUI() { + testFrame = new TestFrame(); + testFrame.getContentPane().setLayout(new BoxLayout(testFrame.getContentPane(), + BoxLayout.Y_AXIS)); + testFrame.getContentPane().setBackground(Color.yellow); + testFrame.setSize(300, 300); + return testFrame; + } + + static class TestFrame extends JFrame { + public TestFrame() { + super("DeiconifyClipTest"); + } + + // make it more visible if the clip is wrong. + public void paint(Graphics g) { + Insets b = getInsets(); + Dimension d = getSize(); + + int x = b.left; + int y = b.top; + int w = d.width - x - b.right; + int h = d.height - y - b.bottom; + + g.setColor(Color.white); + g.fillRect(0, 0, d.width, d.height); + + g.setColor(Color.green); + g.drawRect(x, y, w-1, h-1); + g.drawLine(x, y, x+w, y+h); + g.drawLine(x, y+h, x+w, y); + } + } +} diff --git a/test/jdk/java/awt/Frame/DisabledParentOfToplevel.java b/test/jdk/java/awt/Frame/DisabledParentOfToplevel.java new file mode 100644 index 00000000000..878809749d3 --- /dev/null +++ b/test/jdk/java/awt/Frame/DisabledParentOfToplevel.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2004, 2024, 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. + */ + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Point; +import java.awt.Robot; +import java.awt.Window; +import java.awt.event.InputEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/* + * @test + * @bug 5062118 + * @key headful + * @summary Disabling of a parent should not disable Window. + * @run main DisabledParentOfToplevel + */ + +public class DisabledParentOfToplevel { + private static Button okBtn; + private static Window ww; + private static Frame parentFrame; + private static volatile Point p; + private static volatile Dimension d; + + public static void main(String[] args) throws Exception { + Robot robot = new Robot(); + robot.setAutoDelay(100); + try { + EventQueue.invokeAndWait(() -> { + createAndShowUI(); + }); + robot.delay(1000); + EventQueue.invokeAndWait(() -> { + p = okBtn.getLocationOnScreen(); + d = okBtn.getSize(); + }); + robot.mouseMove(p.x + d.width / 2, p.x + d.height / 2); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.delay(500); + if (ww.isVisible()) { + throw new RuntimeException("Window is visible but should be hidden: failure."); + } + } finally { + EventQueue.invokeAndWait(() -> { + if (parentFrame != null) { + parentFrame.dispose(); + } + }); + } + } + + private static void createAndShowUI() { + parentFrame = new Frame("parentFrame"); + parentFrame.setSize(100, 100); + parentFrame.setEnabled(false); + ww = new Window(parentFrame); + ww.setLayout(new BorderLayout()); + okBtn = new Button("Click to Close Me"); + ww.add(okBtn); + ww.setSize(250, 250); + ww.setLocation(110, 110); + okBtn.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent me) { + System.out.println("Pressed: close"); + ww.setVisible(false); + } + }); + parentFrame.setVisible(true); + ww.setVisible(true); + okBtn.requestFocus(); + } +} diff --git a/test/jdk/java/awt/Frame/DisposeTest.java b/test/jdk/java/awt/Frame/DisposeTest.java new file mode 100644 index 00000000000..08c0def638e --- /dev/null +++ b/test/jdk/java/awt/Frame/DisposeTest.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 1998, 2024, 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. + */ + +import javax.imageio.ImageIO; +import java.awt.Color; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +/* + * @test + * @key headful + * @bug 4127271 + * @summary Tests that disposing of a Frame with MenuBar removes all traces + * of the Frame from the screen. + */ + +public class DisposeTest { + private static Frame backgroundFrame; + private static Frame testedFrame; + + private static final Rectangle backgroundFrameBounds = + new Rectangle(100, 100, 200, 200); + private static final Rectangle testedFrameBounds = + new Rectangle(150, 150, 100, 100); + + private static Robot robot; + + public static void main(String[] args) throws Exception { + robot = new Robot(); + try { + EventQueue.invokeAndWait(DisposeTest::initAndShowGui); + robot.waitForIdle(); + robot.delay(500); + EventQueue.invokeAndWait(testedFrame::dispose); + robot.waitForIdle(); + robot.delay(500); + test(); + } finally { + EventQueue.invokeAndWait(() -> { + backgroundFrame.dispose(); + testedFrame.dispose(); + }); + } + } + + private static void test() { + BufferedImage bi = robot.createScreenCapture(backgroundFrameBounds); + int redPix = Color.RED.getRGB(); + + for (int x = 0; x < bi.getWidth(); x++) { + for (int y = 0; y < bi.getHeight(); y++) { + if (bi.getRGB(x, y) != redPix) { + try { + ImageIO.write(bi, "png", + new File("failure.png")); + } catch (IOException ignored) {} + throw new RuntimeException("Test failed"); + } + } + } + } + + private static void initAndShowGui() { + backgroundFrame = new Frame("DisposeTest background"); + backgroundFrame.setUndecorated(true); + backgroundFrame.setBackground(Color.RED); + backgroundFrame.setBounds(backgroundFrameBounds); + backgroundFrame.setVisible(true); + + testedFrame = new UglyFrame(); + } + + static class UglyFrame extends Frame { + public UglyFrame() { + super("DisposeTest"); + MenuBar mb = new MenuBar(); + Menu m = new Menu("menu"); + mb.add(m); + setMenuBar(mb); + setBounds(testedFrameBounds); + setVisible(true); + } + } +} + diff --git a/test/jdk/java/awt/Frame/FrameMenuPackTest.java b/test/jdk/java/awt/Frame/FrameMenuPackTest.java new file mode 100644 index 00000000000..c034acd8eb7 --- /dev/null +++ b/test/jdk/java/awt/Frame/FrameMenuPackTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +import java.awt.BorderLayout; +import java.awt.Frame; +import java.awt.Label; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.ScrollPane; +import java.awt.Window; +import java.util.List; + +/* + * @test + * @bug 4084766 + * @summary Test for bug(s): 4084766 + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FrameMenuPackTest + */ + +public class FrameMenuPackTest { + private static final String INSTRUCTIONS = """ + Check that both frames that appear are properly packed with + the scrollpane visible. + """; + + public static void main(String[] argv) throws Exception { + PassFailJFrame.builder() + .title("FrameMenuPackTest Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .testUI(FrameMenuPackTest::createAndShowUI) + .positionTestUIRightRow() + .build() + .awaitAndCheck(); + } + + private static List createAndShowUI() { + // Frame without menu, packs correctly + PackedFrame f1 = new PackedFrame(false); + f1.pack(); + + // Frame with menu, doesn't pack right + PackedFrame f2 = new PackedFrame(true); + f2.pack(); + + return List.of(f1, f2); + } + + private static class PackedFrame extends Frame { + public PackedFrame(boolean withMenu) { + super("PackedFrame"); + + MenuBar menubar; + Menu fileMenu; + MenuItem foo; + ScrollPane sp; + + sp = new ScrollPane(); + sp.add(new Label("Label in ScrollPane")); + System.out.println(sp.getMinimumSize()); + + this.setLayout(new BorderLayout()); + this.add(sp, "Center"); + this.add(new Label("Label in Frame"), "South"); + + if (withMenu) { + menubar = new MenuBar(); + fileMenu = new Menu("File"); + foo = new MenuItem("foo"); + fileMenu.add(foo); + menubar.add(fileMenu); + this.setMenuBar(menubar); + } + } + } +} diff --git a/test/jdk/java/awt/Frame/FramePaintTest.java b/test/jdk/java/awt/Frame/FramePaintTest.java new file mode 100644 index 00000000000..aaa14893b34 --- /dev/null +++ b/test/jdk/java/awt/Frame/FramePaintTest.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2001, 2024, 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. + */ + + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Graphics; + +/* + * @test + * @bug 4023385 + * @summary resizing a frame causes too many repaints + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FramePaintTest +*/ + +public class FramePaintTest { + private static final String INSTRUCTIONS = """ + You should see a Frame titled "Repaint Test", filled with colored blocks. + + Resize the frame several times, both inward as well as outward. + + The blocks should move to fill the window without any flashes or + glitches which ensures that repaint is not done excessively + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("FramePaintTest Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .testUI(ResizeLW::new) + .build() + .awaitAndCheck(); + } + + static class ResizeLW extends Frame { + + public ResizeLW() { + super("Repaint Test"); + setBackground(Color.red); + setLayout(new FlowLayout()); + setSize(300, 300); + + for (int i = 0; i < 10; i++) { + add(new ColorComp(Color.blue)); + add(new ColorComp(Color.green)); + } + } + + private static class ColorComp extends Component { + public ColorComp(Color c) { + super(); + setBackground(c); + } + + public void paint(Graphics g) { + g.setColor(getBackground()); + g.fillRect(0, 0, getWidth(), getHeight()); + } + + public Dimension getPreferredSize() { + return new Dimension(50, 50); + } + } + } +} diff --git a/test/jdk/java/awt/Frame/FrameResizeTest/FrameResizeTest_3.java b/test/jdk/java/awt/Frame/FrameResizeTest/FrameResizeTest_3.java new file mode 100644 index 00000000000..6fdef005775 --- /dev/null +++ b/test/jdk/java/awt/Frame/FrameResizeTest/FrameResizeTest_3.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2000, 2024, 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. + */ + +import java.awt.Button; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.Window; +import java.awt.event.ActionListener; + +/* + * @test + * @bug 4097207 + * @summary setSize() on a Frame does not resize its content + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FrameResizeTest_3 +*/ + +public class FrameResizeTest_3 { + + private static final String INSTRUCTIONS = """ + 1. You would see a frame titled 'TestFrame' with 2 buttons + named 'setSize(500,500)' and 'setSize(400,400)' + 2. Click any button and you would see the frame resized + 3. If the buttons get resized along with the frame + (ie., to fit the frame), press Pass else press Fail. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("FrameResizeTest_3 Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .logArea(6) + .testUI(FrameResizeTest_3::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Window createTestUI() { + Frame frame = new Frame("TestFrame"); + frame.setLayout(new GridLayout(2, 1)); + + Button butSize500 = new Button("setSize(500,500)"); + Button butSize400 = new Button("setSize(400,400)"); + + ActionListener actionListener = e -> { + if (e.getSource() instanceof Button) { + if (e.getSource() == butSize500) { + frame.setSize(500, 500); + PassFailJFrame.log("New bounds: " + frame.getBounds()); + } else if (e.getSource() == butSize400) { + frame.setSize(400, 400); + PassFailJFrame.log("New bounds: " + frame.getBounds()); + } + } + }; + butSize500.addActionListener(actionListener); + butSize400.addActionListener(actionListener); + frame.add(butSize500); + frame.add(butSize400); + + frame.setSize(270, 200); + return frame; + } +} diff --git a/test/jdk/java/awt/Frame/FrameResizeTest/FrameResizeTest_4.java b/test/jdk/java/awt/Frame/FrameResizeTest/FrameResizeTest_4.java new file mode 100644 index 00000000000..4428feee335 --- /dev/null +++ b/test/jdk/java/awt/Frame/FrameResizeTest/FrameResizeTest_4.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +/* Note that although this test makes use of Swing classes, like JFrame and */ +/* JButton, it is really an AWT test, because it tests mechanism of sending */ +/* paint events. */ + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import java.awt.BorderLayout; + +/* + * @test + * @bug 4174831 + * @summary Tests that frame do not flicker on diagonal resize + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FrameResizeTest_4 + */ + +public class FrameResizeTest_4 { + private static final String INSTRUCTIONS = """ + Try enlarging the frame diagonally. + If buttons inside frame excessively repaint themselves and flicker + while you enlarge frame, the test fails. + Otherwise, it passes. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("FrameResizeTest_4 Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .testUI(FrameResizeTest_4::createTestUI) + .build() + .awaitAndCheck(); + } + + private static JFrame createTestUI() { + JFrame f = new JFrame("FrameResizeTest_4 Flickering Frame"); + + JPanel panel = new JPanel(new BorderLayout()); + panel.add(new JButton("West"), BorderLayout.WEST); + panel.add(new JButton("East"), BorderLayout.EAST); + panel.add(new JButton("North"), BorderLayout.NORTH); + panel.add(new JButton("South"), BorderLayout.SOUTH); + panel.add(new JButton("Center"), BorderLayout.CENTER); + f.setContentPane(panel); + + f.pack(); + f.setBounds(100, 50, 300, 200); + + return f; + } +} diff --git a/test/jdk/java/awt/Frame/FrameResizeTest/FrameResizeTest_5.java b/test/jdk/java/awt/Frame/FrameResizeTest/FrameResizeTest_5.java new file mode 100644 index 00000000000..5a43b755a52 --- /dev/null +++ b/test/jdk/java/awt/Frame/FrameResizeTest/FrameResizeTest_5.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +import java.awt.Button; +import java.awt.Frame; +import java.awt.GridLayout; + +/* + * @test + * @summary Test to make sure non-resizable Frames can be resized with the + * setSize() method. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FrameResizeTest_5 +*/ + +public class FrameResizeTest_5 { + private static final String INSTRUCTIONS = """ + This tests the programmatic resizability of non-resizable Frames. + Even when a Frame is set to be non-resizable, it should still be + programmatically resizable using the setSize() method. + + Initially the Frame will be resizable. Try using the "Smaller" + and "Larger" buttons to verify that the Frame resizes correctly. + Then, click the "Toggle" button to make the Frame non-resizable. + Again, verify that clicking the "Larger" and "Smaller" buttons + causes the Frame to get larger and smaller. If the Frame does + not change size, or does not re-layout correctly, the test fails. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("FrameResizeTest_5 Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .logArea(6) + .testUI(TestFrame::new) + .build() + .awaitAndCheck(); + } + + private static class TestFrame extends Frame { + Button bLarger, bSmaller, bCheck, bToggle; + + public TestFrame() { + super("Frame Resize Test"); + setSize(200, 200); + bLarger = new Button("Larger"); + bLarger.addActionListener(e -> { + setSize(400, 400); + validate(); + }); + bSmaller = new Button("Smaller"); + bSmaller.addActionListener(e -> { + setSize(200, 100); + validate(); + }); + bCheck = new Button("Resizable?"); + bCheck.addActionListener(e -> { + if (isResizable()) { + PassFailJFrame.log("Frame is resizable"); + setResizable(true); + } else { + PassFailJFrame.log("Frame is not resizable"); + setResizable(false); + } + }); + bToggle = new Button("Toggle"); + bToggle.addActionListener(e -> { + if (isResizable()) { + PassFailJFrame.log("Frame is now not resizable"); + setResizable(false); + } else { + PassFailJFrame.log("Frame is now resizable"); + setResizable(true); + } + }); + setLayout(new GridLayout(4, 1)); + add(bSmaller); + add(bLarger); + add(bCheck); + add(bToggle); + } + } +} diff --git a/test/jdk/java/awt/Frame/FrameSetCursorTest.java b/test/jdk/java/awt/Frame/FrameSetCursorTest.java new file mode 100644 index 00000000000..98968a8fbab --- /dev/null +++ b/test/jdk/java/awt/Frame/FrameSetCursorTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 1998, 2024, 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. + */ + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Cursor; +import java.awt.Frame; +import java.awt.Panel; +import java.awt.event.ActionListener; +import java.lang.Exception; +import java.lang.InterruptedException; +import java.lang.Object; +import java.lang.String; +import java.lang.Thread; + +/* + * @test + * @bug 4097226 + * @summary Frame.setCursor() sometimes doesn't update the cursor until user moves the mouse + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FrameSetCursorTest + */ + +public class FrameSetCursorTest { + private static final String INSTRUCTIONS = """ + 1. Keep the instruction dialog and TestFrame side by side so that + you can read the instructions while doing the test + 2. Click on the 'Start Busy' button on the frame titled 'TestFrame' + and DO NOT MOVE THE MOUSE ANYWHERE till you complete the steps below + 3. The cursor on the TestFrame changes to busy cursor + 4. If you don't see the busy cursor press 'Fail' after + the `done sleeping` message + 5. If the busy cursor is seen, after 5 seconds the message + 'done sleeping' is displayed in the message window + 6. Check for the cursor type after the display of 'done sleeping' + 7. If the cursor on the TestFrame has changed back to default cursor + (without you touching or moving the mouse), then press 'Pass' + else if the frame still shows the busy cursor press 'Fail' + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("FrameSetCursorTest Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .testUI(FrameSetCursorTest::createAndShowUI) + .logArea(5) + .build() + .awaitAndCheck(); + + } + + static Frame createAndShowUI() { + Frame frame = new Frame("TestFrame"); + Panel panel = new Panel(); + Button busyButton = new Button("Start Busy"); + + ActionListener actionListener = event -> { + Object source = event.getSource(); + if (source == busyButton) { + frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + try { + Thread.sleep(5000); + } catch (InterruptedException ignored) {} + PassFailJFrame.log("done sleeping"); + frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + }; + + busyButton.addActionListener(actionListener); + panel.setLayout(new BorderLayout()); + panel.add("North", busyButton); + + frame.add(panel); + frame.pack(); + frame.setSize(200, 200); + return frame; + } +} \ No newline at end of file diff --git a/test/jdk/java/awt/Frame/FrameVisualTest.java b/test/jdk/java/awt/Frame/FrameVisualTest.java new file mode 100644 index 00000000000..767eb0a1896 --- /dev/null +++ b/test/jdk/java/awt/Frame/FrameVisualTest.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2002, 2024, 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. + */ + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsEnvironment; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; + +/* + * @test + * @bug 4328588 + * @key headful + * @summary Non-default visual on top-level Frame should work + * @run main FrameVisualTest + */ + +public class FrameVisualTest { + private static GraphicsConfiguration[] gcs; + private static volatile Frame[] frames; + private static volatile int index; + + private static Frame f; + private static Robot robot; + private static volatile Point p; + private static volatile Dimension d; + private static final int TOLERANCE = 5; + + public static void main(String[] args) throws Exception { + gcs = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getConfigurations(); + robot = new Robot(); + robot.setAutoDelay(100); + try { + EventQueue.invokeAndWait(() -> { + createAndShowUI(); + }); + robot.delay(1000); + System.out.println("frames.length: "+frames.length); + for (index = 0; index < frames.length; index++) { + EventQueue.invokeAndWait(() -> { + p = frames[index].getLocation(); + d = frames[index].getSize(); + }); + Rectangle rect = new Rectangle(p, d); + BufferedImage img = robot.createScreenCapture(rect); + if (chkImgBackgroundColor(img)) { + try { + ImageIO.write(img, "png", new File("Frame_" + index + ".png")); + } catch (IOException ignored) {} + throw new RuntimeException("Frame visual test failed with non-white background color"); + } + } + } finally { + for (index = 0; index < frames.length; index++) { + EventQueue.invokeAndWait(() -> { + if (frames[index] != null) { + frames[index].dispose(); + } + }); + } + } + } + + private static void createAndShowUI() { + frames = new Frame[gcs.length]; + for (int i = 0; i < frames.length; i++) { + frames[i] = new Frame("Frame w/ gc " + i, gcs[i]); + frames[i].setSize(100, 100); + frames[i].setUndecorated(true); + frames[i].setBackground(Color.WHITE); + frames[i].setVisible(true); + } + } + + private static boolean chkImgBackgroundColor(BufferedImage img) { + + // scan for mid-line and if it is non-white color then return true. + for (int x = 1; x < img.getWidth() - 1; ++x) { + Color c = new Color(img.getRGB(x, img.getHeight() / 2)); + if ((c.getRed() - Color.WHITE.getRed()) > TOLERANCE && + (c.getGreen() - Color.WHITE.getGreen()) > TOLERANCE && + (c.getBlue() - Color.WHITE.getBlue()) > TOLERANCE) { + return true; + } + } + return false; + } +} + diff --git a/test/jdk/java/awt/Frame/IMStatusBar.java b/test/jdk/java/awt/Frame/IMStatusBar.java new file mode 100644 index 00000000000..7e882d01c70 --- /dev/null +++ b/test/jdk/java/awt/Frame/IMStatusBar.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1998, 2024, 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. + */ + +import java.awt.BorderLayout; +import java.awt.Frame; +import java.awt.Label; +import java.awt.Panel; +import java.awt.TextField; + +/* + * @test + * @bug 4113040 + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @summary Checks that IMStatusBar does not affect Frame layout + * @run main/manual/othervm -Duser.language=ja -Duser.country=JP IMStatusBar + */ + +public class IMStatusBar { + + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + If the window appears the right size, but then resizes so that the + status field overlaps the bottom label, press Fail; otherwise press Pass. + """; + + PassFailJFrame.builder() + .title("IMStatusBar Instruction") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(40) + .testUI(IMStatusBar::createUI) + .build() + .awaitAndCheck(); + } + + private static Frame createUI() { + Frame f = new Frame(); + Panel centerPanel = new Panel(); + f.setSize(200, 200); + f.setLayout(new BorderLayout()); + f.add(new Label("Top"), BorderLayout.NORTH); + f.add(centerPanel, BorderLayout.CENTER); + f.add(new Label("Bottom"), BorderLayout.SOUTH); + centerPanel.setLayout(new BorderLayout()); + centerPanel.add(new TextField("Middle"), BorderLayout.CENTER); + centerPanel.validate(); + return f; + } +} diff --git a/test/jdk/java/awt/Frame/InitialIconifiedTest.java b/test/jdk/java/awt/Frame/InitialIconifiedTest.java new file mode 100644 index 00000000000..f3f43929e7b --- /dev/null +++ b/test/jdk/java/awt/Frame/InitialIconifiedTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2003, 2024, 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. + */ + +import javax.imageio.ImageIO; +import java.awt.Color; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +/* + * @test + * @key headful + * @bug 4851435 + * @summary Frame is not shown initially iconified after pack + */ + +public class InitialIconifiedTest { + + private static Frame backgroundFrame; + private static Frame testedFrame; + + private static final Rectangle backgroundFrameBounds = + new Rectangle(100, 100, 200, 200); + private static final Rectangle testedFrameBounds = + new Rectangle(150, 150, 100, 100); + + private static Robot robot; + + public static void main(String[] args) throws Exception { + robot = new Robot(); + + try { + EventQueue.invokeAndWait(InitialIconifiedTest::initAndShowGui); + robot.waitForIdle(); + robot.delay(500); + test(); + } finally { + EventQueue.invokeAndWait(() -> { + backgroundFrame.dispose(); + testedFrame.dispose(); + }); + } + } + + private static void initAndShowGui() { + backgroundFrame = new Frame("DisposeTest background"); + backgroundFrame.setUndecorated(true); + backgroundFrame.setBackground(Color.RED); + backgroundFrame.setBounds(backgroundFrameBounds); + backgroundFrame.setVisible(true); + + testedFrame = new Frame("Should have started ICONIC"); + testedFrame.setExtendedState(Frame.ICONIFIED); + testedFrame.setBounds(testedFrameBounds); + testedFrame.setVisible(true); + } + + private static void test() { + BufferedImage bi = robot.createScreenCapture(backgroundFrameBounds); + int redPix = Color.RED.getRGB(); + + for (int x = 0; x < bi.getWidth(); x++) { + for (int y = 0; y < bi.getHeight(); y++) { + if (bi.getRGB(x, y) != redPix) { + try { + ImageIO.write(bi, "png", + new File("failure.png")); + } catch (IOException ignored) {} + throw new RuntimeException("Test failed"); + } + } + } + } +} diff --git a/test/jdk/java/awt/Frame/InsetCorrectionTest.java b/test/jdk/java/awt/Frame/InsetCorrectionTest.java new file mode 100644 index 00000000000..1ea6f03b24b --- /dev/null +++ b/test/jdk/java/awt/Frame/InsetCorrectionTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 1998, 2024, 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. + */ + +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/* + * @test + * @bug 4091426 + * @key headful + * @summary Test inset correction when setVisible(true) BEFORE setSize(), setLocation() + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual InsetCorrectionTest + */ + +public class InsetCorrectionTest { + private static final String INSTRUCTIONS = """ + There is a frame of size 300x300 at location (100,100). + It has a menubar with one menu, 'File', but the frame + is otherwise empty. In particular, there should be no + part of the frame that is not shown in the background color. + Upon test completion, click Pass or Fail appropriately. + """; + + private static InsetCorrection testFrame; + + public static void main(String[] args) throws Exception { + EventQueue.invokeAndWait(() -> testFrame = new InsetCorrection()); + + try { + PassFailJFrame passFailJFrame = PassFailJFrame.builder() + .title("InsetCorrectionTest Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .logArea(3) + .build(); + EventQueue.invokeAndWait(() -> + PassFailJFrame.log("frame location: " + testFrame.getBounds())); + passFailJFrame.awaitAndCheck(); + } finally { + EventQueue.invokeAndWait(testFrame::dispose); + } + } + + static class InsetCorrection extends Frame + implements ActionListener { + MenuBar mb; + Menu file; + MenuItem cause_bug_b; + + public InsetCorrection() { + super("InsetCorrection"); + mb = new MenuBar(); + file = new Menu("File"); + mb.add(file); + cause_bug_b = new MenuItem("cause bug"); + file.add(cause_bug_b); + setMenuBar(mb); + cause_bug_b.addActionListener(this); + + // Making the frame visible before setSize and setLocation() + // are being called causes sometimes strange behaviour with + // JDK1.1.5G. The frame is then sometimes to large and the + // excess areas are drawn in black. This only happens + // sometimes. + setVisible(true); + setSize(300, 300); + setLocation(100, 100); + } + + public void actionPerformed(ActionEvent e) { + setVisible(false); + setVisible(true); + } + } +} diff --git a/test/jdk/java/awt/Frame/MenuCrash.java b/test/jdk/java/awt/Frame/MenuCrash.java new file mode 100644 index 00000000000..f68dd4ad000 --- /dev/null +++ b/test/jdk/java/awt/Frame/MenuCrash.java @@ -0,0 +1,168 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +import java.awt.Button; +import java.awt.CheckboxMenuItem; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.TextField; +import java.awt.Window; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.List; + +/* + * @test + * @bug 4133279 + * @summary Clicking in menu in inactive frame crashes application + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual MenuCrash + */ +public class MenuCrash { + + private static final String INSTRUCTIONS = """ + Two frames will appear, alternate between frames by clicking on the + menubar of the currently deactivated frame and verify no crash occurs. + + Try mousing around the menus and choosing various items to see the menu + item name reflected in the text field. Note that CheckBoxMenuItems do + not fire action events so the check menu item (Item 03) will not change + the field. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("MenuCrash Instructions") + .instructions(INSTRUCTIONS) + .columns(45) + .testUI(MenuCrash::createAndShowUI) + .positionTestUIRightRow() + .build() + .awaitAndCheck(); + } + + + private static List createAndShowUI() { + Frame frame1 = new MenuFrame("Frame 1 MenuCrash"); + Frame frame2 = new MenuFrame("Frame 2 MenuCrash"); + + frame1.setSize(300, 200); + frame2.setSize(300, 200); + + frame1.validate(); + frame2.validate(); + + return List.of(frame1, frame2); + } + + static class MenuFrame extends Frame { + private final TextField field; + + MenuFrame(String name) { + super(name); + setLayout(new FlowLayout()); + + Button removeMenus = new Button("Remove Menus"); + removeMenus.addActionListener(ev -> remove(getMenuBar())); + + Button addMenus = new Button("Add Menus"); + addMenus.addActionListener(ev -> setupMenus()); + + add(removeMenus); + add(addMenus); + field = new TextField(20); + add(field); + + addWindowListener( + new WindowAdapter() { + public void windowActivated(WindowEvent e) { + setupMenus(); + } + } + ); + + addComponentListener( + new ComponentAdapter() { + public void componentResized(ComponentEvent e) { + System.out.println(MenuFrame.this); + } + } + ); + + pack(); + } + + private void addMenuListeners() { + MenuBar menuBar = getMenuBar(); + + for (int nMenu = 0; nMenu < menuBar.getMenuCount(); nMenu++) { + Menu menu = menuBar.getMenu(nMenu); + for (int nMenuItem = 0; nMenuItem < menu.getItemCount(); nMenuItem++) { + MenuItem item = menu.getItem(nMenuItem); + item.addActionListener(ev -> field.setText(ev.getActionCommand())); + } + } + } + + private void setupMenus() { + MenuItem miSetLabel = new MenuItem("Item 01"); + MenuItem miSetEnabled = new MenuItem("Item 02"); + CheckboxMenuItem miSetState = new CheckboxMenuItem("Item 03"); + MenuItem miAdded = new MenuItem("Item 04 Added"); + + MenuBar menuBar = new MenuBar(); + Menu menu1 = new Menu("Menu 01"); + menu1.add(miSetLabel); + menu1.add(miSetEnabled); + menu1.add(miSetState); + menuBar.add(menu1); + setMenuBar(menuBar); + + // now that the peers are created, screw + // around with the menu items + miSetLabel.setLabel("Menu 01 - SetLabel"); + miSetEnabled.setEnabled(false); + miSetState.setState(true); + menu1.add(miAdded); + menu1.remove(miAdded); + menu1.addSeparator(); + menu1.add(miAdded); + + Menu menu2 = new Menu("Menu 02"); + menuBar.add(menu2); + menuBar.remove(menu2); + menuBar.add(menu2); + menu2.add(new MenuItem("Foo")); + menu1.setLabel("Menu Number 1"); + menu2.setLabel("Menu Number 2"); + + addMenuListeners(); + } + } +} diff --git a/test/jdk/java/awt/Frame/MultiScreenTest.java b/test/jdk/java/awt/Frame/MultiScreenTest.java new file mode 100644 index 00000000000..845f601138b --- /dev/null +++ b/test/jdk/java/awt/Frame/MultiScreenTest.java @@ -0,0 +1,485 @@ +/* + * Copyright (c) 2000, 2024, 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. + */ + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Canvas; +import java.awt.Choice; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.FontMetrics; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.Image; +import java.awt.Label; +import java.awt.LayoutManager; +import java.awt.Panel; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.TextField; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import java.awt.image.ColorModel; +import java.awt.image.MemoryImageSource; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JFrame; + +import jtreg.SkippedException; + +/* + * @test + * @bug 4312921 + * @key multimon + * @library /java/awt/regtesthelpers /test/lib + * @build PassFailJFrame + * @summary Tests that no garbage is painted on primary screen with DGA + * @run main/manual MultiScreenTest + */ + +public class MultiScreenTest { + static GraphicsEnvironment ge; + static GraphicsDevice[] gs; + + public static void main(String[] args) throws Exception { + ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + gs = ge.getScreenDevices(); + if (gs.length < 2) { + throw new SkippedException("You have only one monitor in your system - test passed"); + } + MultiScreenTest obj = new MultiScreenTest(); + String INSTRUCTIONS = + "This test is to be run only on multiscreen machine. " + + "You have " + gs.length + " monitors in your system.\n" + + "Actively drag the DitherTest frames on the secondary screen and " + + "if you see garbage appearing on your primary screen " + + "test failed otherwise it passed.";; + + PassFailJFrame.builder() + .title("MultiScreenTest Instruction") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(40) + .testUI(obj::init) + .build() + .awaitAndCheck(); + } + + public List init() { + List list = new ArrayList<>(); + for (int j = 0; j < gs.length; j++) { + GraphicsConfiguration[] gc = gs[j].getConfigurations(); + if (gc.length > 0) { + for (int i = 0; i < gc.length / 2; i++) { + JFrame f = new JFrame(gc[i]); //test JFrame( gc ) + GCCanvas c = new GCCanvas(gc[i]);//test canvas( gc ) + Rectangle gcBounds = gc[i].getBounds(); //test getBounds() + int xoffs = gcBounds.x; + int yoffs = gcBounds.y; + + f.getContentPane().add(c); + f.setTitle("Screen# " + Integer.toString(j) + ", GC#" + Integer.toString(i)); + f.setSize(300, 200); + f.setLocation(400 + xoffs, (i * 150) + yoffs);//test displaying in right location + list.add(f); + + Frame ditherfs = new Frame("DitherTest GC#" + Integer.toString(i), gc[i]); + ditherfs.setLayout(new BorderLayout()); //showDitherTest + DitherTest ditherTest = new DitherTest(gc[i]); + ditherfs.add("Center", ditherTest); + ditherfs.setBounds(300, 200, 300, 200); + ditherfs.setLocation(750 + xoffs, (i * 50) + yoffs); + ditherfs.pack(); + ditherfs.show(); + ditherTest.start(); + } + } + } + return list; + } +} + +class GCCanvas extends Canvas { + + GraphicsConfiguration gc; + Rectangle bounds; + Graphics g = this.getGraphics(); + Dimension size = getSize(); + + public GCCanvas(GraphicsConfiguration gc) { + super(gc); + this.gc = gc; + bounds = gc.getBounds(); + } + + public void paint( Graphics _g ) { + + Graphics2D g = (Graphics2D) _g; + + g.drawRect(0, 0, size.width-1, size.height-1); + g.setColor(Color.lightGray); + g.draw3DRect(1, 1, size.width-3, size.height-3, true); + + g.setColor(Color.red); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + g.drawString("HELLO!", 110, 10); + + g.setColor(Color.blue); + g.drawString("ScreenSize="+Integer.toString(bounds.width)+"X"+ + Integer.toString(bounds.height), 10, 20); + g.setColor(Color.green); + g.drawString(gc.toString(), 10, 30); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); + + g.setColor(Color.orange); + g.fillRect(40, 20, 50, 50); + + g.setColor(Color.red); + g.drawRect(100, 20, 30, 30); + + g.setColor(Color.gray); + g.drawLine(220, 20, 280, 40); + + g.setColor(Color.cyan); + g.fillArc(150, 30, 30, 30, 0, 200); + } + + public Dimension getPreferredSize(){ + return new Dimension(300, 200); + } +} + +class DitherCanvas extends Canvas { + Image img; + static String calcString = "Calculating..."; + + GraphicsConfiguration mGC; + + public DitherCanvas(GraphicsConfiguration gc) { + super(gc); + mGC = gc; + } + + public GraphicsConfiguration getGraphicsConfig() { + return mGC; + } + + public void paint(Graphics g) { + int w = getSize().width; + int h = getSize().height; + if (img == null) { + super.paint(g); + g.setColor(Color.black); + FontMetrics fm = g.getFontMetrics(); + int x = (w - fm.stringWidth(calcString)) / 2; + int y = h / 2; + g.drawString(calcString, x, y); + } else { + g.drawImage(img, 0, 0, w, h, this); + } + } + + public void update(Graphics g) { + paint(g); + } + + public Dimension getMinimumSize() { + return new Dimension(20, 20); + } + + public Dimension getPreferredSize() { + return new Dimension(200, 200); + } + + public Image getImage() { + return img; + } + + public void setImage(Image img) { + this.img = img; + paint(getGraphics()); + } +} + +class DitherTest extends Panel implements Runnable { + final static int NOOP = 0; + final static int RED = 1; + final static int GREEN = 2; + final static int BLUE = 3; + final static int ALPHA = 4; + final static int SATURATION = 5; + + Thread runner; + + DitherControls XControls; + DitherControls YControls; + DitherCanvas canvas; + + public DitherTest(GraphicsConfiguration gc) { + String xspec, yspec; + int xvals[] = new int[2]; + int yvals[] = new int[2]; + + xspec = "red"; + yspec = "blue"; + int xmethod = colormethod(xspec, xvals); + int ymethod = colormethod(yspec, yvals); + + setLayout(new BorderLayout()); + XControls = new DitherControls(this, xvals[0], xvals[1], + xmethod, false); + YControls = new DitherControls(this, yvals[0], yvals[1], + ymethod, true); + YControls.addRenderButton(); + add("North", XControls); + add("South", YControls); + add("Center", canvas = new DitherCanvas(gc)); + } + + public void start() { + runner = new Thread(this); + runner.start(); + } + + int colormethod(String s, int vals[]) { + int method = NOOP; + + if (s == null) { + s = ""; + } + + String lower = s.toLowerCase(); + int len = 0; + if (lower.startsWith("red")) { + method = RED; + lower = lower.substring(3); + } else if (lower.startsWith("green")) { + method = GREEN; + lower = lower.substring(5); + } else if (lower.startsWith("blue")) { + method = BLUE; + lower = lower.substring(4); + } else if (lower.startsWith("alpha")) { + method = ALPHA; + lower = lower.substring(4); + } else if (lower.startsWith("saturation")) { + method = SATURATION; + lower = lower.substring(10); + } + + if (method == NOOP) { + vals[0] = 0; + vals[1] = 0; + return method; + } + + int begval = 0; + int endval = 255; + + try { + int dash = lower.indexOf('-'); + if (dash < 0) { + begval = endval = Integer.parseInt(lower); + } else { + begval = Integer.parseInt(lower.substring(0, dash)); + endval = Integer.parseInt(lower.substring(dash + 1)); + } + } catch (Exception e) { + } + + if (begval < 0) { + begval = 0; + } + if (endval < 0) { + endval = 0; + } + if (begval > 255) { + begval = 255; + } + if (endval > 255) { + endval = 255; + } + + vals[0] = begval; + vals[1] = endval; + + return method; + } + + void applymethod(int c[], int method, int step, int total, int vals[]) { + if (method == NOOP) + return; + int val = ((total < 2) + ? vals[0] + : vals[0] + ((vals[1] - vals[0]) * step / (total - 1))); + switch (method) { + case RED: + c[0] = val; + break; + case GREEN: + c[1] = val; + break; + case BLUE: + c[2] = val; + break; + case ALPHA: + c[3] = val; + break; + case SATURATION: + int max = Math.max(Math.max(c[0], c[1]), c[2]); + int min = max * (255 - val) / 255; + if (c[0] == 0) { + c[0] = min; + } + if (c[1] == 0) { + c[1] = min; + } + if (c[2] == 0) { + c[2] = min; + } + break; + } + } + + public void run() { + canvas.setImage(null); // Wipe previous image + Image img = calculateImage(); + synchronized (this) { + if (img != null && runner == Thread.currentThread()) { + canvas.setImage(img); + } + } + } + + /** + * Calculates and returns the image. Halts the calculation and returns + * null if stopped during the calculation. + */ + Image calculateImage() { + Thread me = Thread.currentThread(); + + int width = canvas.getSize().width; + int height = canvas.getSize().height; + int xvals[] = new int[2]; + int yvals[] = new int[2]; + int xmethod = XControls.getParams(xvals); + int ymethod = YControls.getParams(yvals); + int pixels[] = new int[width * height]; + int c[] = new int[4]; + int index = 0; + + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + c[0] = c[1] = c[2] = 0; + c[3] = 255; + if (xmethod < ymethod) { + applymethod(c, xmethod, i, width, xvals); + applymethod(c, ymethod, j, height, yvals); + } else { + applymethod(c, ymethod, j, height, yvals); + applymethod(c, xmethod, i, width, xvals); + } + pixels[index++] = ((c[3] << 24) | + (c[0] << 16) | + (c[1] << 8) | + (c[2] << 0)); + + } + // Poll once per row to see if we've been told to stop. + if (runner != me) { + return null; + } + } + + return createImage(new MemoryImageSource(width, height, + ColorModel.getRGBdefault(), pixels, 0, width)); + } + + public String getInfo() { + return "An interactive demonstration of dithering."; + } + + public String[][] getParameterInfo() { + String[][] info = { + {"xaxis", "{RED, GREEN, BLUE, PINK, ORANGE, MAGENTA, CYAN, WHITE, YELLOW, GRAY, DARKGRAY}", + "The color of the Y axis. Default is RED."}, + {"yaxis", "{RED, GREEN, BLUE, PINK, ORANGE, MAGENTA, CYAN, WHITE, YELLOW, GRAY, DARKGRAY}", + "The color of the X axis. Default is BLUE."} + }; + return info; + } +} + +class DitherControls extends Panel implements ActionListener { + TextField start; + TextField end; + Button button; + Choice choice; + DitherTest dt; + + static LayoutManager dcLayout = new FlowLayout(FlowLayout.CENTER, 10, 5); + + public DitherControls(DitherTest app, int s, int e, int type, + boolean vertical) { + dt = app; + setLayout(dcLayout); + add(new Label(vertical ? "Vertical" : "Horizontal")); + add(choice = new Choice()); + choice.addItem("Noop"); + choice.addItem("Red"); + choice.addItem("Green"); + choice.addItem("Blue"); + choice.addItem("Alpha"); + choice.addItem("Saturation"); + choice.select(type); + add(start = new TextField(Integer.toString(s), 4)); + add(end = new TextField(Integer.toString(e), 4)); + } + + public void addRenderButton() { + add(button = new Button("New Image")); + button.addActionListener(this); + } + + public int getParams(int vals[]) { + vals[0] = Integer.parseInt(start.getText()); + vals[1] = Integer.parseInt(end.getText()); + return choice.getSelectedIndex(); + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource() == button) { + dt.start(); + } + } +} diff --git a/test/jdk/java/awt/List/ActionEventWhenHitEnterTest.java b/test/jdk/java/awt/List/ActionEventWhenHitEnterTest.java new file mode 100644 index 00000000000..232189ef53b --- /dev/null +++ b/test/jdk/java/awt/List/ActionEventWhenHitEnterTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2002, 2024, 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 4234245 + * @summary the actionEvent is not invoked when hit enter on list. + * @key headful + * @run main ActionEventWhenHitEnterTest + */ + +import java.awt.BorderLayout; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.IllegalComponentStateException; +import java.awt.List; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; + +public class ActionEventWhenHitEnterTest + implements ActionListener, ItemListener { + + volatile boolean passed1; + volatile boolean passed2; + volatile Point pt; + List list; + Frame frame; + + public static void main(final String[] args) throws Exception { + ActionEventWhenHitEnterTest app = new ActionEventWhenHitEnterTest(); + app.doTest(); + } + + public ActionEventWhenHitEnterTest() { + list = new List(7); + for (int i = 0; i < 10; i++) { + list.add("Item " + i); + } + list.addItemListener(this); + list.addActionListener(this); + } + + public void actionPerformed(ActionEvent ae) { + passed1 = true; + System.out.println("--> Action event invoked: " + ae.getSource()); + } + + public void itemStateChanged(ItemEvent ie) { + passed2 = true; + System.out.println("--> Item state changed:" + ie.getSource()); + } + + public void doTest() throws Exception { + EventQueue.invokeAndWait(() -> { + frame = new Frame("ActionEventWhenHitEnterTest"); + frame.add(list); + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + }); + + try { + Robot robot = new Robot(); + robot.setAutoDelay(100); + robot.waitForIdle(); + robot.delay(1000); + + EventQueue.invokeAndWait(() -> { + pt = list.getLocationOnScreen(); + }); + + if (pt.x != 0 || pt.y != 0) { + robot.mouseMove(pt.x + list.getWidth() / 2, + pt.y + list.getHeight() / 2); + robot.waitForIdle(); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + + robot.keyPress(KeyEvent.VK_ENTER); + robot.keyRelease(KeyEvent.VK_ENTER); + } + + robot.waitForIdle(); + } finally { + EventQueue.invokeAndWait(() -> { + if (frame != null) { + frame.dispose(); + } + }); + } + + if (!passed1 || !passed2) { + throw new RuntimeException("ActionEventWhenHitEnterTest FAILED"); + } + System.out.println("Test PASSED"); + + } + +} diff --git a/test/jdk/java/awt/List/DisabledListIsGreyTest.java b/test/jdk/java/awt/List/DisabledListIsGreyTest.java new file mode 100644 index 00000000000..ec1a2570666 --- /dev/null +++ b/test/jdk/java/awt/List/DisabledListIsGreyTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2006, 2024, 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 6354810 + * @summary Items in the list are not grayed out when disabled, XToolkit + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual DisabledListIsGreyTest +*/ + +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.List; + +public class DisabledListIsGreyTest { + + private static final String INSTRUCTIONS = """ + 1) After the test started you will see two lists. + 2) One of them is enabled, and the second is disabled. + 3) Check that the items of the disabled list are grayed. + 4) If so, the test passed. Otherwise, failed."""; + + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("DisabledListIsGreyTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(DisabledListIsGreyTest::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Frame frame = new Frame("DisabledListIsGreyTest Frame"); + frame.setLayout(new FlowLayout()); + + List list1 = new List(3); + List list2 = new List(3); + for (int i = 0; i < 5; i++) { + list1.addItem("Item " + i); + list2.addItem("Item " + i); + } + frame.add(list1); + + list2.setEnabled(false); + frame.add(list2); + frame.pack(); + return frame; + } + +} diff --git a/test/jdk/java/awt/List/HandlingKeyEventIfMousePressedTest.java b/test/jdk/java/awt/List/HandlingKeyEventIfMousePressedTest.java new file mode 100644 index 00000000000..e5c89c1df12 --- /dev/null +++ b/test/jdk/java/awt/List/HandlingKeyEventIfMousePressedTest.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2005, 2024, 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 6293432 + * @summary Key events ('SPACE', 'UP', 'DOWN') aren't blocked + * if mouse is kept in 'PRESSED' state for List + * @key headful + * @run main HandlingKeyEventIfMousePressedTest + */ + +import java.awt.EventQueue; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.List; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.InputEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionAdapter; + +public class HandlingKeyEventIfMousePressedTest { + + static Frame frame; + static List list; + static volatile Point loc; + + public static void main(String[] args) throws Exception { + Robot robot = new Robot(); + robot.setAutoDelay(100); + try { + EventQueue.invokeAndWait(() -> createUI()); + robot.waitForIdle(); + robot.delay(1000); + EventQueue.invokeAndWait(() -> { + loc = list.getLocationOnScreen(); + }); + robot.mouseMove(loc.x + 10, loc.y + 10); + robot.waitForIdle(); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + + // key pressing when the mouse is kept in the 'pressed' state + robot.keyPress(KeyEvent.VK_DOWN); + robot.keyRelease(KeyEvent.VK_DOWN); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.waitForIdle(); + + int selectedIndex = list.getSelectedIndex(); + if (selectedIndex != 0) { + throw new RuntimeException("Test failed: list.getCurrentItem = " + selectedIndex); + } + } finally { + EventQueue.invokeAndWait(() -> { + if (frame != null) { + frame.dispose(); + } + }); + } + } + + private static void createUI() { + frame = new Frame("HandlingKeyEventIfMousePressedTest"); + list = new List(10, false); + + list.add("111"); + list.add("222"); + list.add("333"); + list.add("444"); + frame.add(list); + + addListeners(); + + frame.setLayout(new FlowLayout()); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + // added in order to have more information in failed case + private static void addListeners() { + + list.addMouseMotionListener( + new MouseMotionAdapter() { + @Override + public void mouseDragged(MouseEvent me) { + System.out.println(me); + } + + @Override + public void mouseMoved(MouseEvent me) { + System.out.println(me); + } + }); + + list.addMouseListener( + new MouseAdapter(){ + public void mousePressed(MouseEvent me) { + System.out.println(me); + } + public void mouseClicked(MouseEvent me) { + System.out.println(me); + } + public void mouseEntered(MouseEvent me) { + System.out.println(me); + } + public void mouseExited(MouseEvent me) { + System.out.println(me); + } + public void mouseReleased(MouseEvent me) { + System.out.println(me); + } + }); + + list.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent ae) { + System.out.println(ae); + } + }); + + list.addItemListener( + new ItemListener() { + public void itemStateChanged(ItemEvent ie) { + System.out.println(ie); + } + }); + + list.addFocusListener( + new FocusAdapter() { + public void focusGained(FocusEvent fe) { + System.out.println(fe); + } + public void focusLost(FocusEvent fe) { + System.out.println(fe); + } + }); + } +} diff --git a/test/jdk/java/awt/List/HorizScrollWorkTest.java b/test/jdk/java/awt/List/HorizScrollWorkTest.java new file mode 100644 index 00000000000..6de1de1a4f2 --- /dev/null +++ b/test/jdk/java/awt/List/HorizScrollWorkTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2006, 2024, 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 6355467 + * @summary Horizontal scroll bar thumb of a List does not stay at the end + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @requires (os.family == "linux") + * @run main/manual HorizScrollWorkTest +*/ + +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.List; + +public class HorizScrollWorkTest { + + private static final String INSTRUCTIONS = """ + This is a linux only test. + Drag and drop the horizontal scroll bar thumb at the right end. + If the thumb does not stay at the right end, then the test failed. Otherwise passed."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("HorizScrollWorkTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int)INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(HorizScrollWorkTest::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Frame frame = new Frame("HorizScrollWorkTest Frame"); + List list = new List(4); + + frame.setLayout (new FlowLayout()); + + list.add("veryyyyyyyyyyyyyyyyyyyyyyyyyy longgggggggggggggggggggggg stringggggggggggggggggggggg"); + + frame.add(list); + frame.pack(); + + return frame; + } +} diff --git a/test/jdk/java/awt/List/HorizScrollbarEraseTest.java b/test/jdk/java/awt/List/HorizScrollbarEraseTest.java new file mode 100644 index 00000000000..2601a7ed0b2 --- /dev/null +++ b/test/jdk/java/awt/List/HorizScrollbarEraseTest.java @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2003, 2024, 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 4895367 + * @summary List scrolling w/ down arrow keys obscures horizontal scrollbar + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @requires (os.family == "linux") + * @run main/manual HorizScrollbarEraseTest + */ + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.List; +import java.awt.Panel; +import java.awt.TextArea; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class HorizScrollbarEraseTest { + + private static final String INSTRUCTIONS = """ + This is a Unix-only test. + Do the four mini-tests below. + If the horizontal scrollbar is ever erased by a rectangle + of the background color, the test FAILS. + If the horizontal scrollbars remain painted, test passes."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("HorizScrollbarEraseTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(HorizScrollbarEraseTest::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Frame frame = new Frame("HorizScrollbarEraseTest"); + Panel borderPanel = new Panel(); + borderPanel.setLayout(new BorderLayout()); + Button focusedButton = new Button("Focus starts here"); + borderPanel.add(focusedButton, BorderLayout.NORTH); + + Panel gridPanel = new Panel(); + gridPanel.setLayout(new GridLayout(0, 4)); + borderPanel.add(gridPanel, BorderLayout.CENTER); + + InstructionList il1 = new InstructionList("Tab to Item 2, then \n" + + "press the down" + + "arrow key to scroll down"); + il1.list.select(2); + il1.list.makeVisible(0); + gridPanel.add(il1); + + InstructionList il2 = new InstructionList("Tab to the next List,\n" + + "then press the down\n" + + "arrow key to select\n" + + "the last item."); + il2.list.select(3); + il2.list.makeVisible(0); + gridPanel.add(il2); + + InstructionList il3 = new InstructionList("Click the button to\n" + + "programmatically\n" + + "select item 3 (not showing)"); + Button selectBtn = new Button("Click Me"); + final List selectList = il3.list; + selectBtn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + selectList.select(3); + } + }); + il3.add(selectBtn, BorderLayout.CENTER); + gridPanel.add(il3); + + InstructionList il4 = new InstructionList("Click the button to\nprogrammatically\ndeselect item 3\n(not showing)"); + Button deselectBtn = new Button("Click Me"); + final List deselectList = il4.list; + deselectBtn.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + deselectList.deselect(3); + } + }); + il4.add(deselectBtn, BorderLayout.CENTER); + il4.list.select(3); + il4.list.makeVisible(0); + gridPanel.add(il4); + + frame.add(borderPanel); + frame.pack(); + return frame; + + } +} + +class InstructionList extends Panel { + TextArea ta; + public List list; + + public InstructionList(String instructions) { + super(); + setLayout(new BorderLayout()); + ta = new TextArea(instructions, 6, 25, TextArea.SCROLLBARS_NONE); + ta.setFocusable(false); + list = new List(); + for (int i = 0; i < 5; i++) { + list.add("Item " + i + ", a long, long, long, long item"); + } + add(ta, BorderLayout.NORTH); + add(list, BorderLayout.SOUTH); + } +} diff --git a/test/jdk/java/awt/List/ListActionEventTest.java b/test/jdk/java/awt/List/ListActionEventTest.java new file mode 100644 index 00000000000..2cd8d04a39d --- /dev/null +++ b/test/jdk/java/awt/List/ListActionEventTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2002, 2024, 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 4089604 + * @summary Enter key doesn't fire List actionPerformed as specified + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual ListActionEventTest +*/ + +import java.awt.BorderLayout; +import java.awt.Frame; +import java.awt.List; +import java.awt.Panel; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +public class ListActionEventTest { + + private static final String INSTRUCTIONS = """ + A frame will be shown. + 1. Click any item in the list (say item 1) in the frame + 2. A message 'ItemSelected' is displayed on the message window. + 3. Press the return key on the selected item. + 4. If the text 'ActionPerformed' is displayed on the message window, + then press PASS else press FAIL."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("ListActionEventTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(ListActionEventTest::createTestUI) + .logArea() + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Frame frame = new Frame("ListActionEventTest frame"); + + Panel pnl1 = new Panel(); + frame.add(pnl1); + pnl1.setLayout(new BorderLayout()); + + List list = new List(); + for (int i = 0; i < 5; i++) { + list.addItem("Item " + i); + } + pnl1.add(list); + + list.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ev) { + PassFailJFrame.log("ActionPerformed"); + } + }); + + list.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent ev) { + PassFailJFrame.log("ItemSelected"); + } + }); + frame.pack(); + return frame; + } +} diff --git a/test/jdk/java/awt/List/ListAddPerfTest.java b/test/jdk/java/awt/List/ListAddPerfTest.java new file mode 100644 index 00000000000..7ff3eaf882c --- /dev/null +++ b/test/jdk/java/awt/List/ListAddPerfTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 1999, 2024, 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 4117288 + * @summary JDKversion1.2beta3-J List's add() method is much slower. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual ListAddPerfTest + */ + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Frame; +import java.awt.List; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ListAddPerfTest { + + static Button button; + static List list; + + private static final String INSTRUCTIONS = """ + It is used to check the performance of List add operation. + + Instructions: + Click on the Remove All button. + The list should be cleared. + The button is now named "Add Items". + Click on the "Add Items" button. + 800 items should be added to the list. + Notice not only how fast or slow this is, but also how + 'smooth' it goes as well i.e. without any flashing. + + Press pass if the list performance is acceptable."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("ListAddPerfTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int)INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(ListAddPerfTest::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Frame frame = new Frame("ListAddPerfTest"); + frame.setLayout(new BorderLayout()); + + button = new Button("Remove All"); + button.addActionListener((ActionEvent e) -> { + if (list.getItemCount() > 0) { + list.removeAll(); + list.invalidate(); + button.setLabel("Add Items"); + } else { + for (int i = 0; i < 800; i ++) { + list.add("My number is " + i); + } + button.setLabel("Remove All"); + } + }); + + list = new List(15); + for (int i = 0; i < 800; i ++) { + list.add("My number is " + i); + } + + frame.add("North", button); + frame.add("South", list); + + frame.pack(); + return frame; + } +} diff --git a/test/jdk/java/awt/List/ListFrameResizeTest.java b/test/jdk/java/awt/List/ListFrameResizeTest.java new file mode 100644 index 00000000000..4655e817da5 --- /dev/null +++ b/test/jdk/java/awt/List/ListFrameResizeTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2000, 2024, 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 4085379 + * @summary List component not properly "resized" with GridBagLayout + * @requires (os.family == "windows") + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual ListFrameResizeTest + */ + +import java.awt.Color; +import java.awt.Frame; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.List; + +public class ListFrameResizeTest { + + private static final String INSTRUCTIONS = """ + This test is for windows only. + + 1. A Frame will appear with a List + (the List occupies the whole Frame) + 2. Minimize the Frame, the Frame is now in the Task Bar (ie.,iconified) + 3. Right click (right mouse button) the icon in the task bar + and click on the 'maximize' menuitem to maximize the Frame + 4. If you notice the List has not been resized + (ie.,if it partly occupies the Frame), then press FAIL else press PASS"."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("ListFrameResizeTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(ListFrameResizeTest::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + wintest client = new wintest("ListFrameResizeTest Frame"); + client.resize(500, 300); + client.setBackground(Color.blue); + return client; + } + +} + +class wintest extends Frame { + private List msg; + + public wintest(String title) { + super(title); + msg = new List(); + for (int i = 0; i < 100; i++) { + msg.add("" + i); + } + + GridBagLayout gridbag = new GridBagLayout(); + GridBagConstraints constraints = new GridBagConstraints(); + + setLayout(gridbag); + + constraints.fill = GridBagConstraints.BOTH; + + constraints.anchor = GridBagConstraints.CENTER; + constraints.insets = new Insets(10, 10, 10, 10); + constraints.ipadx = 0; + constraints.ipady = 0; + constraints.weightx = 1; + constraints.weighty = 1; + constraints.gridx = 0; + constraints.gridy = 0; + constraints.gridwidth = GridBagConstraints.REMAINDER; + constraints.gridheight = GridBagConstraints.REMAINDER; + gridbag.setConstraints(msg, constraints); + add(msg); + } +} diff --git a/test/jdk/java/awt/List/MouseDraggedOriginatedByScrollBarTest.java b/test/jdk/java/awt/List/MouseDraggedOriginatedByScrollBarTest.java new file mode 100644 index 00000000000..600d38fe393 --- /dev/null +++ b/test/jdk/java/awt/List/MouseDraggedOriginatedByScrollBarTest.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2005, 2024, 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 6240151 + * @summary XToolkit: Dragging the List scrollbar initiates DnD + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual MouseDraggedOriginatedByScrollBarTest +*/ + +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.List; +import java.awt.event.MouseMotionAdapter; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public class MouseDraggedOriginatedByScrollBarTest { + + private static final String INSTRUCTIONS = """ + 1) Click and drag the scrollbar of the list. + 2) Keep dragging till the mouse pointer goes out the scrollbar. + 3) The test failed if you see messages about events. The test passed if you don't."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("MouseDraggedOriginatedByScrollBarTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(MouseDraggedOriginatedByScrollBarTest::createTestUI) + .logArea() + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Frame frame = new Frame(); + List list = new List(4, false); + + list.add("000"); + list.add("111"); + list.add("222"); + list.add("333"); + list.add("444"); + list.add("555"); + list.add("666"); + list.add("777"); + list.add("888"); + list.add("999"); + + frame.add(list); + + list.addMouseMotionListener( + new MouseMotionAdapter(){ + @Override + public void mouseDragged(MouseEvent me){ + PassFailJFrame.log(me.toString()); + } + }); + + list.addMouseListener( + new MouseAdapter() { + public void mousePressed(MouseEvent me) { + PassFailJFrame.log(me.toString()); + } + + public void mouseReleased(MouseEvent me) { + PassFailJFrame.log(me.toString()); + } + + public void mouseClicked(MouseEvent me){ + PassFailJFrame.log(me.toString()); + } + }); + + frame.setLayout(new FlowLayout()); + frame.pack(); + return frame; + } +} diff --git a/test/jdk/java/awt/List/MultiSelectionListCrashTest.java b/test/jdk/java/awt/List/MultiSelectionListCrashTest.java new file mode 100644 index 00000000000..b408a12ebba --- /dev/null +++ b/test/jdk/java/awt/List/MultiSelectionListCrashTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 1999, 2024, 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 4201967 + * @summary tests that a multiselection list doesn't causes crash when FileDialog is invoked + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual MultiSelectionListCrashTest + */ + +import java.awt.Button; +import java.awt.FileDialog; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.List; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class MultiSelectionListCrashTest { + + private static final String INSTRUCTIONS = """ + Press "Invoke dialog" button to invoke a FileDialog. + When it appears close it by pressing cancel button. + If all remaining frames are enabled and + page fault didn't occur the test passed. Otherwise the test failed. + + Try to invoke a FileDialog several times to verify that the bug doesn't exist."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("MultiSelectionListCrashTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(MultiSelectionListCrashTest::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + + Frame frame = new Frame("MultiSelectionListCrashTest frame"); + Button button = new Button("Invoke dialog"); + button.addActionListener(new FileDialogInvoker(frame)); + List list = new List(4, true); + list.add("Item1"); + list.add("Item2"); + frame.setLayout(new FlowLayout()); + frame.add(button); + frame.add(list); + frame.setSize(200, 200); + return frame; + } +} + +class FileDialogInvoker implements ActionListener { + FileDialog fileDialog; + + public FileDialogInvoker(Frame frame) { + fileDialog = new FileDialog(frame); + } + + public void actionPerformed(ActionEvent e) { + fileDialog.setVisible(true); + } + +} diff --git a/test/jdk/java/awt/List/MultiSelectionListHorizScrollbar.java b/test/jdk/java/awt/List/MultiSelectionListHorizScrollbar.java new file mode 100644 index 00000000000..289cd0c2dac --- /dev/null +++ b/test/jdk/java/awt/List/MultiSelectionListHorizScrollbar.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1999, 2024, 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 4102881 + * @summary Ensure multiple selection Lists have horizontal scrollbars when necessary + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual MultiSelectionListHorizScrollbar +*/ + +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.List; + +public class MultiSelectionListHorizScrollbar { + + private static final String INSTRUCTIONS = """ + Resize the frame so that the lists are not wide enough + to fully display the lines of text they contain. + Once the lists are in this state, press pass + if both lists display an horizontal scrollbar. Otherwise press fail."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("MultiSelectionListHorizScrollbar Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(MultiSelectionListHorizScrollbar::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Frame frame = new Frame("MultiSelectionListHorizScrollbar Frame"); + List singleList = new List(3); + List multiList = new List(3, true); + + frame.setLayout(new GridLayout(1, 2)); + frame.add(singleList); + frame.add(multiList); + + singleList.addItem("This is the 1st item in the list! Does it scroll horizontally??"); + singleList.addItem("This is the 2nd item in the list! Does it scroll horizontally??"); + singleList.addItem("This is the 4th item in the list! Does it scroll horizontally??"); + singleList.addItem("This is the 5th item in the list! Does it scroll horizontally??"); + singleList.addItem("This is the 6th item in the list! Does it scroll horizontally??"); + + multiList.addItem("This is the 1st item in the list! Does it scroll horizontally??"); + multiList.addItem("This is the 2nd item in the list! Does it scroll horizontally??"); + multiList.addItem("This is the 4th item in the list! Does it scroll horizontally??"); + multiList.addItem("This is the 5th item in the list! Does it scroll horizontally??"); + multiList.addItem("This is the 6th item in the list! Does it scroll horizontally??"); + + frame.pack(); + return frame; + } +} diff --git a/test/jdk/java/awt/List/RepaintAfterResize.java b/test/jdk/java/awt/List/RepaintAfterResize.java new file mode 100644 index 00000000000..12bb584aefa --- /dev/null +++ b/test/jdk/java/awt/List/RepaintAfterResize.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2005, 2024, 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 6308295 + * @summary XAWTduplicate list item is displayed + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual RepaintAfterResize +*/ + +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.List; + +public class RepaintAfterResize { + + private static final String INSTRUCTIONS = """ + 1) A Frame appears with a list + 2) Resize somehow the frame using mouse + 3) Move down the vertical scrollbar of the list + 4) If you see that two selected items are displayed then the test failed. + Otherwise, the test passed."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("RepaintAfterResize Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(RepaintAfterResize::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Frame frame = new Frame("RepaintAfterResize Frame"); + List list = new List(4, false); + + frame.setLayout (new FlowLayout ()); + list.setBounds(100, 100, 100, 100); + for (int i = 0 ; i < 7 ; i++) { + list.add(" " + i); + } + frame.add(list); + list.select(3); + + frame.setSize(100, 100); + return frame; + + } +} diff --git a/test/jdk/java/awt/List/ScrollbarPositionTest.java b/test/jdk/java/awt/List/ScrollbarPositionTest.java new file mode 100644 index 00000000000..25167fa5627 --- /dev/null +++ b/test/jdk/java/awt/List/ScrollbarPositionTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 1998, 2024, 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 4024943 + * @summary Test for position of List scrollbar when it is added + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual ScrollbarPositionTest + */ + +import java.awt.Button; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.List; +import java.awt.Panel; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class ScrollbarPositionTest { + static int item = 0; + static List list; + static Button addButton, delButton; + + private static final String INSTRUCTIONS = """ + Click on the "Add List Item" button many times + until the vertical scrollbar appears. + Verify that the displayed vertical scrollbar does not take the space + that was occupied by buttons before the scrollbar is shown."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("ScrollbarPositionTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(ScrollbarPositionTest::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Panel pan; + + Frame frame = new Frame("ScrollbarPositionTest Frame"); + frame.setLayout(new GridLayout(1, 2)); + list = new List(); + frame.add(list); + frame.add(pan = new Panel()); + pan.setLayout(new GridLayout(4, 1)); + + MyListener listener = new MyListener(); + addButton = new Button("Add List Item"); + addButton.addActionListener(listener); + pan.add(addButton); + + delButton = new Button("Delete List Item"); + delButton.addActionListener(listener); + pan.add(delButton); + + frame.pack(); + return frame; + } + + static class MyListener implements ActionListener { + public void actionPerformed(ActionEvent evt) { + if (evt.getSource() == addButton) { + String s = "item"; + for (int i = 0; i <= item; i++) { + s = s +" "+Integer.toString(i); + } + item++; + list.addItem(s); + } else if (evt.getSource() == delButton) { + int i; + if ((i = list.countItems()) > 0) { + list.delItem(i - 1); + --item; + } + } + } + } +} diff --git a/test/jdk/java/awt/List/ScrollbarPresenceTest.java b/test/jdk/java/awt/List/ScrollbarPresenceTest.java new file mode 100644 index 00000000000..d82cbb80060 --- /dev/null +++ b/test/jdk/java/awt/List/ScrollbarPresenceTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2006, 2024, 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 6336384 + * @summary ScrollBar does not show up correctly + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual ScrollbarPresenceTest +*/ + +import java.awt.Font; +import java.awt.Frame; +import java.awt.List; + +public class ScrollbarPresenceTest { + + private static final String INSTRUCTIONS = """ + You will see a list, + If a vertical scrollbar appears on the list and the list is big enough + to show all items then the test failed else the test passed."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("ScrollbarPresenceTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(ScrollbarPresenceTest::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Frame frame = new Frame("ScrollbarPresenceTest Frame"); + List list = new List(); + + for (int i = 0; i < 6; i++) { + list.addItem("Row " + i); + } + + list.setFont(new Font("MonoSpaced", Font.PLAIN, 12)); + list.setBounds(30, 30, 128, 104); + frame.add(list); + + frame.pack(); + return frame; + } + +} diff --git a/test/jdk/java/awt/List/SelectedItemVisibilityTest.java b/test/jdk/java/awt/List/SelectedItemVisibilityTest.java new file mode 100644 index 00000000000..53364e93771 --- /dev/null +++ b/test/jdk/java/awt/List/SelectedItemVisibilityTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2002, 2024, 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 4676536 + * @summary REGRESSION: makeVisible() method of List Component does not perform + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual SelectedItemVisibilityTest + */ + +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Label; +import java.awt.List; + +public class SelectedItemVisibilityTest { + + static List list1, list2; + static int visibleItem = 4; + static int selectedItems[] = {6, 7, 8}; + static String selectedItemsStr = ""; + + static { + for (int i = 0 ; i < selectedItems.length ; i++) { + selectedItemsStr += ""+selectedItems[i]+" "; + } + } + + private static final String INSTRUCTIONS = + "You should see two lists.\n" + + "\n" + + "list1: \n" + + "\t1. the first visible item should be " + visibleItem + + "\n\t2. the selected item should be " + selectedItems[0] + + "\n" + + "list2:\n" + + "\t1. the first visible item should be " + visibleItem + + "\n\t2. the selected items should be " + selectedItemsStr + + "\n" + + "\nIf it is so the test passed else failed."; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("SelectedItemVisibilityTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(SelectedItemVisibilityTest::createTestUI) + .logArea() + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + + Frame frame = new Frame("SelectedItemVisibilityTest Frame"); + frame.setLayout(new FlowLayout()); + + // list1 + list1 = new List(4); + for (int i = 0; i < 20; i++) { + list1.add(""+i); + } + list1.makeVisible(visibleItem); + list1.select(selectedItems[0]); + frame.add(new Label("list1:")); + frame.add(list1); + + // list2 + list2 = new List(4); + list2.setMultipleMode(true); + for (int i = 0; i < 20; i++) { + list2.add(""+i); + } + list2.makeVisible(visibleItem); + for (int i = 0 ; i < selectedItems.length ; i++) { + list2.select(selectedItems[i]); + } + frame.add(new Label("list2:")); + frame.add(list2); + frame.setSize(200, 200); + + // common output + String s; + int sel[]; + + PassFailJFrame.log("list1: "); + PassFailJFrame.log("\tgetVisibleIndex="+list1.getVisibleIndex()); + sel = list1.getSelectedIndexes(); + s = "\tgetSelectedIndexes="; + for (int i = 0 ; i < sel.length ; i++) { + s += "" + sel[i] + " "; + } + PassFailJFrame.log(s); + + PassFailJFrame.log("list2: "); + PassFailJFrame.log("\tgetVisibleIndex="+list2.getVisibleIndex()); + sel = list2.getSelectedIndexes(); + s = "\tgetSelectedIndexes="; + for (int i = 0 ; i < sel.length ; i++) { + s += "" + sel[i] + " "; + } + PassFailJFrame.log(s); + return frame; + } +} diff --git a/test/jdk/java/awt/List/SetForegroundTest.java b/test/jdk/java/awt/List/SetForegroundTest.java new file mode 100644 index 00000000000..7b22e538508 --- /dev/null +++ b/test/jdk/java/awt/List/SetForegroundTest.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2005, 2024, 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 6246467 + * @summary Tests that list works correctly if user specified foreground colors on XToolkit/Motif + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual SetForegroundTest + */ + +import java.awt.Button; +import java.awt.Component; +import java.awt.Checkbox; +import java.awt.Choice; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Label; +import java.awt.List; +import java.awt.Panel; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.ScrollPane; + +public class SetForegroundTest { + + private static final String INSTRUCTIONS = """ + To make sure, that for each component + (Button, Checkbox, Label, List, TextArea, TextField, Choice) + in the frame, + the title exist and the color of the title is red. + If not, the test failed."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("SetForegroundTest Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(SetForegroundTest::createTestUI) + .build() + .awaitAndCheck(); + } + + private static Frame createTestUI() { + Frame frame = new Frame(); + ScrollPane sp = new ScrollPane() { + public Dimension getPreferredSize() { + return new Dimension(180, 180); + } + }; + Panel p = new Panel(); + Component childs[] = new Component[] {new Button("button"), + new Checkbox("checkbox"), + new Label("label"), + new List(3, false), + new TextArea("text area"), + new TextField("text field"), + new Choice()}; + + p.setLayout (new FlowLayout ()); + + sp.add(p); + + sp.validate(); + + frame.add(sp); + for (int i = 0; i < childs.length; i++){ + childs[i].setForeground(Color.red); + } + + for (int i = 0; i < childs.length; i++) { + p.add(childs[i]); + if (childs[i] instanceof List) { + ((List)childs[i]).add("list1"); + ((List)childs[i]).add("list2"); + } else if (childs[i] instanceof Choice) { + ((Choice)childs[i]).add("choice1"); + ((Choice)childs[i]).add("choice2"); + } + } + frame.pack(); + return frame; + } +} diff --git a/test/jdk/java/awt/MouseInfo/ContainerResizeMousePositionTest.java b/test/jdk/java/awt/MouseInfo/ContainerResizeMousePositionTest.java new file mode 100644 index 00000000000..72aa4d93a5c --- /dev/null +++ b/test/jdk/java/awt/MouseInfo/ContainerResizeMousePositionTest.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2003, 2024, 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. + */ + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/* + * @test + * @key headful + * @bug 4009555 + * @summary Unit test for a new method in Container class: getMousePosition(boolean) + * while Container resized. + */ + +public class ContainerResizeMousePositionTest { + private static Frame frame; + private static Button button; + private static Robot robot; + private static volatile Point frameLocation; + private static volatile Point newLoc; + private static boolean testSucceeded = false; + + private static final CountDownLatch eventCaught = new CountDownLatch(1); + + public static void main(String[] args) throws Exception { + try { + robot = new Robot(); + EventQueue.invokeAndWait(() -> createAndShowUI()); + robot.waitForIdle(); + robot.delay(1000); + testUI(); + } finally { + EventQueue.invokeAndWait(() -> { + if (frame != null) { + frame.dispose(); + } + }); + } + } + + private static void createAndShowUI() { + frame = new Frame("Testing getMousePosition() after resize"); + button = new Button("Button"); + frame.setLayout(new BorderLayout()); + frame.add(button); + frame.setSize(200, 200); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + private static void testUI() throws Exception { + EventQueue.invokeAndWait(() -> { + frameLocation = frame.getLocationOnScreen(); + newLoc = new Point(frame.getWidth() + 10, frame.getHeight() + 10); + }); + + robot.mouseMove(frameLocation.x + newLoc.x, frameLocation.y + newLoc.y); + EventQueue.invokeAndWait(() -> { + button.addComponentListener(new ResizeAdapter()); + frame.setSize(frame.getWidth() * 2, frame.getHeight() * 2); + frame.validate(); + }); + robot.waitForIdle(); + robot.delay(500); + + if (!eventCaught.await(2, TimeUnit.SECONDS)) { + throw new RuntimeException("componentResized Event isn't" + + " received within a timeout"); + } + + if (!testSucceeded) { + throw new RuntimeException("Container.getMousePosition(boolean)" + + " returned incorrect result while Container resized"); + } + } + + static class ResizeAdapter extends ComponentAdapter { + int testStageCounter = 0; + @Override + public void componentResized(ComponentEvent e) { + Point pTrue = frame.getMousePosition(true); + if (frame.getMousePosition(false) == null) { + testStageCounter++; + System.out.println(""" + TEST STAGE 1 PASSED: + Container.getMousePosition(false) + returned NULL over Child Component + during resize. + """); + } + if (pTrue != null) { + testStageCounter++; + System.out.println(""" + TEST STAGE 2 PASSED: + Container.getMousePosition(true) + returned NON-NULL over Child Component + during resize. + """); + } + if (pTrue != null && pTrue.x == newLoc.x && pTrue.y == newLoc.y) { + testStageCounter++; + System.out.println(""" + TEST STAGE 3 PASSED: + Container.getMousePosition(true) + returned correct result over Child Component + during resize. + """); + } + testSucceeded = testStageCounter == 3; + eventCaught.countDown(); + } + } +} diff --git a/test/jdk/java/awt/PopupMenu/PeripheryOfScreen.java b/test/jdk/java/awt/PopupMenu/PeripheryOfScreen.java new file mode 100644 index 00000000000..b169a7d9692 --- /dev/null +++ b/test/jdk/java/awt/PopupMenu/PeripheryOfScreen.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2005, 2024, 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. + */ + +import java.awt.Button; +import java.awt.Frame; +import java.awt.MenuItem; +import java.awt.PopupMenu; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/* + * @test + * @bug 6267162 + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @summary Popup Menu gets hidden below the screen when opened near the periphery + * of the screen, XToolkit Test if popup menu window is adjusted on screen + * when trying to show outside + * @run main/manual PeripheryOfScreen + */ + +public class PeripheryOfScreen { + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + Click on the button to show popup menu in the center of + frame. Move frame beyond the edge of screen and click on + button to show the popup menu and see if popup menu is + adjusted to the edge. + + Press Pass if popup menu behaves as per instruction, otherwise + press Fail. + """; + + PassFailJFrame.builder() + .title("PeripheryOfScreen Instruction") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(PeripheryOfScreen::createUI) + .build() + .awaitAndCheck(); + } + + private static Frame createUI () { + Frame f = new Frame("PeripheryOfScreen Test frame"); + Button b = new Button("Click to show popup menu"); + PopupMenu pm = new PopupMenu("Test menu"); + MenuItem i = new MenuItem("Click me"); + pm.add(i); + b.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + pm.show(f, 100, 100); + } + }); + f.add(b); + f.add(pm); + f.setSize(300, 200); + f.toFront(); + return f; + } +} diff --git a/test/jdk/java/awt/PopupMenu/PopupLeadingSeparatorTest.java b/test/jdk/java/awt/PopupMenu/PopupLeadingSeparatorTest.java new file mode 100644 index 00000000000..c9274e9b807 --- /dev/null +++ b/test/jdk/java/awt/PopupMenu/PopupLeadingSeparatorTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +import java.awt.Component; +import java.awt.Frame; +import java.awt.Font; +import java.awt.MenuItem; +import java.awt.PopupMenu; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/* + * @test + * @bug 4169155 + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @summary Popup menus get a leading separator on Motif system + * @run main/manual PopupLeadingSeparatorTest + */ + +public class PopupLeadingSeparatorTest { + public static void main(String[] args) throws Exception { + PopupLeadingSeparatorTest obj = new PopupLeadingSeparatorTest(); + String INSTRUCTIONS = """ + Press mouse button on the frame. Popup menu without leading + separator should appear. + If a PopupMenu behaves same, press Pass, else press Fail. + """; + + PassFailJFrame.builder() + .title("PopupLeadingSeparatorTest Instruction") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(obj::createUI) + .build() + .awaitAndCheck(); + } + + private Frame createUI() { + Frame f = new Frame("PopupLeadingSeparatorTest Test"); + PopupMenu popupMenu = new PopupMenu("Popup Menu Title"); + popupMenu.add(new MenuItem("Item1")); + PopupMenu cascadeMenu = new PopupMenu("Multifont menu"); + cascadeMenu.add(new MenuItem("Item1")); + MenuItem item2 = new MenuItem("Item2"); + item2.setFont(new Font("Serif", Font.BOLD, 36)); + cascadeMenu.add(item2); + + popupMenu.add(cascadeMenu); + f.add(popupMenu); + f.setSize(300, 150); + f.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent evt) { + popupMenu.show((Component) evt.getSource(), evt.getX(), evt.getY()); + } + }); + return f; + } +} diff --git a/test/jdk/java/awt/PopupMenu/PopupMenuShowTest.java b/test/jdk/java/awt/PopupMenu/PopupMenuShowTest.java new file mode 100644 index 00000000000..b36fdc5d19c --- /dev/null +++ b/test/jdk/java/awt/PopupMenu/PopupMenuShowTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Label; +import java.awt.MenuItem; +import java.awt.PopupMenu; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/* + * @test + * @bug 4168006 4196790 + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @summary Popup menu test fails on x86/Solaris 2.6 combination. + * @run main/manual PopupMenuShowTest + */ + +public class PopupMenuShowTest { + public static void main(String[] args) throws Exception { + PopupMenuShowTest obj = new PopupMenuShowTest(); + String INSTRUCTIONS = """ + Press the right mouse button in the PopupTest window. + If a PopupMenu appears, press Pass, else press Fail. + """; + + PassFailJFrame.builder() + .title("PopupMenuShowTest Instruction") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(obj::createUI) + .build() + .awaitAndCheck(); + } + + private Frame createUI() { + Frame f = new Frame("PopupMenuShowTest Test"); + f.setLayout(new FlowLayout()); + f.add(new Label("Press right mouse button inside this frame.")); + f.add(new Label("A pop-up menu should appear.")); + PopupMenu popupMenu = new PopupMenu("Popup Menu Title"); + MenuItem mi = new MenuItem("Menu Item"); + popupMenu.add(mi); + f.add(popupMenu); + f.setSize(400, 350); + f.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + popupMenu.show(e.getComponent(), e.getX(), e.getY()); + } + }); + return f; + } +} diff --git a/test/jdk/java/awt/PopupMenu/PopupMenuWithMenuBar.java b/test/jdk/java/awt/PopupMenu/PopupMenuWithMenuBar.java new file mode 100644 index 00000000000..1a927e29f84 --- /dev/null +++ b/test/jdk/java/awt/PopupMenu/PopupMenuWithMenuBar.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 1998, 2024, 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. + */ + +import java.awt.Frame; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.PopupMenu; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/* + * @test + * @bug 4038140 + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @summary Test for functionality of PopupMenuWithMenuBar + * @run main/manual PopupMenuWithMenuBar + */ + +public class PopupMenuWithMenuBar { + public static void main(String[] args) throws Exception { + PopupMenuWithMenuBar obj = new PopupMenuWithMenuBar(); + String INSTRUCTIONS = """ + There was a bug that prevented the popup menu from appearing properly + (if even at all) for a frame window when there is also a menu bar. + + Right click inside the frame window to display the popup window. If + the popup menu appears normally, then the test is successful and the + bug has been fixed."""; + + PassFailJFrame.builder() + .title("PopupMenuWithMenuBar Instruction") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(obj::createUI) + .build() + .awaitAndCheck(); + } + + private Frame createUI() { + Frame f = new Frame("PopupMenuWithMenuBar Test"); + f.setBounds(10, 10, 300, 250); + MenuBar menuBar = new MenuBar(); + Menu fileMenu = createFileMenu(); + menuBar.add(fileMenu); + f.setMenuBar(menuBar); + PopupMenu popupMenu = createPopupMenu(); + f.add(popupMenu); + f.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + popupMenu.show(f, e.getX(), e.getY()); + } + }); + return f; + } + + private Menu createFileMenu() { + String[] menu1Labels = new String[] + {"Save As", "Save As", "Quit"}; + MenuItem menuItem; + Menu returnMenu = new Menu("File"); + for (int menu1Index = 0; menu1Index < menu1Labels.length; menu1Index++) { + menuItem = new MenuItem(menu1Labels[menu1Index]); + returnMenu.add(menuItem); + } + return returnMenu; + } + + private PopupMenu createPopupMenu() { + String[] popupLabels = new String[] + {"Popup 1", "Popup 2", "Quit"}; + MenuItem menuItem; + PopupMenu returnMenu = new PopupMenu("Popups"); + for (int popupIndex = 0; popupIndex < popupLabels.length; popupIndex++) { + menuItem = new MenuItem(popupLabels[popupIndex]); + returnMenu.add(menuItem); + } + return returnMenu; + } +} diff --git a/test/jdk/java/awt/PopupMenu/PopupOnButton.java b/test/jdk/java/awt/PopupMenu/PopupOnButton.java new file mode 100644 index 00000000000..581714bf76a --- /dev/null +++ b/test/jdk/java/awt/PopupMenu/PopupOnButton.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +import java.awt.Button; +import java.awt.Component; +import java.awt.Frame; +import java.awt.MenuItem; +import java.awt.PopupMenu; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/* + * @test + * @bug 4181790 + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @summary Tests a popup menu on a button. + * @run main/manual PopupOnButton + */ + +public class PopupOnButton { + public static void main(String[] args) throws Exception { + PopupOnButton obj = new PopupOnButton(); + String INSTRUCTIONS = """ + Right-click on the button. + Popup Menu should appear and behave fine. + If a PopupMenu appears, press Pass, else press Fail. + """; + + PassFailJFrame.builder() + .title("PopupOnButton Instruction") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(obj::createUI) + .build() + .awaitAndCheck(); + } + + private Frame createUI() { + Frame f = new Frame("PopupOnButton Test"); + Button b = new Button("button with popup menu"); + PopupMenu m = new PopupMenu("popup"); + m.add(new MenuItem("item1")); + m.add(new MenuItem("item2")); + m.add(new MenuItem("item3")); + b.add(m); + b.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + if (e.isPopupTrigger()) { + m.show((Component) e.getSource(), e.getX(), e.getY()); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + if (e.isPopupTrigger()) { + m.show((Component) e.getSource(), e.getX(), e.getY()); + } + } + }); + + f.add(b); + f.setSize(200, 150); + return f; + } + } diff --git a/test/jdk/java/awt/PrintJob/PrintCompatibilityTest.java b/test/jdk/java/awt/PrintJob/PrintCompatibilityTest.java new file mode 100644 index 00000000000..a2433f45547 --- /dev/null +++ b/test/jdk/java/awt/PrintJob/PrintCompatibilityTest.java @@ -0,0 +1,446 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +import java.awt.Button; +import java.awt.Canvas; +import java.awt.Checkbox; +import java.awt.Choice; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.JobAttributes; +import java.awt.Label; +import java.awt.List; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.PageAttributes; +import java.awt.Panel; +import java.awt.PrintJob; +import java.awt.Scrollbar; +import java.awt.ScrollPane; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.JobAttributes.DialogType; +import java.awt.PageAttributes.OriginType; + +import java.util.Enumeration; +import java.util.Properties; + +/* + * @test + * @bug 4247583 + * @key printer + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @summary Tests that the old Properties API still works + * @run main/manual PrintCompatibilityTest + */ + +public class PrintCompatibilityTest { + + public static void main(String[] args) throws Exception { + + String INSTRUCTIONS = """ + A frame window will appear. + Choose 'Print to Printer...' from the 'Print' menu. Make sure that you print + to a printer, not a file. Examine the output and verify that the frame and all + the components in it get printed properly. + + Known problems: + * The text in the second row of the menubar is not indented correctly. + + You can also use the 'Print to Screen...' command for a quick manual check that + printing works, but this is only for debugging purposes."""; + + PassFailJFrame.builder() + .title("PrintComponentTest Test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(60) + .testTimeOut(10) + .testUI(new MainFrame()) + .logArea(8) + .build() + .awaitAndCheck(); + } +} + +class MainFrame extends Frame { + private LWContainer lwc; + + public MainFrame() { + super("PrintCompatibilityTest"); + + setSize(800, 400); + setLayout(new FlowLayout()); + + // peered components + Button button = new Button("Button"); + button.setFont(new Font("Dialog", Font.PLAIN, 12)); + add(button); + add(new TestCanvas()); + Checkbox cbox = new Checkbox("Checkbox", true); + cbox.setFont(new Font("DialogInput", Font.PLAIN, 12)); + add(cbox); + Choice choice = new Choice(); + choice.add("Choice 1"); + choice.add("Choice Two"); + choice.setFont(new Font("Monospaced", Font.PLAIN, 12)); + add(choice); + Label label = new Label("Label"); + label.setFont(new Font("Serif", Font.PLAIN, 12)); + add(label); + List list = new List(); + list.add("List 1"); + list.add("List Two"); + list.setFont(new Font("SansSerif", Font.PLAIN, 12)); + add(list); + add(new Scrollbar(Scrollbar.VERTICAL) ); + add(new Scrollbar(Scrollbar.HORIZONTAL) ); + ScrollPane scrollpane = new ScrollPane(); + Button spButton = new Button("Button in a scrollpane"); + spButton.setFont(new Font("Monospaced", Font.PLAIN, 12)); + scrollpane.add(spButton); + add(scrollpane); + TextArea textarea = new TextArea("TextArea", 3, 30); + textarea.setFont(new Font("Dialog", Font.ITALIC, 10)); + add(textarea); + TextField textfield = new TextField("TextField"); + textfield.setFont(new Font("DialogInput", Font.ITALIC, 10)); + add(textfield); + + // nested components + Panel panel1 = new Panel(); + panel1.setLayout(new FlowLayout()); + panel1.setBackground(Color.red); + this.add(panel1); + + Button p1Button = new Button("level 2"); + p1Button.setFont(new Font("Monospaced", Font.ITALIC, 10)); + panel1.add(p1Button); + + Panel panel2 = new Panel(); + panel2.setLayout(new FlowLayout()); + panel2.setBackground(Color.green); + panel1.add(panel2); + + Button p2Button = new Button("level 3"); + p2Button.setFont(new Font("Serif", Font.ITALIC, 10)); + panel2.add(p2Button); + + + // lightweight components + LWButton lwbutton = new LWButton("LWbutton"); + lwbutton.setFont(new Font("SansSerif", Font.ITALIC, 10)); + add(lwbutton); + + lwc = new LWContainer("LWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainer"); + lwc.setFont(new Font("Monospaced", Font.ITALIC, 10)); + add(lwc); + Button lwcButton1 = new Button("HW Button 1"); + Button lwcButton2 = new Button("HW Button 2"); + LWButton lwcButton3 = new LWButton("LW Button"); + lwcButton1.setFont(new Font("Dialog", Font.BOLD, 14)); + lwcButton2.setFont(new Font("DialogInput", Font.BOLD, 14)); + lwcButton3.setFont(new Font("Monospaced", Font.BOLD, 14)); + lwc.add(lwcButton1); + lwc.add(lwcButton2); + lwc.add(lwcButton3); + + // overlapping components + add(new ZOrderPanel()); + + /////////////////////// + + Menu menu = new Menu("Print"); + Menu menu2 = new Menu("File"); + Menu menu3 = new Menu("Edit"); + Menu menu4 = new Menu("ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLong"); + menu2.setFont(new Font("SansSerif", Font.BOLD, 20)); + menu2.setEnabled(false); + menu3.setFont(new Font("Monospaced", Font.ITALIC, 18)); + menu3.setEnabled(false); + menu4.setEnabled(false); + MenuItem itemPrinter = new MenuItem("Print to Printer..."); + MenuItem itemScreen = new MenuItem("Print to Screen..."); + menu.add(itemPrinter); + menu.add(itemScreen); + MenuBar menuBar = new MenuBar(); + menuBar.add( menu ); + menuBar.add( menu2 ); + menuBar.add( menu3 ); + menuBar.add( menu4 ); + setMenuBar(menuBar); + + itemPrinter.addActionListener( new ActionPrint() ); + itemScreen.addActionListener( new ActionPrintToScreen() ); + setVisible(true); + } + + static void printProps(Properties props) + { + Enumeration propNames = props.propertyNames(); + while (propNames.hasMoreElements()) { + String propName = (String)propNames.nextElement(); + PassFailJFrame.log( propName + " = " + props.getProperty(propName)); + } + } + + class ActionPrint implements ActionListener { + private final int ITERATIONS = 1; + private Properties props = new Properties(); + + public void actionPerformed(ActionEvent ev) { + PassFailJFrame.log("About to show print dialog..."); + printProps(props); + PrintJob pj = getToolkit().getPrintJob( + MainFrame.this, "Print test!", props); + if (pj == null) { + return; + } + Dimension d = pj.getPageDimension(); + PassFailJFrame.log("About to print..."); + PassFailJFrame.log("Dimensions: " + d); + printProps(props); + + // For xor mode set, there is a printing issue with number of copies to be print. + // So, ITERATIONS are changed to 1 from 3. + // So, for now the XOR related code is commented out. + + //boolean xor = false; + + for (int i = 0; i < ITERATIONS; i++) { + Graphics g = pj.getGraphics(); + g.setColor(Color.red); + //if (xor) { + // g.setXORMode(Color.blue); + //} + g.translate(13, 13); + printAll(g); + g.dispose(); + //xor = (xor) ? false : true; + } + + // For xor mode set, LWC components don't get printed. + // So, for now the code is commented out and separate bug + // (JDK-8340495) is filed to handle it. + + // one more page so that we can test printing a lightweight + // at the top of the hierarchy (BugId 4212564) + //Graphics g = pj.getGraphics(); + //g.setColor(Color.red); + //g.translate(13, 13); + //lwc.printAll(g); + //g.dispose(); + // end 4212564 + + pj.end(); + } + } + + class ActionPrintToScreen implements ActionListener { + public void actionPerformed(ActionEvent ev) { + PrintFrame printFrame = new PrintFrame(MainFrame.this); + printFrame.show(); + Graphics g = printFrame.getGraphics(); + g.setColor(Color.red); + printAll(g); + g.dispose(); + } + } + + // Frame window that displays results of printing + // main window to a screen Graphics-- useful for + // quick testing of printing + class PrintFrame extends Frame + { + private Component printComponent; + public PrintFrame( Component c ) + { + super("Print to Screen"); + printComponent = c ; + addWindowListener( new WindowAdapter() { + public void windowClosing(WindowEvent ev) { + setVisible(false); + dispose(); + } + } + ); + setSize(printComponent.getSize()); + setResizable(false); + } + + public void paint( Graphics g ) { + printComponent.printAll(g); + } + } + + class LWButton extends Component { + String label; + int width = 100; + int height = 30; + + public LWButton(String label) { + super(); + this.label = label; + } + + public void paint(Graphics g) { + Dimension d = getSize(); + g.setColor(Color.orange); + g.setFont(getFont()); + g.fillRect(0, 0, d.width, d.height); + g.setColor(Color.black); + int x = 5; + int y = (d.height - 5); + g.drawString(label, x, y); + } + + public Dimension getPreferredSize() + { + return new Dimension(width, height); + } + } + + class LWContainer extends Container { + String label; + int width = 300; + int height = 100; + + public LWContainer(String label) { + super(); + this.label = label; + setLayout(new FlowLayout()); + } + + public void paint(Graphics g) { + super.paint(g); + Dimension d = getSize(); + g.setColor(Color.green); + g.setFont(getFont()); + g.drawLine(0, 0, d.width - 1, 0); + g.drawLine(d.width - 1, 0, d.width - 1, d.height - 1); + g.drawLine(d.width - 1, d.height - 1, 0, d.height - 1); + g.drawLine(0, d.height - 1, 0, 0); + g.setColor(Color.black); + int x = 5; + int y = (d.height - 5); + g.drawString(label, x, y); + } + + public Dimension getPreferredSize() + { + return new Dimension(width, height); + } + } + + class TestCanvas extends Canvas { + int width = 100; + int height = 100; + + public void paint(Graphics g) { + g.setColor(Color.blue); + g.fillRoundRect(10, 10, 50, 50, 15, 30); + g.setColor(Color.red); + g.fillOval(70, 70, 25, 25); + } + public Dimension getPreferredSize() { + return new Dimension(width, height); + } + } + + class ZOrderPanel extends Panel + { + ZOrderPanel() + { + setLayout(null); + + Component first, second, third, fourth; + + setVisible(true); + // add first component + first = makeBox("Second", Color.blue, + new Font("Serif", Font.BOLD, 14), + -1); + // insert on top + second = makeBox("First", Color.yellow, + new Font("SansSerif", Font.BOLD, 14), + 0); + // put at the back + fourth = makeBox("Fourth", Color.red, + new Font("Monospaced", Font.BOLD, 14), + 2); + // insert in last position + third = makeBox("Third", Color.green, + new Font("Dialog", Font.PLAIN, 12), + 3); + // swap third and fourth to correct positions + remove(third); + add(third, 2); + // re-validate so third and fourth peers change position + validate(); + // now make things really interesting with a lightweight + // component at the top of the z-order, that should print + // _below_ the native guys to match the screen... + add(new LWButton("LWButton"), 0); + } + + public Dimension preferredSize() + { + return new Dimension(260, 80); + } + + public void layout() + { + int i, n; + Insets ins = getInsets(); + n = getComponentCount(); + for (i = n-1; i >= 0; i--) { + Component p = getComponent(i); + p.setBounds(ins.left + 40 * i, ins.top + 5 * i, 60, 60); + } + } + + public Component makeBox(String s, Color c, Font f, int index) + { + Label l = new Label(s); + l.setBackground(c); + l.setAlignment(Label.RIGHT); + l.setFont(f); + add(l, index); + validate(); + return l; + } + } +} diff --git a/test/jdk/java/awt/PrintJob/PrintComponentTest.java b/test/jdk/java/awt/PrintJob/PrintComponentTest.java new file mode 100644 index 00000000000..d568c5a4279 --- /dev/null +++ b/test/jdk/java/awt/PrintJob/PrintComponentTest.java @@ -0,0 +1,486 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +import java.awt.Button; +import java.awt.Canvas; +import java.awt.Checkbox; +import java.awt.Choice; +import java.awt.Color; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.JobAttributes; +import java.awt.Label; +import java.awt.List; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.PageAttributes; +import java.awt.Panel; +import java.awt.PrintJob; +import java.awt.Scrollbar; +import java.awt.ScrollPane; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.JobAttributes.DialogType; +import java.awt.PageAttributes.OriginType; + + +/* + * @test + * @bug 4111262 4035285 4038900 4046147 4049680 4084038 4100004 4105875 + * @bug 4117502 4037486 4068433 4128031 4151161 4151707 4155884 4212564 + * @bug 4025626 4029565 4034365 4036068 4040622 4061890 4067405 4086256 + * @bug 4113827 4116722 4121984 4145350 4146510 4172659 4179886 4218471 + * @bug 4219657 4227128 4242308 4245917 4265746 + * @key printer + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @summary Test printing of lightweight (and heavyweight) components + * @run main/manual PrintComponentTest + */ + +public class PrintComponentTest { + public static void main(String[] args) throws Exception { + + String INSTRUCTIONS = """ + A frame window will appear. + Choose 'Print to Printer...' from the 'Print' menu. Examine the output + and verify that the frame and all the components in it get printed properly. + + Print using both 'Portrait' and 'Landscape' orientation. + Verify that the paper dimensions printed to standard error + are exactly inverted. + (That is, if the output for 'Portrait' is + "Dimensions: java.awt.Dimension[width=612,height=792]" then the output + for 'Landscape' should be "Dimensions: java.awt.Dimension[width=792, height=612].) + + Now, attempt to print a second time. When the print dialog box appears, + however, cancel the print request. + Verify that _no_ output is sent to standard error. + + You should attempt to print with both the native and common print dialogs, + as well as with no dialog. + Note that on Linux the native and common print dialogs are identical. + + On Windows, the common print dialog communicates with the printer to + determine supported paper sizes and duplex capability. + Verify that these constraints are properly enforced in the common dialog + for the target printer. + + Known problems: + * The text in the second row of the menubar is not indented + correctly. + + You can also use the 'Print to Screen...' command for a quick manual + check that printing works, but this is only for debugging purposes."""; + + PassFailJFrame.builder() + .title("PrintComponentTest Test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(60) + .testTimeOut(10) + .testUI(new MainFrame()) + .logArea(8) + .build() + .awaitAndCheck(); + } +} + +class MainFrame extends Frame { + private LWContainer lwc; + + public MainFrame() { + super("PrintComponentTest"); + + setSize(800, 400); + setLayout(new FlowLayout()); + + // peered components + Button button = new Button("Button"); + button.setFont(new Font("Dialog", Font.PLAIN, 12)); + add(button); + add(new TestCanvas()); + Checkbox cbox = new Checkbox("Checkbox", true); + cbox.setFont(new Font("DialogInput", Font.PLAIN, 12)); + add(cbox); + Choice choice = new Choice(); + choice.add("Choice 1"); + choice.add("Choice Two"); + choice.setFont(new Font("Monospaced", Font.PLAIN, 12)); + add(choice); + Label label = new Label("Label"); + label.setFont(new Font("Serif", Font.PLAIN, 12)); + add(label); + List list = new List(); + list.add("List 1"); + list.add("List Two"); + list.setFont(new Font("SansSerif", Font.PLAIN, 12)); + add(list); + add(new Scrollbar(Scrollbar.VERTICAL) ); + add(new Scrollbar(Scrollbar.HORIZONTAL) ); + ScrollPane scrollpane = new ScrollPane(); + Button spButton = new Button("Button in a scrollpane"); + spButton.setFont(new Font("Monospaced", Font.PLAIN, 12)); + scrollpane.add(spButton); + add(scrollpane); + TextArea textarea = new TextArea("TextArea", 3, 30); + textarea.setFont(new Font("Dialog", Font.ITALIC, 10)); + add(textarea); + TextField textfield = new TextField("TextField"); + textfield.setFont(new Font("DialogInput", Font.ITALIC, 10)); + add(textfield); + + // nested components + Panel panel1 = new Panel(); + panel1.setLayout(new FlowLayout()); + panel1.setBackground(Color.red); + this.add(panel1); + + Button p1Button = new Button("level 2"); + p1Button.setFont(new Font("Monospaced", Font.ITALIC, 10)); + panel1.add(p1Button); + + Panel panel2 = new Panel(); + panel2.setLayout(new FlowLayout()); + panel2.setBackground(Color.green); + panel1.add(panel2); + + Button p2Button = new Button("level 3"); + p2Button.setFont(new Font("Serif", Font.ITALIC, 10)); + panel2.add(p2Button); + + + // lightweight components + LWButton lwbutton = new LWButton("LWbutton"); + lwbutton.setFont(new Font("SansSerif", Font.ITALIC, 10)); + add(lwbutton); + + lwc = new LWContainer("LWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainerLWContainer"); + lwc.setFont(new Font("Monospaced", Font.ITALIC, 10)); + add(lwc); + Button lwcButton1 = new Button("HW Button 1"); + Button lwcButton2 = new Button("HW Button 2"); + LWButton lwcButton3 = new LWButton("LW Button"); + lwcButton1.setFont(new Font("Dialog", Font.BOLD, 14)); + lwcButton2.setFont(new Font("DialogInput", Font.BOLD, 14)); + lwcButton3.setFont(new Font("Monospaced", Font.BOLD, 14)); + lwc.add(lwcButton1); + lwc.add(lwcButton2); + lwc.add(lwcButton3); + + // overlapping components + add(new ZOrderPanel()); + + /////////////////////// + + Menu menu = new Menu("Print"); + Menu menu2 = new Menu("File"); + Menu menu3 = new Menu("Edit"); + Menu menu4 = new Menu("ReallyReallyReallyReallyReallyReallyReallyReally" + + "ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReally" + + "ReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLong"); + menu2.setFont(new Font("SansSerif", Font.BOLD, 20)); + menu2.setEnabled(false); + menu3.setFont(new Font("Monospaced", Font.ITALIC, 18)); + menu3.setEnabled(false); + menu4.setEnabled(false); + MenuItem itemJFC = + new MenuItem("Print to Printer with Cross-Platform Dialog..."); + itemJFC.setActionCommand("common"); + MenuItem itemNative = + new MenuItem("Print to Printer with Native Dialog..."); + itemNative.setActionCommand("native"); + MenuItem itemBackground = + new MenuItem("Print to Printer in Background"); + itemBackground.setActionCommand("none"); + MenuItem itemScreen = new MenuItem("Print to Screen..."); + menu.add(itemJFC); + menu.add(itemNative); + menu.add(itemBackground); + menu.add(itemScreen); + MenuBar menuBar = new MenuBar(); + menuBar.add( menu ); + menuBar.add( menu2 ); + menuBar.add( menu3 ); + menuBar.add( menu4 ); + setMenuBar(menuBar); + + ActionPrint actionPrint = new ActionPrint(); + + itemJFC.addActionListener( actionPrint ); + itemNative.addActionListener( actionPrint ); + itemBackground.addActionListener( actionPrint ); + itemScreen.addActionListener( new ActionPrintToScreen() ); + } + + class ActionPrint implements ActionListener { + private final int ITERATIONS = 1; + private PageAttributes pageAttributes = new PageAttributes(); + private JobAttributes jobAttributes = new JobAttributes(); + + public void actionPerformed(ActionEvent ev) { + DialogType dialog; + if (ev.getActionCommand().equals("common")) { + dialog = DialogType.COMMON; + } else if (ev.getActionCommand().equals("native")) { + dialog = DialogType.NATIVE; + } else { + dialog = DialogType.NONE; + } + jobAttributes.setDialog(dialog); + pageAttributes.setOrigin(OriginType.PRINTABLE); + System.err.println(jobAttributes); + System.err.println(pageAttributes); + + PassFailJFrame.log("About to show print dialog..."); + + PrintJob pj = getToolkit().getPrintJob( + MainFrame.this, "Print test!", jobAttributes, pageAttributes); + if (pj == null) { + return; + } + Dimension d = pj.getPageDimension(); + PassFailJFrame.log("About to print..."); + PassFailJFrame.log("Dimensions: " + d); + System.err.println(jobAttributes); + System.err.println(pageAttributes); + + // For xor mode set, there is a printing issue with number of copies to be print. + // So, ITERATIONS are changed to 1 from 3. + // So, for now the XOR related code is commented out. + + //boolean xor = false; + + for (int i = 0; i < ITERATIONS; i++) { + Graphics g = pj.getGraphics(); + g.setColor(Color.red); + //if (xor) { + // g.setXORMode(Color.blue); + //} + printAll(g); + g.dispose(); + //xor = (xor) ? false : true; + } + + // For xor mode set, LWC components don't get printed. + // So, for now the code is commented out and separate bug + // (JDK-8340495) is filed to handle it. + + // one more page so that we can test printing a lightweight + // at the top of the hierarchy (BugId 4212564) + //Graphics g = pj.getGraphics(); + //g.setColor(Color.red); + //lwc.printAll(g); + //g.dispose(); + // end 4212564 + + pj.end(); + } + } + + class ActionPrintToScreen implements ActionListener { + public void actionPerformed(ActionEvent ev) { + PrintFrame printFrame = new PrintFrame(MainFrame.this); + printFrame.show(); + Graphics g = printFrame.getGraphics(); + g.setColor(Color.red); + printAll(g); + g.dispose(); + } + } + + // Frame window that displays results of printing + // main window to a screen Graphics-- useful for + // quick testing of printing + class PrintFrame extends Frame + { + private Component printComponent; + public PrintFrame( Component c ) + { + super("Print to Screen"); + printComponent = c ; + addWindowListener( new WindowAdapter() { + public void windowClosing(WindowEvent ev) { + setVisible(false); + dispose(); + } + } + ); + setSize(printComponent.getSize()); + setResizable(false); + } + + public void paint( Graphics g ) { + printComponent.printAll(g); + } + } + + class LWButton extends Component { + String label; + int width = 100; + int height = 30; + + public LWButton(String label) { + super(); + this.label = label; + } + + public void paint(Graphics g) { + Dimension d = getSize(); + g.setColor(Color.orange); + g.setFont(getFont()); + g.fillRect(0, 0, d.width, d.height); + g.setColor(Color.black); + int x = 5; + int y = (d.height - 5); + g.drawString(label, x, y); + } + + public Dimension getPreferredSize() + { + return new Dimension(width, height); + } + } + + class LWContainer extends Container { + String label; + int width = 300; + int height = 100; + + public LWContainer(String label) { + super(); + this.label = label; + setLayout(new FlowLayout()); + } + + public void paint(Graphics g) { + super.paint(g); + Dimension d = getSize(); + g.setColor(Color.green); + g.setFont(getFont()); + g.drawLine(0, 0, d.width - 1, 0); + g.drawLine(d.width - 1, 0, d.width - 1, d.height - 1); + g.drawLine(d.width - 1, d.height - 1, 0, d.height - 1); + g.drawLine(0, d.height - 1, 0, 0); + g.setColor(Color.black); + int x = 5; + int y = (d.height - 5); + g.drawString(label, x, y); + } + + public Dimension getPreferredSize() + { + return new Dimension(width, height); + } + } + + class TestCanvas extends Canvas { + int width = 100; + int height = 100; + + public void paint(Graphics g) { + g.setColor(Color.blue); + g.fillRoundRect(10, 10, 50, 50, 15, 30); + g.setColor(Color.red); + g.fillOval(70, 70, 25, 25); + } + public Dimension getPreferredSize() { + return new Dimension(width, height); + } + } + + class ZOrderPanel extends Panel + { + ZOrderPanel() + { + setLayout(null); + + Component first, second, third, fourth; + + setVisible(true); + // add first component + first = makeBox("Second", Color.blue, + new Font("Serif", Font.BOLD, 14), + -1); + // insert on top + second = makeBox("First", Color.yellow, + new Font("SansSerif", Font.BOLD, 14), + 0); + // put at the back + fourth = makeBox("Fourth", Color.red, + new Font("Monospaced", Font.BOLD, 14), + 2); + // insert in last position + third = makeBox("Third", Color.green, + new Font("Dialog", Font.PLAIN, 12), + 3); + // swap third and fourth to correct positions + remove(third); + add(third, 2); + // re-validate so third and fourth peers change position + validate(); + // now make things really interesting with a lightweight + // component at the top of the z-order, that should print + // _below_ the native guys to match the screen... + add(new LWButton("LWButton"), 0); + } + + public Dimension preferredSize() + { + return new Dimension(260, 80); + } + + public void layout() + { + int i, n; + Insets ins = getInsets(); + n = getComponentCount(); + for (i = n-1; i >= 0; i--) { + Component p = getComponent(i); + p.setBounds(ins.left + 40 * i, ins.top + 5 * i, 60, 60); + } + } + + public Component makeBox(String s, Color c, Font f, int index) + { + Label l = new Label(s); + l.setBackground(c); + l.setAlignment(Label.RIGHT); + l.setFont(f); + add(l, index); + validate(); + return l; + } + } +} diff --git a/test/jdk/java/awt/PrintJob/ScaledImagePrintingTest.java b/test/jdk/java/awt/PrintJob/ScaledImagePrintingTest.java new file mode 100644 index 00000000000..838c9210e30 --- /dev/null +++ b/test/jdk/java/awt/PrintJob/ScaledImagePrintingTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 1999, 2024, 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. + */ + +import java.awt.Button; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.PrintJob; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/* + * @test + * @bug 4257962 + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @summary tests that scaled images are printed at resolution greater than 72dpi + * @run main/manual ScaledImagePrintingTest + */ + +public class ScaledImagePrintingTest { + + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + Press 'Print' button from the test UI. + + The test will bring up a print dialog. Select a printer and proceed. + Verify that the output is a series of a horizontal lines in a + rectangular box in the center of the page. + + If output is as mentioned above, press Pass else Fail."""; + + PassFailJFrame.builder() + .title("ScaledImagePrintingTest Test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(40) + .testTimeOut(5) + .testUI(ScaledImagePrintingTest::createUI) + .logArea(8) + .build() + .awaitAndCheck(); + } + + private static Frame createUI() { + Frame frame = new Frame("ResolutionTest"); + Button b = new Button("Print"); + b.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + PrintJob pj = frame.getToolkit().getPrintJob(frame, "ResolutionTest", null); + PassFailJFrame.log("Printing code started."); + if (pj != null) { + Graphics g = pj.getGraphics(); + g.setColor(Color.black); + int w = 200; + int h = 200; + Image image = frame.createImage(w, h); + Graphics imageGraphics = image.getGraphics(); + Dimension d = pj.getPageDimension(); + imageGraphics.setColor(Color.black); + for (int i = 0; i < h; i += 20) { + imageGraphics.drawLine(0, i, w, i); + } + g.translate(d.width / 2, d.height / 2); + g.drawImage(image, -w / 8, -h / 8, w / 4, h / 4, frame); + g.setColor(Color.black); + g.drawRect(-w / 4, -h / 4, w / 2, h / 2); + imageGraphics.dispose(); + g.dispose(); + pj.end(); + } + PassFailJFrame.log("Printing code finished."); + } + }); + frame.add(b); + frame.setSize(50, 50); + return frame; + } +} diff --git a/test/jdk/java/awt/Window/bug4189244.java b/test/jdk/java/awt/Window/bug4189244.java new file mode 100644 index 00000000000..df37d2fce0e --- /dev/null +++ b/test/jdk/java/awt/Window/bug4189244.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2000, 2024, 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 4189244 + * @summary Swing Popup menu is not being refreshed (cleared) under a Dialog + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @requires (os.family == "windows") + * @run main/manual bug4189244 +*/ + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; + +public class bug4189244 { + + private static final String INSTRUCTIONS = """ + This is Windows only test! + + Click right button on frame to show popup menu. + (menu should be placed inside frame otherwise bug is not reproducible) + click on any menu item (dialog will be shown). + close dialog. + if you see part of popupmenu, under dialog, before it is closed, + then test failed, else passed."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("bug4189244 Instructions") + .instructions(INSTRUCTIONS) + .rows((int)INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(bug4189244::createTestUI) + .build() + .awaitAndCheck(); + } + + + private static JFrame createTestUI() { + RefreshBug panel = new RefreshBug(); + JFrame frame = new JFrame("Popup refresh bug"); + + frame.add(panel, BorderLayout.CENTER); + panel.init(); + frame.setSize(400, 400); + return frame; + } +} + +class RefreshBug extends JPanel implements ActionListener { + JPopupMenu _jPopupMenu = new JPopupMenu(); + + public void init() { + JMenuItem menuItem; + JButton jb = new JButton("Bring the popup here and select an item"); + + this.add(jb, BorderLayout.CENTER); + + for(int i = 1; i < 10; i++) { + menuItem = new JMenuItem("Item " + i); + menuItem.addActionListener(this); + _jPopupMenu.add(menuItem); + } + + MouseListener ml = new MouseAdapter() { + public void mouseReleased(MouseEvent e) { + if (e.isPopupTrigger()) { + _jPopupMenu.show(e.getComponent(), + e.getX(), e.getY()); + } + } + }; + this.addMouseListener(ml); + + jb.addMouseListener(ml); + + } + + // An action is requested by the user + public void actionPerformed(java.awt.event.ActionEvent e) { + JOptionPane.showMessageDialog(this, + "Check if there is some popup left under me\n"+ + "if not, retry and let the popup appear where i am", + "WARNING", + JOptionPane.WARNING_MESSAGE); + + } +} diff --git a/test/jdk/java/awt/color/XAWTDifference/XAWTColors.jpg b/test/jdk/java/awt/color/XAWTDifference/XAWTColors.jpg new file mode 100644 index 00000000000..f53b30407cc Binary files /dev/null and b/test/jdk/java/awt/color/XAWTDifference/XAWTColors.jpg differ diff --git a/test/jdk/java/awt/color/XAWTDifference/XAWTDifference.java b/test/jdk/java/awt/color/XAWTDifference/XAWTDifference.java new file mode 100644 index 00000000000..ef0f5aacf44 --- /dev/null +++ b/test/jdk/java/awt/color/XAWTDifference/XAWTDifference.java @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2005, 2024, 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. + */ + +import java.awt.Button; +import java.awt.Canvas; +import java.awt.Checkbox; +import java.awt.Choice; +import java.awt.Component; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.Image; +import java.awt.Label; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.Panel; +import java.awt.PopupMenu; +import java.awt.ScrollPane; +import java.awt.Scrollbar; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.Window; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; + +/* + * @test + * @bug 5092883 6513478 7154025 + * @requires (os.family == "linux") + * @summary REGRESSION: SystemColor class gives back wrong values under Linux + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual XAWTDifference + */ + +public class XAWTDifference { + + private static final String INSTRUCTIONS = """ + You would see a frame with title "XAWTDifference Test Frame". + + Test Frame (1) + + a) It has three columns in it. The 1st one with ordinary components. + The 2nd one with disabled components. + The 3rd one with uneditable components (only text components + are there). Verify that the difference between different states + is visible. + + Standard Frame (2) + + b) You would also see a frame named StandardFrame (2) + with a lot of components in it. Actually this is just a jpg-image + in a frame. Verify that every component in the frame (1) looks + similar to the same component in (2). + + They might differ in colors and be darker or brighter but + the whole picture should be the same. + + c) Also check the color of the MenuBar Items in the MenuBar and + the PopupMenu assigned to TextArea. + As you can't compare the colors of menu items with the picture + so just look if the are adequate enough. + """; + private static final int HGAP = 20; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("Test Instructions") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(XAWTDifference::createAndShowUI) + .positionTestUI(XAWTDifference::positionMultiTestUI) + .build() + .awaitAndCheck(); + } + + private static Panel addComponentsIntoPanel(boolean enabled, boolean editable) { + TextField tf = new TextField("TextField"); + TextArea ta = new TextArea("TextArea", 10, 10); + + Choice levelChooser = new Choice(); + levelChooser.add("Item #1"); + levelChooser.add("Item #2"); + + Button b = new Button("BUTTON"); + Label label = new Label("LABEL"); + java.awt.List list = new java.awt.List(4, false); + list.add("one"); + list.add("two"); + list.add("three"); + + Checkbox chb = new Checkbox(); + Scrollbar sb = new Scrollbar(Scrollbar.HORIZONTAL); + ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS); + sp.add(new TextArea("this is a textarea in scrollpane")); + sp.setSize(200, 200); + Canvas canvas = new Canvas(); + canvas.setSize(100, 100); + + //add popup menu to Button + final PopupMenu pm = new PopupMenu(); + MenuItem i1 = new MenuItem("Item1"); + MenuItem i2 = new MenuItem("Item2"); + MenuItem i3 = new MenuItem("Item3"); + i3.setEnabled(false); + pm.add(i1); + pm.add(i2); + pm.add(i3); + canvas.add(pm); + + ta.add(pm); + ta.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent me) { + if (me.isPopupTrigger()) { + pm.show(me.getComponent(), me.getX(), me.getY()); + } + } + }); + + ArrayList componentList = new ArrayList<>(); + + componentList.add(tf); + componentList.add(ta); + if (editable){ + componentList.add(levelChooser); + componentList.add(b); + componentList.add(label); + componentList.add(list); + componentList.add(chb); + componentList.add(sb); + componentList.add(sp); + componentList.add(canvas); + } else { + tf.setEditable(false); + ta.setEditable(false); + } + + Panel panel = new Panel(); + panel.setLayout(new GridLayout(0, 1)); + for (Component c : componentList) { + if (!enabled) { + c.setEnabled(false); + } + panel.add(c); + } + return panel; + } + + private static List createAndShowUI() { + Frame testFrame = new Frame("XAWTDifference Test Frame"); + StandardFrame standardFrame = new StandardFrame("StandardFrame"); + standardFrame.pack(); + + testFrame.setLayout(new GridLayout(1, 3)); + testFrame.add(addComponentsIntoPanel(true, true)); + testFrame.add(addComponentsIntoPanel(false, true)); + testFrame.add(addComponentsIntoPanel(true, false)); + + MenuItem mi1 = new MenuItem("Item1"); + MenuItem mi2 = new MenuItem("Item2"); + MenuItem mi3 = new MenuItem("Disabled Item3"); + mi3.setEnabled(false); + + MenuBar mb = new MenuBar(); + Menu enabledMenu = new Menu("Enabled Menu"); + Menu disabledMenu = new Menu("Disabled Menu"); + disabledMenu.setEnabled(false); + mb.add(enabledMenu); + mb.add(disabledMenu); + enabledMenu.add(mi1); + enabledMenu.add(mi2); + enabledMenu.add(mi3); + + testFrame.setMenuBar(mb); + testFrame.setSize(standardFrame.getWidth(), standardFrame.getHeight()); + return List.of(testFrame, standardFrame); + } + + private static void positionMultiTestUI(List windows, + PassFailJFrame.InstructionUI instructionUI) { + int x = instructionUI.getLocation().x + instructionUI.getSize().width + HGAP; + for (Window w : windows) { + w.setLocation(x, instructionUI.getLocation().y); + x += w.getWidth() + HGAP; + } + } + + private static class StandardFrame extends Frame { + public StandardFrame(String name) { + super(name); + String testPath = System.getProperty("test.src", "."); + Panel panel = new Panel(); + panel.add(new JLabel(new ImageIcon(testPath + File.separator + "XAWTColors.jpg"))); + add(panel); + } + } +} diff --git a/test/jdk/java/awt/geom/Arc2D/Arc2DHitTest.java b/test/jdk/java/awt/geom/Arc2D/Arc2DHitTest.java new file mode 100644 index 00000000000..de6b39d5c6f --- /dev/null +++ b/test/jdk/java/awt/geom/Arc2D/Arc2DHitTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 1999, 2024, 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 4178123 + * @summary Verifies that the Arc2D.contains(point) methods work correctly. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual Arc2DHitTest + */ + +import java.awt.Color; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Panel; +import java.awt.Point; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.geom.Arc2D; + +public class Arc2DHitTest { + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + This test displays an arc figure and lets the user click on it. + The arc will initially be drawn in red and only when the user clicks + within the arc in the window it will be redrawn into green otherwise + it should stay red. + + For convenience, the point being tested is drawn in black. Note + that rounding in the arc rendering routines may cause points near + the boundary of the arc to render incorrectly. Allow for a pixel + or two of leeway near the boundary. + """; + + PassFailJFrame.builder() + .title("Test Instructions") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(initialize()) + .build() + .awaitAndCheck(); + } + private static Frame initialize() { + Frame f = new Frame("Arc2DHitTest"); + ArcHitPanel panel = new ArcHitPanel(); + f.add(panel); + f.setSize(300, 250); + return f; + } +} + +class ArcHitPanel extends Panel { + private Arc2D arc; + private Point hit; + public ArcHitPanel() { + arc = new Arc2D.Float(10, 10, 100, 100, 0, 120, Arc2D.PIE); + this.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + hit = e.getPoint(); + repaint(); + } + }); + } + + @Override + public void paint(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.setColor(Color.white); + g2.fill(g2.getClipBounds()); + g2.setColor((hit != null && arc.contains(hit)) + ? Color.green : Color.red); + g2.fill(arc); + if (hit != null) { + g2.setColor(Color.black); + g2.fillRect(hit.x, hit.y, 1, 1); + } + } +} diff --git a/test/jdk/java/awt/geom/Arc2D/BoundsBug.java b/test/jdk/java/awt/geom/Arc2D/BoundsBug.java new file mode 100644 index 00000000000..a17f45f9dad --- /dev/null +++ b/test/jdk/java/awt/geom/Arc2D/BoundsBug.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 1999, 2024, 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 4197746 + * @summary Verifies that the getBounds2D method of Arc2D returns the + * correct result. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual BoundsBug + */ + +import java.awt.Color; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Panel; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.geom.Arc2D; +import java.awt.geom.Ellipse2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +public class BoundsBug { + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + This test displays three figures and draws the outline of their + bounding boxes. The bounding boxes should correctly encompass + the 3 figures. + + This test also paints two highlight rectangles at the ends of the + angular extents of the arc. The two highlights should correctly + appear at the outer circumference of the arc where the radii lines + from its center intersect that circumference. + """; + + PassFailJFrame.builder() + .title("Test Instructions") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(initialize()) + .build() + .awaitAndCheck(); + } + private static Frame initialize() { + Frame f = new Frame("BoundsBug"); + ArcPanel panel = new ArcPanel(); + f.add(panel); + f.setSize(300, 250); + return f; + } +} + +class ArcPanel extends Panel { + protected void drawPoint(Graphics2D g2, Point2D p) { + g2.setColor(Color.green); + g2.fill(new Rectangle2D.Double(p.getX() - 5, p.getY() - 5, 10, 10)); + } + + protected void drawShapeAndBounds(Graphics2D g2, Shape s) { + g2.setColor(Color.orange); + g2.fill(s); + g2.setColor(Color.black); + g2.draw(s); + + Rectangle2D r = s.getBounds2D(); + g2.setColor(Color.gray); + g2.draw(r); + } + + @Override + public void paint(Graphics g) { + Graphics2D g2 = (Graphics2D)g; + g2.setColor(Color.white); + g2.fill(g.getClipBounds()); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + // Create some interesting shapes. + Ellipse2D ellipse = new Ellipse2D.Float(20, 40, 60, 80); + Arc2D arc = new Arc2D.Float(60, 40, 100, 120, + -30, -40, Arc2D.PIE); + GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD); + path.moveTo(0, 0); + path.lineTo(75, -25); + path.lineTo(25, 75); + path.lineTo(0, 25); + path.lineTo(100, 50); + path.lineTo(50, 0); + path.lineTo(25, 50); + path.closePath(); + // Now draw them and their bounds rectangles. + drawShapeAndBounds(g2, ellipse); + drawShapeAndBounds(g2, arc); + drawPoint(g2, arc.getStartPoint()); + drawPoint(g2, arc.getEndPoint()); + g2.translate(180, 65); + drawShapeAndBounds(g2, path); + } +} diff --git a/test/jdk/java/awt/geom/Area/Translate.java b/test/jdk/java/awt/geom/Area/Translate.java new file mode 100644 index 00000000000..7519f1753bc --- /dev/null +++ b/test/jdk/java/awt/geom/Area/Translate.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 1999, 2024, 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 4183373 + * @summary Verifies that the translated Area objects display correctly + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual Translate + */ + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Panel; +import java.awt.Rectangle; +import java.awt.geom.AffineTransform; +import java.awt.geom.Area; +import java.awt.geom.Rectangle2D; + +public class Translate { + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + This test displays two sets of rectangular figures. The two sets + should be displayed one on top of the other and should be lined + up vertically with each other. If the two sets of figures are + not directly above and below each other then the test fails + """; + + PassFailJFrame.builder() + .title("Test Instructions") + .instructions(INSTRUCTIONS) + .columns(35) + .testUI(initialize()) + .build() + .awaitAndCheck(); + } + private static Frame initialize() { + Frame f = new Frame("Translate"); + TranslatePanel panel = new TranslatePanel(); + f.add(panel); + f.setSize(300, 250); + return f; + } +} + +class TranslatePanel extends Panel { + private static Image bufferedImage; + private static Area a1, a2, a3; + + public TranslatePanel() { + a1 = new Area(new Rectangle2D.Double(20.0, 20.0, 60.0, 60.0)); + + a2 = new Area((Area) a1.clone()); + a2.subtract(new Area(new Rectangle2D.Double(30.0, 30.0, 40.0, 40.0))); + + a3 = new Area((Area) a2.clone()); + a3.add(new Area(new Rectangle2D.Double(40.0, 40.0, 20.0, 20.0))); + + AffineTransform at2 = new AffineTransform(); + at2.translate(100.0, 0.0); + a2.transform(at2); + + AffineTransform at3 = new AffineTransform(); + at3.translate(200.0, 0.0); + a3.transform(at3); + } + private void paintRects(Graphics2D g2) { + Rectangle clip = g2.getClipBounds(); + g2.setColor(Color.white); + g2.fillRect(clip.x, clip.y, clip.width, clip.height); + g2.setPaint(Color.red); + g2.fill(a1); + g2.setPaint(Color.yellow); + g2.fill(a2); + g2.setPaint(Color.blue); + g2.fill(a3); + } + + @Override + public void paint(Graphics g) { + if (bufferedImage == null) { + bufferedImage = createImage(300, 100); + Graphics big = bufferedImage.getGraphics(); + // Notice that if you remove the translate() call, it works fine. + big.translate(-1, -1); + big.setClip(1, 1, 300, 100); + paintRects((Graphics2D)big); + big.translate(1, 1); + } + paintRects((Graphics2D)g); + g.drawImage(bufferedImage, 1, 100, this); + g.setColor(Color.black); + g.drawString("From offscreen image (with translate):", 10, 95); + g.drawString(" (should line up with rectangles above)", 10, 110); + } +} diff --git a/test/jdk/java/awt/regtesthelpers/PassFailJFrame.java b/test/jdk/java/awt/regtesthelpers/PassFailJFrame.java index 3a142c716b1..feb5da43a5c 100644 --- a/test/jdk/java/awt/regtesthelpers/PassFailJFrame.java +++ b/test/jdk/java/awt/regtesthelpers/PassFailJFrame.java @@ -79,15 +79,77 @@ import static javax.swing.SwingUtilities.isEventDispatchThread; /** - * Provides a framework for manual tests to display test instructions and - * Pass/Fail buttons. + * A framework for manual tests to display test instructions and + * Pass / Fail buttons. The framework automatically + * creates a frame to display the instructions, provides buttons + * to select the test result, and handles test timeout. + * + *

      + * The instruction UI frame displays a timer at the top which indicates + * how much time is left. The timer can be paused using the Pause + * button to the right of the time; the title of the button changes to + * Resume. To resume the timer, use the Resume button. + * + *

      + * In the center, the instruction UI frame displays instructions for the + * tester. The instructions can be either plain text or HTML. If the + * text of the instructions starts with {@code ""}, the + * instructions are displayed as HTML, as supported by Swing, which + * provides richer formatting options. + *

      + * The instructions are displayed in a text component with word-wrapping + * so that there's no horizontal scroll bar. If the text doesn't fit, a + * vertical scroll bar is shown. Use {@code rows} and {@code columns} + * parameters to change the size of this text component. + * If possible, choose the number of rows and columns so that + * the instructions fit and no scroll bars are shown. + * + *

      + * At the bottom, the instruction UI frame displays the + * Pass and Fail buttons. The tester clicks either Pass + * or Fail button to finish the test. When the tester clicks the + * Fail button, the framework displays a dialog box prompting for + * a reason why the test fails. The tester enters the reason and clicks + * OK to close the dialog and fail the test, + * or simply closes the dialog to fail the test without providing any reason. + * + *

      + * If you enable the screenshot feature, a Screenshot button is + * added to the right of the Fail button. The tester can choose either + * Capture Full Screen (default) or Capture Frames and click the + * Screenshot button to take a screenshot. + * If there are multiple screens, screenshots of each screen are created. + * If the tester selects the Capture Frames mode, screenshots of all + * the windows or frames registered in the {@code PassFailJFrame} framework + * are created. + * + *

      + * If you enable a log area, the instruction UI frame adds a text component + * to display log messages below the buttons. + * Use {@link #log(String) log}, {@link #logSet(String) logSet} + * and {@link #logClear() logClear} static methods of {@code PassFailJFrame} + * to add or clear messages from the log area. + * + *

      + * After you create an instance of {@code PassFailJFrame}, call the + * {@link #awaitAndCheck() awaitAndCheck} method to stop the current thread + * (usually the main thread) and wait until the tester clicks + * either Pass or Fail button, + * or until the test times out. *

      - * Instructions for the user can be either plain text or HTML as supported - * by Swing. If the instructions start with {@code }, the - * instructions are displayed as HTML. + * The call to the {@code awaitAndCheck} method is usually the last + * statement in the {@code main} method of your test. + * If the test fails, an exception is thrown to signal the failure to jtreg. + * The test fails if the tester clicks the Fail button, + * if the timeout occurs, + * or if any window or frame is closed. *

      + * Before returning from {@code awaitAndCheck}, the framework disposes of + * all the windows and frames. + * + *

      Sample Manual Test

      * A simple test would look like this: - *
      {@code
      + * {@snippet id='sampleManualTestCode' lang='java':
        * public class SampleManualTest {
        *     private static final String INSTRUCTIONS =
        *             "Click Pass, or click Fail if the test failed.";
      @@ -95,7 +157,7 @@
        *     public static void main(String[] args) throws Exception {
        *         PassFailJFrame.builder()
        *                       .instructions(INSTRUCTIONS)
      - *                       .testUI(() -> createTestUI())
      + *                       .testUI(SampleManualTest::createTestUI)
        *                       .build()
        *                       .awaitAndCheck();
        *     }
      @@ -106,39 +168,87 @@
        *         return testUI;
        *     }
        * }
      - * }
      + * } *

      - * The above example uses the {@link Builder Builder} to set the parameters of - * the instruction frame. It is the recommended way. + * The above example uses the {@link Builder Builder} class to set + * the parameters of the instruction frame. + * It is the recommended way. + * *

      - * The framework will create instruction UI, it will call - * the provided {@code createTestUI} on the Event Dispatch Thread (EDT), - * and it will automatically position the test UI and make it visible. + * The framework will create an instruction UI frame, it will call + * the provided {@code createTestUI} on the Event Dispatch Thread (EDT), + * and it will automatically position the test UI frame and make it visible. + * + *

      + * Add the following jtreg tags before the test class declaration + * {@snippet : + * /* + * * @test + * * @summary Sample manual test + * * @library /java/awt/regtesthelpers + * * @build PassFailJFrame + * * @run main/manual SampleManualTest + * } + * and the closing comment tag */. *

      + * The {@code @library} tag points to the location of the + * {@code PassFailJFrame} class in the source code; + * the {@code @build} tag makes jtreg compile the {@code PassFailJFrame} class, + * and finally the {@code @run} tag specifies it is a manual + * test and the class to run. + * + *

      Using {@code Builder}

      + * Use methods of the {@link Builder Builder} class to set or change + * parameters of {@code PassFailJFrame} and its instruction UI: + *
        + *
      • {@link Builder#title(String) title} sets + * the title of the instruction UI + * (the default is {@value #TITLE});
      • + *
      • {@link Builder#testTimeOut(long) testTimeOut} sets + * the timeout of the test + * (the default is {@value #TEST_TIMEOUT});
      • + *
      • {@link Builder#rows(int) rows} and + * {@link Builder#columns(int) columns} control the size + * the text component which displays the instructions + * (the default number of rows is the number of lines in the text + * of the instructions, + * the default number of columns is {@value #COLUMNS});
      • + *
      • {@link Builder#logArea() logArea} adds a log area;
      • + *
      • {@link Builder#screenCapture() screenCapture} + * enables screenshots.
      • + *
      + * + *

      Using {@code testUI} and {@code splitUI}

      * The {@code Builder.testUI} methods accept interfaces which create one window * or a list of windows if the test needs multiple windows, * or directly a single window, an array of windows or a list of windows. *

      - * For simple test UI, use {@code Builder.splitUI}, or explicitly - * {@code Builder.splitUIRight} or {@code Builder.splitUIBottom} with - * a {@code PanelCreator}. The framework will call the provided - * {@code createUIPanel} to create the component with test UI and + * For simple test UI, use {@link Builder#splitUI(PanelCreator) splitUI}, + * or explicitly + * {@link Builder#splitUIRight(PanelCreator) splitUIRight} or + * {@link Builder#splitUIBottom(PanelCreator) splitUIBottom} with + * a {@link PanelCreator PanelCreator}. + * The framework will call the provided + * {@code createUIPanel} method to create the component with test UI and * will place it as the right or bottom component in a split pane * along with instruction UI. *

      + * Note: support for multiple windows is incomplete. + * + *

      Obsolete Sample Test

      * Alternatively, use one of the {@code PassFailJFrame} constructors to * create an object, then create secondary test UI, register it * with {@code PassFailJFrame}, position it and make it visible. * The following sample demonstrates it: - *
      {@code
      - * public class SampleOldManualTest {
      + * {@snippet id='obsoleteSampleTestCode' lang='java':
      + * public class ObsoleteManualTest {
        *     private static final String INSTRUCTIONS =
        *             "Click Pass, or click Fail if the test failed.";
        *
        *     public static void main(String[] args) throws Exception {
        *         PassFailJFrame passFail = new PassFailJFrame(INSTRUCTIONS);
        *
      - *         SwingUtilities.invokeAndWait(() -> createTestUI());
      + *         SwingUtilities.invokeAndWait(ObsoleteManualTest::createTestUI);
        *
        *         passFail.awaitAndCheck();
        *     }
      @@ -151,17 +261,29 @@
        *         testUI.setVisible(true);
        *     }
        * }
      - * }
      + * } *

      - * Use methods of the {@code Builder} class or constructors of the - * {@code PassFailJFrame} class to control other parameters: - *

        - *
      • the title of the instruction UI,
      • - *
      • the timeout of the test,
      • - *
      • the size of the instruction UI via rows and columns, and
      • - *
      • to add a log area,
      • - *
      • to enable screenshots.
      • - *
      + * This sample uses {@link #PassFailJFrame(String) a constructor} of + * {@code PassFailJFrame} to create its instance, + * there are several overloads provided which allow changing other parameters. + *

      + * When you use the constructors, you have to explicitly create + * your test UI window on EDT. After you create the window, + * you need to register it with the framework using + * {@link #addTestWindow(Window) addTestWindow} + * to ensure the window is disposed of when the test completes. + * Before showing the window, you have to call + * {@link #positionTestWindow(Window, Position) positionTestWindow} + * to position the test window near the instruction UI frame provided + * by the framework. And finally you have to explicitly show the test UI + * window by calling {@code setVisible(true)}. + *

      + * To avoid the complexity, use the {@link Builder Builder} class + * which provides a streamlined way to configure and create an + * instance of {@code PassFailJFrame}. + *

      + * Consider updating tests which use {@code PassFailJFrame} constructors to + * use the builder pattern. */ public final class PassFailJFrame { @@ -170,6 +292,11 @@ public final class PassFailJFrame { private static final int ROWS = 10; private static final int COLUMNS = 40; + /** + * A gap between windows. + */ + public static final int WINDOW_GAP = 8; + /** * Prefix for the user-provided failure reason. */ @@ -213,90 +340,172 @@ public final class PassFailJFrame { public enum Position {HORIZONTAL, VERTICAL, TOP_LEFT_CORNER} - public PassFailJFrame(String instructions) throws InterruptedException, - InvocationTargetException { + /** + * Constructs a frame which displays test instructions and + * the Pass / Fail buttons with the given instructions, and + * the default timeout of {@value #TEST_TIMEOUT} minutes, + * the default title of {@value #TITLE} and + * the default values of {@value #ROWS} and {@value #COLUMNS} + * for rows and columns. + *

      + * See {@link #PassFailJFrame(String,String,long,int,int,boolean)} for + * more details. + * + * @param instructions the instructions for the tester + * + * @throws InterruptedException if the current thread is interrupted + * while waiting for EDT to finish creating UI components + * @throws InvocationTargetException if an exception is thrown while + * creating UI components on EDT + */ + public PassFailJFrame(String instructions) + throws InterruptedException, InvocationTargetException { this(instructions, TEST_TIMEOUT); } - public PassFailJFrame(String instructions, long testTimeOut) throws - InterruptedException, InvocationTargetException { + /** + * Constructs a frame which displays test instructions and + * the Pass / Fail buttons + * with the given instructions and timeout as well as + * the default title of {@value #TITLE} + * and the default values of {@value #ROWS} and {@value #COLUMNS} + * for rows and columns. + *

      + * See {@link #PassFailJFrame(String,String,long,int,int,boolean)} for + * more details. + * + * @param instructions the instructions for the tester + * @param testTimeOut the test timeout in minutes + * + * @throws InterruptedException if the current thread is interrupted + * while waiting for EDT to finish creating UI components + * @throws InvocationTargetException if an exception is thrown while + * creating UI components on EDT + */ + public PassFailJFrame(String instructions, long testTimeOut) + throws InterruptedException, InvocationTargetException { this(TITLE, instructions, testTimeOut); } + /** + * Constructs a frame which displays test instructions and + * the Pass / Fail buttons + * with the given title, instructions and timeout as well as + * the default values of {@value #ROWS} and {@value #COLUMNS} + * for rows and columns. + * The screenshot feature is not enabled, if you use this constructor. + *

      + * See {@link #PassFailJFrame(String,String,long,int,int,boolean)} for + * more details. + * + * @param title the title of the instruction frame + * @param instructions the instructions for the tester + * @param testTimeOut the test timeout in minutes + * + * @throws InterruptedException if the current thread is interrupted + * while waiting for EDT to finish creating UI components + * @throws InvocationTargetException if an exception is thrown while + * creating UI components on EDT + */ public PassFailJFrame(String title, String instructions, - long testTimeOut) throws InterruptedException, - InvocationTargetException { + long testTimeOut) + throws InterruptedException, InvocationTargetException { this(title, instructions, testTimeOut, ROWS, COLUMNS); } /** - * Constructs a JFrame with a given title & serves as test instructional - * frame where the user follows the specified test instruction in order - * to test the test case & mark the test pass or fail. If the expected - * result is seen then the user click on the 'Pass' button else click - * on the 'Fail' button and the reason for the failure should be - * specified in the JDialog JTextArea. + * Constructs a frame which displays test instructions and + * the Pass / Fail buttons + * with the given title, instructions, timeout, number of rows and columns. + * The screenshot feature is not enabled, if you use this constructor. + *

      + * See {@link #PassFailJFrame(String,String,long,int,int,boolean)} for + * more details. * - * @param title title of the Frame. - * @param instructions the instruction for the tester on how to test - * and what is expected (pass) and what is not - * expected (fail). - * @param testTimeOut test timeout where time is specified in minutes. - * @param rows number of visible rows of the JTextArea where the - * instruction is show. - * @param columns Number of columns of the instructional - * JTextArea - * @throws InterruptedException exception thrown when thread is - * interrupted + * @param title the title of the instruction frame + * @param instructions the instructions for the tester + * @param testTimeOut the test timeout in minutes + * @param rows the number of rows for the text component + * which displays test instructions + * @param columns the number of columns for the text component + * which displays test instructions + * + * @throws InterruptedException if the current thread is interrupted + * while waiting for EDT to finish creating UI components * @throws InvocationTargetException if an exception is thrown while - * creating the test instruction frame on - * EDT + * creating UI components on EDT */ - public PassFailJFrame(String title, String instructions, long testTimeOut, - int rows, int columns) throws InterruptedException, - InvocationTargetException { + public PassFailJFrame(String title, String instructions, + long testTimeOut, + int rows, int columns) + throws InterruptedException, InvocationTargetException { this(title, instructions, testTimeOut, rows, columns, false); } /** - * Constructs a JFrame with a given title & serves as test instructional - * frame where the user follows the specified test instruction in order - * to test the test case & mark the test pass or fail. If the expected - * result is seen then the user click on the 'Pass' button else click - * on the 'Fail' button and the reason for the failure should be - * specified in the JDialog JTextArea. + * Constructs a frame which displays test instructions and + * the Pass / Fail buttons + * as well as supporting UI components with the given title, instructions, + * timeout, number of rows and columns, + * and screen capture functionality. + * All the UI components are created on the EDT, so it is safe to call + * the constructor on the main thread. + *

      + * After you create a test UI window, register the window using + * {@link #addTestWindow(Window) addTestWindow} for disposal, and + * position it close to the instruction frame using + * {@link #positionTestWindow(Window, Position) positionTestWindow}. + * As the last step, make your test UI window visible. + *

      + * Call the {@link #awaitAndCheck() awaitAndCheck} method on the instance + * of {@code PassFailJFrame} when you set up the testing environment. *

      - * The test instruction frame also provides a way for the tester to take - * a screenshot (full screen or individual frame) if this feature - * is enabled by passing {@code true} as {@code enableScreenCapture} - * parameter. + * If the tester clicks the Fail button, a dialog prompting for + * a description of the problem is displayed, and then an exception + * is thrown which fails the test. + * If the tester clicks the Pass button, the test completes + * successfully. + * If the timeout occurs or the instruction frame is closed, + * the test fails. + *

      + * The {@code rows} and {@code columns} parameters control + * the size of a text component which displays the instructions. + * The preferred size of the instructions is calculated by + * creating {@code new JTextArea(rows, columns)}. + *

      + * If you enable screenshots by setting the {@code screenCapture} + * parameter to {@code true}, a Screenshot button is added. + * Clicking the Screenshot button takes screenshots of + * all the monitors or all the windows registered with + * {@code PassFailJFrame}. * - * @param title title of the Frame. - * @param instructions the instruction for the tester on how to test - * and what is expected (pass) and what is not - * expected (fail). - * @param testTimeOut test timeout where time is specified in minutes. - * @param rows number of visible rows of the JTextArea where the - * instruction is show. - * @param columns Number of columns of the instructional - * JTextArea - * @param enableScreenCapture if set to true, 'Capture Screen' button & its - * associated UIs are added to test instruction - * frame - * @throws InterruptedException exception thrown when thread is - * interrupted + * @param title the title of the instruction frame + * @param instructions the instructions for the tester + * @param testTimeOut the test timeout in minutes + * @param rows the number of rows for the text component + * which displays test instructions + * @param columns the number of columns for the text component + * which displays test instructions + * @param screenCapture if set to {@code true}, enables screen capture + * functionality + * + * @throws InterruptedException if the current thread is interrupted + * while waiting for EDT to finish creating UI components * @throws InvocationTargetException if an exception is thrown while - * creating the test instruction frame on - * EDT + * creating UI components on EDT + * + * @see JTextArea#JTextArea(int,int) JTextArea(int rows, int columns) + * @see Builder Builder */ - public PassFailJFrame(String title, String instructions, long testTimeOut, + public PassFailJFrame(String title, String instructions, + long testTimeOut, int rows, int columns, - boolean enableScreenCapture) + boolean screenCapture) throws InterruptedException, InvocationTargetException { invokeOnEDT(() -> createUI(title, instructions, testTimeOut, rows, columns, - enableScreenCapture)); + screenCapture)); } /** @@ -454,7 +663,11 @@ private static JComponent createInstructionUIPanel(String instructions, : configurePlainText(instructions, rows, columns); text.setEditable(false); - main.add(new JScrollPane(text), BorderLayout.CENTER); + JPanel textPanel = new JPanel(new BorderLayout()); + textPanel.setBorder(createEmptyBorder(4, 0, 0, 0)); + textPanel.add(new JScrollPane(text), BorderLayout.CENTER); + + main.add(textPanel, BorderLayout.CENTER); JButton btnPass = new JButton("Pass"); btnPass.addActionListener((e) -> { @@ -587,7 +800,7 @@ public interface PositionWindows { * @param testWindows the list of test windows * @param instructionUI information about the instruction frame */ - void positionTestWindows(List testWindows, + void positionTestWindows(List testWindows, InstructionUI instructionUI); } @@ -735,7 +948,7 @@ public void windowClosing(WindowEvent e) { private static JComponent createCapturePanel() { JComboBox screenShortType = new JComboBox<>(CaptureType.values()); - JButton capture = new JButton("ScreenShot"); + JButton capture = new JButton("Screenshot"); capture.addActionListener((e) -> captureScreen((CaptureType) screenShortType.getSelectedItem())); @@ -747,7 +960,7 @@ private static JComponent createCapturePanel() { private enum CaptureType { FULL_SCREEN("Capture Full Screen"), - WINDOWS("Capture Individual Frame"); + WINDOWS("Capture Frames"); private final String type; CaptureType(String type) { @@ -925,13 +1138,13 @@ private static void positionInstructionFrame(final Position position) { switch (position) { case HORIZONTAL: - int newX = ((screenSize.width / 2) - frame.getWidth()); + int newX = (((screenSize.width + WINDOW_GAP) / 2) - frame.getWidth()); frame.setLocation((newX + screenInsets.left), (frame.getY() + screenInsets.top)); break; case VERTICAL: - int newY = ((screenSize.height / 2) - frame.getHeight()); + int newY = (((screenSize.height + WINDOW_GAP) / 2) - frame.getHeight()); frame.setLocation((frame.getX() + screenInsets.left), (newY + screenInsets.top)); break; @@ -979,13 +1192,13 @@ public static void positionTestWindow(Window testWindow, Position position) { switch (position) { case HORIZONTAL: case TOP_LEFT_CORNER: - testWindow.setLocation((frame.getX() + frame.getWidth() + 5), + testWindow.setLocation((frame.getX() + frame.getWidth() + WINDOW_GAP), frame.getY()); break; case VERTICAL: testWindow.setLocation(frame.getX(), - (frame.getY() + frame.getHeight() + 5)); + (frame.getY() + frame.getHeight() + WINDOW_GAP)); break; } } @@ -1288,6 +1501,7 @@ public Builder testUI(WindowCreator windowCreator) { return this; } + /** * Adds an implementation of {@link PositionWindows PositionWindows} * which the framework will use to position multiple test UI windows. @@ -1311,6 +1525,77 @@ public Builder positionTestUI(PositionWindows positionWindows) { return this; } + /** + * Positions the test UI windows in a row to the right of + * the instruction frame. The top of the windows is aligned to + * that of the instruction frame. + * + * @return this builder + */ + public Builder positionTestUIRightRow() { + return position(Position.HORIZONTAL) + .positionTestUI(WindowLayouts::rightOneRow); + } + + /** + * Positions the test UI windows in a column to the right of + * the instruction frame. The top of the first window is aligned to + * that of the instruction frame. + * + * @return this builder + */ + public Builder positionTestUIRightColumn() { + return position(Position.HORIZONTAL) + .positionTestUI(WindowLayouts::rightOneColumn); + } + + /** + * Positions the test UI windows in a column to the right of + * the instruction frame centering the stack of the windows. + * + * @return this builder + */ + public Builder positionTestUIRightColumnCentered() { + return position(Position.HORIZONTAL) + .positionTestUI(WindowLayouts::rightOneColumnCentered); + } + + /** + * Positions the test UI windows in a row to the bottom of + * the instruction frame. The left of the first window is aligned to + * that of the instruction frame. + * + * @return this builder + */ + public Builder positionTestUIBottomRow() { + return position(Position.VERTICAL) + .positionTestUI(WindowLayouts::bottomOneRow); + } + + /** + * Positions the test UI windows in a row to the bottom of + * the instruction frame centering the row of the windows. + * + * @return this builder + */ + public Builder positionTestUIBottomRowCentered() { + return position(Position.VERTICAL) + .positionTestUI(WindowLayouts::bottomOneRowCentered); + } + + /** + * Positions the test UI windows in a column to the bottom of + * the instruction frame. The left of the first window is aligned to + * that of the instruction frame. + * + * @return this builder + */ + public Builder positionTestUIBottomColumn() { + return position(Position.VERTICAL) + .positionTestUI(WindowLayouts::bottomOneColumn); + } + + /** * Adds a {@code WindowListCreator} which the framework will use * to create a list of test UI windows. @@ -1413,6 +1698,7 @@ public Builder testUI(PanelCreator panelCreator) { return this; } + /** * Adds a {@code PanelCreator} which the framework will use * to create a component with test UI and display it in a split pane. diff --git a/test/jdk/java/awt/regtesthelpers/WindowLayouts.java b/test/jdk/java/awt/regtesthelpers/WindowLayouts.java new file mode 100644 index 00000000000..4368e3a5943 --- /dev/null +++ b/test/jdk/java/awt/regtesthelpers/WindowLayouts.java @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2023, 2024, 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. + */ + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.GraphicsConfiguration; +import java.awt.Insets; +import java.awt.Point; +import java.awt.Window; +import java.util.List; + +import static java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment; +import static java.awt.Toolkit.getDefaultToolkit; + +/** + * A utility class which provides standard window layouts for multi-window + * manual tests using the {@link PassFailJFrame} framework. + * The layout methods {@code right-} and {@code bottom-} implement the + * {@link PassFailJFrame.PositionWindows PositionWindows} interface and + * can be used directly or via builder methods. + *

      + * There are several helper methods, such as + * {@link #getScreenCenter() getScreenCenter}, which could help you + * implement customized windows layouts. + */ +public final class WindowLayouts { + + /** Private constructor to prevent instantiating the utility class. */ + private WindowLayouts() { + } + + /** A gap between windows. (Local copy makes expressions shorter.) */ + private static final int WINDOW_GAP = PassFailJFrame.WINDOW_GAP; + + /** + * Lays out the window list in one row to the right of + * the instruction frame. The top of the windows is aligned to + * that of the instruction frame. + * + * @param windows the list of windows to lay out + * @param instructionUI information about the instruction frame + */ + public static void rightOneRow(final List windows, + final PassFailJFrame.InstructionUI instructionUI) { + layoutRow(instructionUI.getLocation().x + + instructionUI.getSize().width + + WINDOW_GAP, + instructionUI.getLocation().y, + windows); + } + + /** + * Lays out the window list in one column to the right of + * the instruction frame. The top of the first window is aligned to + * that of the instruction frame. + * + * @param windows the list of windows to lay out + * @param instructionUI information about the instruction frame + */ + public static void rightOneColumn(final List windows, + final PassFailJFrame.InstructionUI instructionUI) { + layoutColumn(instructionUI.getLocation().x + + instructionUI.getSize().width + + WINDOW_GAP, + instructionUI.getLocation().y, + windows); + } + + /** + * Lays out the window list in one column to the right of + * the instruction frame centering the stack of the windows. + * + * @param windows the list of windows to lay out + * @param instructionUI information about the instruction frame + */ + public static void rightOneColumnCentered(final List windows, + final PassFailJFrame.InstructionUI instructionUI) { + layoutColumn(instructionUI.getLocation().x + + instructionUI.getSize().width + + WINDOW_GAP, + getScreenCenter().y + - getWindowListHeight(windows) / 2, + windows); + } + + + /** + * Lays out the window list in one row to the bottom of + * the instruction frame. The left of the first window is aligned to + * that of the instruction frame. + * + * @param windows the list of windows to lay out + * @param instructionUI information about the instruction frame + */ + public static void bottomOneRow(final List windows, + final PassFailJFrame.InstructionUI instructionUI) { + layoutRow(instructionUI.getLocation().x, + instructionUI.getLocation().y + + instructionUI.getSize().height + + WINDOW_GAP, + windows); + } + + /** + * Lays out the window list in one row to the bottom of + * the instruction frame centering the row of the windows. + * + * @param windows the list of windows to lay out + * @param instructionUI information about the instruction frame + */ + public static void bottomOneRowCentered(final List windows, + final PassFailJFrame.InstructionUI instructionUI) { + layoutRow(getScreenCenter().x + - getWindowListWidth(windows) / 2, + instructionUI.getLocation().y + + instructionUI.getSize().height + + WINDOW_GAP, + windows); + } + + /** + * Lays out the window list in one column to the bottom of + * the instruction frame. The left of the first window is aligned to + * that of the instruction frame. + * + * @param windows the list of windows to lay out + * @param instructionUI information about the instruction frame + */ + public static void bottomOneColumn(final List windows, + final PassFailJFrame.InstructionUI instructionUI) { + layoutColumn(instructionUI.getLocation().x, + instructionUI.getLocation().y + + instructionUI.getSize().height + + WINDOW_GAP, + windows); + } + + + /** + * Lays out the window list in one row starting at + * ({@code x0}, {@code y}). + * + * @param x0 the starting x coordinate of the windows + * @param y the y coordinate of the windows + * @param windows the list of windows to lay out + */ + public static void layoutRow(final int x0, + final int y, + final List windows) { + int x = x0; + for (Window w : windows) { + w.setLocation(x, y); + x += w.getWidth() + WINDOW_GAP; + } + } + + /** + * Lays out the window list in one column starting at + * ({@code x}, {@code y0}). + * + * @param x the x coordinate of the windows + * @param y0 the starting y coordinate of the windows + * @param windows the list of windows to lay out + */ + public static void layoutColumn(final int x, + final int y0, + final List windows) { + int y = y0; + for (Window w : windows) { + w.setLocation(x, y); + y += w.getHeight() + WINDOW_GAP; + } + } + + + /** + * {@return the center point of the main screen} + */ + public static Point getScreenCenter() { + GraphicsConfiguration gc = getLocalGraphicsEnvironment() + .getDefaultScreenDevice() + .getDefaultConfiguration(); + Dimension size = gc.getBounds() + .getSize(); + Insets insets = getDefaultToolkit() + .getScreenInsets(gc); + + return new Point((size.width - insets.left - insets.right) / 2, + (size.height - insets.top - insets.bottom) / 2); + } + + /** + * {@return width of the windows in the list, taking into account + * the gap between windows} + * + * @param windows the list of windows to get the width of + */ + public static int getWindowListWidth(final List windows) { + return windows.stream() + .mapToInt(Component::getWidth) + .sum() + + WINDOW_GAP * (windows.size() - 1); + } + + /** + * {@return height of the windows in the list, taking into account + * the gap between windows} + * + * @param windows the list of windows to get the height of + */ + public static int getWindowListHeight(final List windows) { + return windows.stream() + .mapToInt(Component::getHeight) + .sum() + + WINDOW_GAP * (windows.size() - 1); + } +} diff --git a/test/jdk/java/lang/StringBuffer/HugeCapacity.java b/test/jdk/java/lang/StringBuffer/HugeCapacity.java index e3c98496c50..d1ff51dddb2 100644 --- a/test/jdk/java/lang/StringBuffer/HugeCapacity.java +++ b/test/jdk/java/lang/StringBuffer/HugeCapacity.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -21,11 +21,14 @@ * questions. */ +import jdk.internal.util.ArraysSupport; + /** * @test * @bug 8218227 * @summary StringBuilder/StringBuffer constructor throws confusing * NegativeArraySizeException + * @modules java.base/jdk.internal.util * @requires (sun.arch.data.model == "64" & os.maxMemory >= 8G) * @run main/othervm -Xms6G -Xmx6G HugeCapacity */ @@ -43,7 +46,7 @@ public static void main(String[] args) { private static void testHugeInitialString() { try { - String str = "Z".repeat(Integer.MAX_VALUE - 8); + String str = "Z".repeat(ArraysSupport.SOFT_MAX_ARRAY_LENGTH); StringBuffer sb = new StringBuffer(str); } catch (OutOfMemoryError ignore) { } catch (Throwable unexpected) { diff --git a/test/jdk/java/lang/StringBuilder/HugeCapacity.java b/test/jdk/java/lang/StringBuilder/HugeCapacity.java index a584ce1f07a..a81f1614fe5 100644 --- a/test/jdk/java/lang/StringBuilder/HugeCapacity.java +++ b/test/jdk/java/lang/StringBuilder/HugeCapacity.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024, 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 @@ -21,11 +21,14 @@ * questions. */ +import jdk.internal.util.ArraysSupport; + /** * @test * @bug 8149330 8218227 * @summary Capacity should not get close to Integer.MAX_VALUE unless * necessary + * @modules java.base/jdk.internal.util * @requires (sun.arch.data.model == "64" & os.maxMemory >= 8G) * @run main/othervm -Xms6G -Xmx6G -XX:+CompactStrings HugeCapacity true * @run main/othervm -Xms6G -Xmx6G -XX:-CompactStrings HugeCapacity false @@ -75,7 +78,7 @@ private static void testUtf16() { private static void testHugeInitialString() { try { - String str = "Z".repeat(Integer.MAX_VALUE - 8); + String str = "Z".repeat(ArraysSupport.SOFT_MAX_ARRAY_LENGTH); StringBuilder sb = new StringBuilder(str); } catch (OutOfMemoryError ignore) { } catch (Throwable unexpected) { diff --git a/test/jdk/java/lang/invoke/BigArityTest.java b/test/jdk/java/lang/invoke/BigArityTest.java index 338903f3163..2dba056a183 100644 --- a/test/jdk/java/lang/invoke/BigArityTest.java +++ b/test/jdk/java/lang/invoke/BigArityTest.java @@ -24,7 +24,7 @@ /* @test * @summary High arity invocations * @compile BigArityTest.java - * @run junit/othervm/timeout=2500 -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies -esa -DBigArityTest.ITERATION_COUNT=1 test.java.lang.invoke.BigArityTest + * @run junit/othervm/timeout=2500 -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies -XX:CompileCommand=memlimit,*.*,0 -esa -DBigArityTest.ITERATION_COUNT=1 test.java.lang.invoke.BigArityTest */ package test.java.lang.invoke; diff --git a/test/jdk/java/math/BigInteger/MutableBigIntegerShiftTests.java b/test/jdk/java/math/BigInteger/MutableBigIntegerShiftTests.java new file mode 100644 index 00000000000..e64cae480d3 --- /dev/null +++ b/test/jdk/java/math/BigInteger/MutableBigIntegerShiftTests.java @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2024, 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. + */ + +import jdk.test.lib.RandomFactory; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.Arguments; + +import java.math.BigInteger; +import java.math.MutableBigIntegerBox; +import java.util.Arrays; +import java.util.Random; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static java.math.MutableBigIntegerBox.*; + +/** + * @test + * @bug 8336274 + * @summary Tests for correctness of MutableBigInteger.leftShift(int) + * @library /test/lib + * @build jdk.test.lib.RandomFactory + * @build java.base/java.math.MutableBigIntegerBox + * @key randomness + * @run junit MutableBigIntegerShiftTests + */ +public class MutableBigIntegerShiftTests { + + private static final int ORDER_SMALL = 60; + private static final int ORDER_MEDIUM = 100; + + private static final Random random = RandomFactory.getRandom(); + + private static int[] orders() { + return new int[] { ORDER_SMALL, ORDER_MEDIUM }; + } + + @ParameterizedTest + @MethodSource("orders") + public void shift(int order) { + for (int i = 0; i < 100; i++) { + test(fetchNumber(order), random.nextInt(200)); + } + } + + @ParameterizedTest + @MethodSource("pathTargetedCases") + public void test(MutableBigIntegerBox x, int n) { + leftShiftAssertions(x, n); + } + + private static Arguments[] pathTargetedCases() { + return new Arguments[] { + // intLen == 0 + Arguments.of(MutableBigIntegerBox.ZERO, + random.nextInt(33)), + // intLen != 0 && n <= leadingZeros + Arguments.of(new MutableBigIntegerBox(new int[] { (int) random.nextLong(1L, 1L << 16) }), + random.nextInt(1, 17)), + // intLen != 0 && n > leadingZeros && nBits <= leadingZeros && value.length < newLen && nBits == 0 + Arguments.of(new MutableBigIntegerBox(new int[] { (int) random.nextLong(1L, 1L << 32) }), + 32), + // intLen != 0 && n > leadingZeros && nBits <= leadingZeros && value.length < newLen && nBits != 0 + Arguments.of(new MutableBigIntegerBox(new int[] { (int) random.nextLong(1L, 1L << 16) }), + 32 + random.nextInt(1, 17)), + // intLen != 0 && n > leadingZeros && nBits <= leadingZeros && value.length >= newLen && nBits == 0 + // && newOffset != offset + Arguments.of(new MutableBigIntegerBox(new int[] { random.nextInt(), (int) random.nextLong(1L, 1L << 32) }, 1, 1), + 32), + // intLen != 0 && n > leadingZeros && nBits <= leadingZeros && value.length >= newLen && nBits == 0 + // && newOffset == offset + Arguments.of(new MutableBigIntegerBox(new int[] { (int) random.nextLong(1L, 1L << 32), random.nextInt() }, 0, 1), + 32), + // intLen != 0 && n > leadingZeros && nBits <= leadingZeros && value.length >= newLen && nBits != 0 + // && newOffset != offset + Arguments.of(new MutableBigIntegerBox(new int[] { random.nextInt(), (int) random.nextLong(1L, 1L << 16) }, 1, 1), + 32 + random.nextInt(1, 17)), + // intLen != 0 && n > leadingZeros && nBits <= leadingZeros && value.length >= newLen && nBits != 0 + // && newOffset == offset + Arguments.of(new MutableBigIntegerBox(new int[] { (int) random.nextLong(1L, 1L << 16), random.nextInt() }, 0, 1), + 32 + random.nextInt(1, 17)), + // intLen != 0 && n > leadingZeros && nBits > leadingZeros && value.length < newLen + Arguments.of(new MutableBigIntegerBox(new int[] { (int) random.nextLong(1L << 15, 1L << 32) }), + random.nextInt(17, 32)), + // intLen != 0 && n > leadingZeros && nBits > leadingZeros && value.length >= newLen && newOffset != offset + Arguments.of(new MutableBigIntegerBox(new int[] { random.nextInt(), (int) random.nextLong(1L << 15, 1L << 32) }, 1, 1), + random.nextInt(17, 32)), + // intLen != 0 && n > leadingZeros && nBits > leadingZeros && value.length >= newLen && newOffset == offset + Arguments.of(new MutableBigIntegerBox(new int[] { (int) random.nextLong(1L << 15, 1L << 32), random.nextInt() }, 0, 1), + random.nextInt(17, 32)), + }; + } + + private static void leftShiftAssertions(MutableBigIntegerBox x, int n) { + MutableBigIntegerBox xShifted = x.shiftLeft(n); + assertEquals(x.multiply(new MutableBigIntegerBox(BigInteger.TWO.pow(n))), xShifted); + assertEquals(x, xShifted.shiftRight(n)); + } + + /* + * Get a random or boundary-case number. This is designed to provide + * a lot of numbers that will find failure points, such as max sized + * numbers, empty MutableBigIntegers, etc. + * + * If order is less than 2, order is changed to 2. + */ + private static MutableBigIntegerBox fetchNumber(int order) { + int numType = random.nextInt(8); + MutableBigIntegerBox result = null; + if (order < 2) order = 2; + + int[] val; + switch (numType) { + case 0: // Empty + result = MutableBigIntegerBox.ZERO; + break; + + case 1: // One + result = MutableBigIntegerBox.ONE; + break; + + case 2: // All bits set in number + int numInts = (order + 31) >> 5; + int[] fullBits = new int[numInts]; + Arrays.fill(fullBits, -1); + + fullBits[0] &= -1 >>> -order; + result = new MutableBigIntegerBox(fullBits); + break; + + case 3: // One bit in number + result = MutableBigIntegerBox.ONE.shiftLeft(random.nextInt(order)); + break; + + case 4: // Random bit density + val = new int[(order + 31) >> 5]; + int iterations = random.nextInt(order); + for (int i = 0; i < iterations; i++) { + int bitIdx = random.nextInt(order); + val[bitIdx >> 5] |= 1 << bitIdx; + } + result = new MutableBigIntegerBox(val); + break; + case 5: // Runs of consecutive ones and zeros + result = ZERO; + int remaining = order; + int bit = random.nextInt(2); + while (remaining > 0) { + int runLength = Math.min(remaining, random.nextInt(order)); + result = result.shiftLeft(runLength); + if (bit > 0) + result = result.add(ONE.shiftLeft(runLength).subtract(ONE)); + remaining -= runLength; + bit = 1 - bit; + } + break; + case 6: // random bits with trailing space + int len = random.nextInt((order + 31) >> 5) + 1; + int offset = random.nextInt(len); + val = new int[len << 1]; + for (int i = 0; i < val.length; i++) + val[i] = random.nextInt(); + result = new MutableBigIntegerBox(val, offset, len); + break; + default: // random bits + result = new MutableBigIntegerBox(new BigInteger(order, random)); + } + + return result; + } +} diff --git a/test/jdk/java/math/BigInteger/java.base/java/math/MutableBigIntegerBox.java b/test/jdk/java/math/BigInteger/java.base/java/math/MutableBigIntegerBox.java new file mode 100644 index 00000000000..1f82e449198 --- /dev/null +++ b/test/jdk/java/math/BigInteger/java.base/java/math/MutableBigIntegerBox.java @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.math; + +import java.util.Arrays; + +/** + * A class for tests. + */ +public class MutableBigIntegerBox { + + /** + * Constant zero + */ + public static final MutableBigIntegerBox ZERO = new MutableBigIntegerBox(new MutableBigInteger()); + + /** + * Constant one + */ + public static final MutableBigIntegerBox ONE = new MutableBigIntegerBox(MutableBigInteger.ONE); + + /** + * Constant two + */ + public static final MutableBigIntegerBox TWO = new MutableBigIntegerBox(new MutableBigInteger(2)); + + private MutableBigInteger val; + + MutableBigIntegerBox(MutableBigInteger val) { + this.val = val; + } + + /** + * Construct MutableBigIntegerBox from magnitude, starting from + * offset and with a length of intLen ints. + * The value is normalized. + * @param mag the magnitude + * @param offset the offset where the value starts + * @param intLen the length of the value, in int words. + */ + public MutableBigIntegerBox(int[] mag, int offset, int intLen) { + this(new MutableBigInteger(mag)); + val.offset = offset; + val.intLen = intLen; + val.normalize(); + } + + /** + * Construct MutableBigIntegerBox from magnitude. + * The value is normalized. + * @param mag the magnitude + */ + public MutableBigIntegerBox(int[] mag) { + this(mag, 0, mag.length); + } + + /** + * Construct MutableBigIntegerBox from BigInteger val + * @param val the value + */ + public MutableBigIntegerBox(BigInteger val) { + this(val.mag); + } + + /** + * Returns the bit length of this MutableBigInteger value + * @return the bit length of this MutableBigInteger value + */ + public long bitLength() { + return val.bitLength(); + } + + /** + * Return {@code this << n} + * @return {@code this << n} + * @param n the shift + */ + public MutableBigIntegerBox shiftLeft(int n) { + MutableBigIntegerBox res = new MutableBigIntegerBox(val.value.clone(), val.offset, val.intLen); + res.val.safeLeftShift(n); + return res; + } + + /** + * Return {@code this >> n} + * @return {@code this >> n} + * @param n the shift + */ + public MutableBigIntegerBox shiftRight(int n) { + MutableBigInteger res = new MutableBigInteger(val); + res.safeRightShift(n); + return new MutableBigIntegerBox(res); + } + + /** + * Return this + addend + * @return this + addend + * @param addend the addend + */ + public MutableBigIntegerBox add(MutableBigIntegerBox addend) { + MutableBigInteger res = new MutableBigInteger(val); + res.add(addend.val); + return new MutableBigIntegerBox(res); + } + + /** + * Return this - subtraend + * @return this - subtraend + * @param subtraend the subtraend + */ + public MutableBigIntegerBox subtract(MutableBigIntegerBox subtraend) { + MutableBigInteger res = new MutableBigInteger(val); + res.subtract(subtraend.val); + return new MutableBigIntegerBox(res); + } + + /** + * Return this * multiplier + * @return this * multiplier + * @param multiplier the multiplier + */ + public MutableBigIntegerBox multiply(MutableBigIntegerBox multiplier) { + MutableBigInteger res = new MutableBigInteger(); + if (!(val.isZero() || multiplier.val.isZero())) + val.multiply(multiplier.val, res); + + return new MutableBigIntegerBox(res); + } + + /** + * Compare the magnitude of two MutableBigIntegers. Returns -1, 0 or 1 + * as this is numerically less than, equal to, or greater than {@code b}. + * @return -1, 0 or 1 as this is numerically less than, equal to, or + * greater than {@code b}. + * @param b the value to compare + */ + public int compare(MutableBigIntegerBox b) { + return val.compare(b.val); + } + + /** + * Compares this MutableBigIntegerBox with the specified Object for equality. + * + * @param x Object to which this MutableBigIntegerBox is to be compared. + * @return {@code true} if and only if the specified Object is a + * MutableBigIntegerBox whose value is numerically equal to this MutableBigIntegerBox. + */ + @Override + public boolean equals(Object x) { + return (x instanceof MutableBigIntegerBox xInt) + && Arrays.equals(val.value, val.offset, val.offset + val.intLen, + xInt.val.value, xInt.val.offset, xInt.val.offset + xInt.val.intLen); + } + + @Override + public String toString() { + return val.toString(); + } +} diff --git a/test/jdk/java/nio/charset/CharsetDecoder/XcodeOverflow.java b/test/jdk/java/nio/charset/CharsetDecoder/XcodeOverflow.java index 7570da3945c..197b61c0ac5 100644 --- a/test/jdk/java/nio/charset/CharsetDecoder/XcodeOverflow.java +++ b/test/jdk/java/nio/charset/CharsetDecoder/XcodeOverflow.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, 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 @@ -27,6 +27,7 @@ * @summary Make sure IAE is not thrown on `int` overflow, turning negative * size. The test should either not throw any Throwable, or an OOME * with real Java heap space error (not "exceeds VM limit"). + * @modules java.base/jdk.internal.util * @requires sun.arch.data.model == "64" * @run junit/othervm XcodeOverflow */ @@ -37,6 +38,7 @@ import java.nio.charset.StandardCharsets; import java.util.stream.Stream; +import jdk.internal.util.ArraysSupport; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.Arguments; @@ -44,8 +46,8 @@ public class XcodeOverflow { private static Stream sizes() { return Stream.of( - // SOFT_MAX_ARRAY_LENGTH: copied from ArraysSupport. No overflow; no OOME. - Arguments.of(Integer.MAX_VALUE - 8), + // No overflow; no OOME. + Arguments.of(ArraysSupport.SOFT_MAX_ARRAY_LENGTH), // overflow case: OOME w/ "Java heap space" is thrown on decoding Arguments.of(Integer.MAX_VALUE - 1000000) diff --git a/test/jdk/java/nio/charset/spi/CharsetProviderAsModuleTest.java b/test/jdk/java/nio/charset/spi/CharsetProviderAsModuleTest.java new file mode 100644 index 00000000000..ba6aae234c6 --- /dev/null +++ b/test/jdk/java/nio/charset/spi/CharsetProviderAsModuleTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024, 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 8340404 + * @summary Check that a CharsetProvider SPI can be deployed as a module + * @build provider/* + * @run main/othervm CharsetProviderAsModuleTest + */ + +import java.nio.charset.Charset; + +public class CharsetProviderAsModuleTest { + + // Basic test ensures that our BAZ charset is loaded via the BazProvider + public static void main(String[] args) { + var cs = Charset.availableCharsets(); + Charset bazCs; + // check provider is providing BAZ via charsets() + if (!cs.containsKey("BAZ")) { + throw new RuntimeException("SPI BazProvider did not provide BAZ Charset"); + } else { + bazCs = cs.get("BAZ"); + // check provider is in a named module + if (!bazCs.getClass().getModule().isNamed()) { + throw new RuntimeException("BazProvider is not a named module"); + } + var aliases = bazCs.aliases(); + // check BAZ cs aliases were loaded correctly + if (!aliases.contains("BAZ-1") || !aliases.contains("BAZ-2")) { + throw new RuntimeException("BAZ Charset did not provide correct aliases"); + } + // check provider implements charsetForName() + if (!bazCs.equals(Charset.forName("BAZ"))) { + throw new RuntimeException("SPI BazProvider provides bad charsetForName()"); + } + } + } +} diff --git a/test/jdk/java/nio/charset/spi/provider/module-info.java b/test/jdk/java/nio/charset/spi/provider/module-info.java new file mode 100644 index 00000000000..5cfe6db92db --- /dev/null +++ b/test/jdk/java/nio/charset/spi/provider/module-info.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024, 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. + */ +module provider { + provides java.nio.charset.spi.CharsetProvider with spi.BazProvider; +} diff --git a/test/jdk/java/nio/charset/spi/provider/spi/BazProvider.java b/test/jdk/java/nio/charset/spi/provider/spi/BazProvider.java new file mode 100644 index 00000000000..7def239e64c --- /dev/null +++ b/test/jdk/java/nio/charset/spi/provider/spi/BazProvider.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package spi; + +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; +import java.nio.charset.spi.CharsetProvider; +import java.util.Collections; +import java.util.Iterator; + +// Provides some simple BAZ related attributes to our provider +public class BazProvider extends CharsetProvider { + + @Override + public Iterator charsets() { + return Collections.singleton(new BazCharset()).iterator(); + } + + @Override + public Charset charsetForName(String charsetName) { + if (charsetName.equals("BAZ")) { + return new BazCharset(); + } else { + return null; + } + } + + public static class BazCharset extends Charset { + + public BazCharset() { + super("BAZ", new String[] { "BAZ-1", "BAZ-2" }); + } + + // Overrides to satisfy Charset + @Override + public boolean contains(Charset cs) { + return false; + } + + @Override + public CharsetDecoder newDecoder() { + return null; + } + + @Override + public CharsetEncoder newEncoder() { + return null; + } + } +} diff --git a/test/jdk/java/util/Base64/TestEncodingDecodingLength.java b/test/jdk/java/util/Base64/TestEncodingDecodingLength.java index ce6d0db4adc..452f11ebea9 100644 --- a/test/jdk/java/util/Base64/TestEncodingDecodingLength.java +++ b/test/jdk/java/util/Base64/TestEncodingDecodingLength.java @@ -21,6 +21,7 @@ * questions. */ +import jdk.internal.util.ArraysSupport; import org.junit.jupiter.api.Test; import java.lang.reflect.InvocationTargetException; @@ -37,6 +38,7 @@ * Base64.Decoder.decode behavior with large, (Integer.MAX_VALUE) sized * input array/buffer. Tests the private methods "encodedOutLength" and * "decodedOutLength". + * @modules java.base/jdk.internal.util * @run junit/othervm --add-opens java.base/java.util=ALL-UNNAMED TestEncodingDecodingLength */ @@ -45,7 +47,7 @@ public class TestEncodingDecodingLength { // A value large enough to test the desired memory conditions in encode and decode - private static final int LARGE_MEM_SIZE = Integer.MAX_VALUE - 8; + private static final int LARGE_MEM_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; private static final Base64.Decoder DECODER = Base64.getDecoder(); private static final Base64.Encoder ENCODER = Base64.getEncoder(); diff --git a/test/jdk/java/util/concurrent/tck/ArrayDeque8Test.java b/test/jdk/java/util/concurrent/tck/ArrayDeque8Test.java index eb606b0c781..fb21ebfed36 100644 --- a/test/jdk/java/util/concurrent/tck/ArrayDeque8Test.java +++ b/test/jdk/java/util/concurrent/tck/ArrayDeque8Test.java @@ -36,6 +36,7 @@ import java.util.Collections; import java.util.Spliterator; +import jdk.internal.util.ArraysSupport; import junit.framework.Test; public class ArrayDeque8Test extends JSR166TestCase { @@ -86,7 +87,7 @@ public void testHugeCapacity() { return; final Item e = fortytwo; - final int maxArraySize = Integer.MAX_VALUE - 8; + final int maxArraySize = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; assertThrows(OutOfMemoryError.class, () -> new ArrayDeque(Integer.MAX_VALUE)); diff --git a/test/jdk/java/util/concurrent/tck/JSR166TestCase.java b/test/jdk/java/util/concurrent/tck/JSR166TestCase.java index 451864bcf5d..19897fa0785 100644 --- a/test/jdk/java/util/concurrent/tck/JSR166TestCase.java +++ b/test/jdk/java/util/concurrent/tck/JSR166TestCase.java @@ -38,7 +38,7 @@ * @test id=default * @summary Conformance testing variant of JSR-166 tck tests. * @build * - * @modules java.management + * @modules java.management java.base/jdk.internal.util * @run junit/othervm/timeout=1000 JSR166TestCase */ @@ -47,7 +47,7 @@ * @summary Conformance testing variant of JSR-166 tck tests * with java security manager set to allow. * @build * - * @modules java.management + * @modules java.management java.base/jdk.internal.util * @run junit/othervm/timeout=1000 -Djava.security.manager=allow JSR166TestCase */ @@ -56,7 +56,7 @@ * @summary Test implementation details variant of JSR-166 * tck tests with ForkJoinPool common parallelism. * @build * - * @modules java.management + * @modules java.management java.base/jdk.internal.util * @run junit/othervm/timeout=1000 * --add-opens java.base/java.util.concurrent=ALL-UNNAMED * --add-opens java.base/java.lang=ALL-UNNAMED @@ -78,7 +78,7 @@ * JSR-166 tck tests apart from ForkJoinPool common * parallelism. * @build * - * @modules java.management + * @modules java.management java.base/jdk.internal.util * @run junit/othervm/timeout=1000 * --add-opens java.base/java.util.concurrent=ALL-UNNAMED * --add-opens java.base/java.lang=ALL-UNNAMED diff --git a/test/jdk/java/util/zip/ZipFile/CenSizeTooLarge.java b/test/jdk/java/util/zip/ZipFile/CenSizeTooLarge.java index 3a5430d0573..e3f0b20fce8 100644 --- a/test/jdk/java/util/zip/ZipFile/CenSizeTooLarge.java +++ b/test/jdk/java/util/zip/ZipFile/CenSizeTooLarge.java @@ -23,10 +23,12 @@ /* @test * @bug 8272746 + * @modules java.base/jdk.internal.util * @summary Verify that ZipFile rejects a ZIP with a CEN size which does not fit in a Java byte array * @run junit CenSizeTooLarge */ +import jdk.internal.util.ArraysSupport; import org.junit.Before; import org.junit.Test; @@ -49,7 +51,7 @@ public class CenSizeTooLarge { public static final int NAME_LENGTH = 10; // Maximum allowed CEN size allowed by the ZipFile implementation - static final int MAX_CEN_SIZE = Integer.MAX_VALUE - ZipFile.ENDHDR - 1; + static final int MAX_CEN_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; /** * From the APPNOTE.txt specification: diff --git a/test/jdk/java/util/zip/ZipFile/EndOfCenValidation.java b/test/jdk/java/util/zip/ZipFile/EndOfCenValidation.java index 51ed2c28c12..ec6542768c5 100644 --- a/test/jdk/java/util/zip/ZipFile/EndOfCenValidation.java +++ b/test/jdk/java/util/zip/ZipFile/EndOfCenValidation.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, 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 @@ -23,10 +23,12 @@ /* @test * @bug 8272746 + * @modules java.base/jdk.internal.util * @summary Verify that ZipFile rejects files with CEN sizes exceeding the implementation limit * @run testng/othervm EndOfCenValidation */ +import jdk.internal.util.ArraysSupport; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -68,7 +70,7 @@ public class EndOfCenValidation { private static final int ENDSIZ = ZipFile.ENDSIZ; // Offset of CEN size field within ENDHDR private static final int ENDOFF = ZipFile.ENDOFF; // Offset of CEN offset field within ENDHDR // Maximum allowed CEN size allowed by ZipFile - private static int MAX_CEN_SIZE = Integer.MAX_VALUE - ENDHDR - 1; + private static int MAX_CEN_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; // Expected message when CEN size does not match file size private static final String INVALID_CEN_BAD_SIZE = "invalid END header (bad central directory size)"; diff --git a/test/jdk/javax/net/ssl/DTLS/TEST.properties b/test/jdk/javax/net/ssl/DTLS/TEST.properties index ceb6c8c9c42..a50cba09c0f 100644 --- a/test/jdk/javax/net/ssl/DTLS/TEST.properties +++ b/test/jdk/javax/net/ssl/DTLS/TEST.properties @@ -6,3 +6,4 @@ modules = \ java.security.jgss/sun.security.krb5.internal:+open \ java.security.jgss/sun.security.krb5.internal.ktab \ java.base/sun.security.util +maxOutputSize = 2500000 diff --git a/test/jdk/jdk/classfile/InstructionValidationTest.java b/test/jdk/jdk/classfile/InstructionValidationTest.java new file mode 100644 index 00000000000..17210e1173b --- /dev/null +++ b/test/jdk/jdk/classfile/InstructionValidationTest.java @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2022, 2024, 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 8341277 + * @summary Testing ClassFile instruction argument validation. + * @run junit InstructionValidationTest + */ + +import java.lang.classfile.*; +import java.lang.classfile.constantpool.ClassEntry; +import java.lang.classfile.constantpool.ConstantPoolBuilder; +import java.lang.classfile.instruction.*; +import java.util.List; +import java.util.function.ObjIntConsumer; +import java.util.stream.Stream; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; + +import static java.lang.constant.ConstantDescs.*; +import static org.junit.jupiter.api.Assertions.*; +import static java.lang.classfile.Opcode.*; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class InstructionValidationTest { + + @Test + void testArgumentConstant() { + assertDoesNotThrow(() -> ConstantInstruction.ofArgument(SIPUSH, 0)); + assertDoesNotThrow(() -> ConstantInstruction.ofArgument(SIPUSH, Short.MIN_VALUE)); + assertDoesNotThrow(() -> ConstantInstruction.ofArgument(SIPUSH, Short.MAX_VALUE)); + assertDoesNotThrow(() -> ConstantInstruction.ofArgument(BIPUSH, 0)); + assertDoesNotThrow(() -> ConstantInstruction.ofArgument(BIPUSH, Byte.MIN_VALUE)); + assertDoesNotThrow(() -> ConstantInstruction.ofArgument(BIPUSH, Byte.MAX_VALUE)); + + assertThrows(IllegalArgumentException.class, () -> ConstantInstruction.ofArgument(SIPUSH, (int) Short.MIN_VALUE - 1)); + assertThrows(IllegalArgumentException.class, () -> ConstantInstruction.ofArgument(SIPUSH, (int) Short.MAX_VALUE + 1)); + assertThrows(IllegalArgumentException.class, () -> ConstantInstruction.ofArgument(BIPUSH, (int) Byte.MIN_VALUE - 1)); + assertThrows(IllegalArgumentException.class, () -> ConstantInstruction.ofArgument(BIPUSH, (int) Byte.MAX_VALUE + 1)); + } + + /** + * Tests the bad slot argument IAE for load, store, increment, and ret. + */ + @Test + void testSlots() { + record Result(boolean shouldFail, int slot) { + } + + List badSlots = List.of(-1, 72694, -42, 0x10000, Integer.MIN_VALUE, Integer.MAX_VALUE); + List u2OnlySlots = List.of(0x100, 1000, 0xFFFF); + List u1Slots = List.of(0, 2, 15, 0xFF); + + List badU1Slots = Stream.concat(badSlots.stream(), u2OnlySlots.stream()).toList(); + List u2Slots = Stream.concat(u1Slots.stream(), u2OnlySlots.stream()).toList(); + List u2Cases = Stream.concat( + badSlots.stream().map(i -> new Result(true, i)), + u2Slots.stream().map(i -> new Result(false, i)) + ).toList(); + List u1Cases = Stream.concat( + badU1Slots.stream().map(i -> new Result(true, i)), + u1Slots.stream().map(i -> new Result(false, i)) + ).toList(); + List nonIntrinsicValues = Stream.of(badSlots, u2Slots, u1Slots).mapMulti(List::forEach) + .filter(i -> i < 0 || i > 3).toList(); + + Label[] capture = new Label[1]; + ClassFile.of().build(CD_Object, clb -> clb.withMethodBody("test", MTD_void, 0, cob -> { + capture[0] = cob.startLabel(); + cob.return_(); + })); + Label dummyLabel = capture[0]; + + List> cbFactories = List.of( + CodeBuilder::aload, + CodeBuilder::iload, + CodeBuilder::lload, + CodeBuilder::dload, + CodeBuilder::fload, + CodeBuilder::astore, + CodeBuilder::istore, + CodeBuilder::lstore, + CodeBuilder::dstore, + CodeBuilder::fstore + ); + + for (var r : u2Cases) { + var fails = r.shouldFail; + var i = r.slot; + for (var fac : cbFactories) { + //check(fails, () -> execute(cob -> fac.accept(cob, i))); + } + for (TypeKind tk : TypeKind.values()) { + if (tk == TypeKind.VOID) + continue; + //check(fails, () -> execute(cob -> cob.loadLocal(tk, i))); + //check(fails, () -> execute(cob -> cob.storeLocal(tk, i))); + check(fails, () -> LoadInstruction.of(tk, i)); + check(fails, () -> StoreInstruction.of(tk, i)); + } + //check(fails, () -> execute(cob -> cob.iinc(i, 1))); + check(fails, () -> IncrementInstruction.of(i, 1)); + check(fails, () -> DiscontinuedInstruction.RetInstruction.of(i)); + check(fails, () -> DiscontinuedInstruction.RetInstruction.of(RET_W, i)); + check(fails, () -> LocalVariable.of(i, "test", CD_Object, dummyLabel, dummyLabel)); + check(fails, () -> LocalVariableType.of(i, "test", Signature.of(CD_Object), dummyLabel, dummyLabel)); + } + + for (var r : u1Cases) { + var fails = r.shouldFail; + var i = r.slot; + for (var u1Op : List.of(ALOAD, ILOAD, LLOAD, FLOAD, DLOAD)) + check(fails, () -> LoadInstruction.of(u1Op, i)); + for (var u1Op : List.of(ASTORE, ISTORE, LSTORE, FSTORE, DSTORE)) + check(fails, () -> StoreInstruction.of(u1Op, i)); + check(fails, () -> DiscontinuedInstruction.RetInstruction.of(RET, i)); + } + + for (var i : nonIntrinsicValues) { + for (var intrinsicOp : List.of(ALOAD_0, ILOAD_0, LLOAD_0, FLOAD_0, DLOAD_0, ALOAD_1, ILOAD_1, LLOAD_1, FLOAD_1, DLOAD_1, + ALOAD_2, ILOAD_2, LLOAD_2, FLOAD_2, DLOAD_2, ALOAD_3, ILOAD_3, LLOAD_3, FLOAD_3, DLOAD_3)) { + assertThrows(IllegalArgumentException.class, () -> LoadInstruction.of(intrinsicOp, i)); + } + for (var intrinsicOp : List.of(ASTORE_0, ISTORE_0, LSTORE_0, FSTORE_0, DSTORE_0, ASTORE_1, ISTORE_1, LSTORE_1, FSTORE_1, DSTORE_1, + ASTORE_2, ISTORE_2, LSTORE_2, FSTORE_2, DSTORE_2, ASTORE_3, ISTORE_3, LSTORE_3, FSTORE_3, DSTORE_3)) { + assertThrows(IllegalArgumentException.class, () -> StoreInstruction.of(intrinsicOp, i)); + } + } + } + + static void check(boolean fails, Executable exec) { + if (fails) { + assertThrows(IllegalArgumentException.class, exec); + } else { + assertDoesNotThrow(exec); + } + } + + @Test + void testIincConstant() { + IncrementInstruction.of(0, 2); + IncrementInstruction.of(0, Short.MAX_VALUE); + IncrementInstruction.of(0, Short.MIN_VALUE); + assertThrows(IllegalArgumentException.class, () -> IncrementInstruction.of(0, Short.MAX_VALUE + 1)); + assertThrows(IllegalArgumentException.class, () -> IncrementInstruction.of(0, Short.MIN_VALUE - 1)); + } + + @Test + void testNewMultiArrayDimension() { + ClassEntry ce = ConstantPoolBuilder.of().classEntry(CD_Class); + NewMultiArrayInstruction.of(ce, 1); + NewMultiArrayInstruction.of(ce, 13); + NewMultiArrayInstruction.of(ce, 0xFF); + assertThrows(IllegalArgumentException.class, () -> NewMultiArrayInstruction.of(ce, 0)); + assertThrows(IllegalArgumentException.class, () -> NewMultiArrayInstruction.of(ce, 0x100)); + assertThrows(IllegalArgumentException.class, () -> NewMultiArrayInstruction.of(ce, -1)); + assertThrows(IllegalArgumentException.class, () -> NewMultiArrayInstruction.of(ce, Integer.MIN_VALUE)); + assertThrows(IllegalArgumentException.class, () -> NewMultiArrayInstruction.of(ce, Integer.MAX_VALUE)); + } +} diff --git a/test/jdk/jdk/classfile/OpcodesValidationTest.java b/test/jdk/jdk/classfile/OpcodesValidationTest.java deleted file mode 100644 index 2470fcf132c..00000000000 --- a/test/jdk/jdk/classfile/OpcodesValidationTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2022, 2024, 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 - * @summary Testing ClassFile constant instruction argument validation. - * @run junit OpcodesValidationTest - */ -import java.lang.classfile.instruction.ConstantInstruction; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; -import static java.lang.classfile.Opcode.*; - -class OpcodesValidationTest { - - @Test - void testArgumentConstant() { - assertDoesNotThrow(() -> ConstantInstruction.ofArgument(SIPUSH, 0)); - assertDoesNotThrow(() -> ConstantInstruction.ofArgument(SIPUSH, Short.MIN_VALUE)); - assertDoesNotThrow(() -> ConstantInstruction.ofArgument(SIPUSH, Short.MAX_VALUE)); - assertDoesNotThrow(() -> ConstantInstruction.ofArgument(BIPUSH, 0)); - assertDoesNotThrow(() -> ConstantInstruction.ofArgument(BIPUSH, Byte.MIN_VALUE)); - assertDoesNotThrow(() -> ConstantInstruction.ofArgument(BIPUSH, Byte.MAX_VALUE)); - - assertThrows(IllegalArgumentException.class, () -> ConstantInstruction.ofArgument(SIPUSH, (int)Short.MIN_VALUE - 1)); - assertThrows(IllegalArgumentException.class, () -> ConstantInstruction.ofArgument(SIPUSH, (int)Short.MAX_VALUE + 1)); - assertThrows(IllegalArgumentException.class, () -> ConstantInstruction.ofArgument(BIPUSH, (int)Byte.MIN_VALUE - 1)); - assertThrows(IllegalArgumentException.class, () -> ConstantInstruction.ofArgument(BIPUSH, (int)Byte.MAX_VALUE + 1)); - } -} diff --git a/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithG1ConcurrentMark.java b/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithG1ConcurrentMark.java index bd3a7f63a8a..e0ea218a07f 100644 --- a/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithG1ConcurrentMark.java +++ b/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithG1ConcurrentMark.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -41,7 +41,7 @@ public static void main(String[] args) throws Exception { String[] vmFlags = {"-XX:+UseG1GC", "-XX:+ExplicitGCInvokesConcurrent"}; String[] gcNames = {GCHelper.gcG1New, GCHelper.gcG1Old, GCHelper.gcG1Full}; String[] gcCauses = {"Metadata GC Threshold", "G1 Evacuation Pause", "G1 Preventive Collection", - "G1 Compaction Pause", "System.gc()"}; + "G1 Compaction Pause", "CodeCache GC Threshold", "System.gc()"}; GCGarbageCollectionUtil.test(testID, vmFlags, gcNames, gcCauses); } } diff --git a/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithG1FullCollection.java b/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithG1FullCollection.java index 072c3905baf..308a544adeb 100644 --- a/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithG1FullCollection.java +++ b/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithG1FullCollection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -41,7 +41,7 @@ public static void main(String[] args) throws Exception { String[] vmFlags = {"-XX:+UseG1GC"}; String[] gcNames = {GCHelper.gcG1New, GCHelper.gcG1Old, GCHelper.gcG1Full}; String[] gcCauses = {"Metadata GC Threshold", "G1 Evacuation Pause", "G1 Preventive Collection", - "G1 Compaction Pause", "System.gc()"}; + "G1 Compaction Pause", "CodeCache GC Threshold", "System.gc()"}; GCGarbageCollectionUtil.test(testID, vmFlags, gcNames, gcCauses); } } diff --git a/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithParallelOld.java b/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithParallelOld.java index 4d8f697d837..16217c0cbe1 100644 --- a/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithParallelOld.java +++ b/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithParallelOld.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -39,7 +39,8 @@ public static void main(String[] args) throws Exception { String testID = "ParallelOld"; String[] vmFlags = {"-XX:+UseParallelGC"}; String[] gcNames = {GCHelper.gcParallelScavenge, GCHelper.gcParallelOld}; - String[] gcCauses = {"Allocation Failure", "System.gc()", "GCLocker Initiated GC"}; + String[] gcCauses = {"Allocation Failure", "System.gc()", "GCLocker Initiated GC", + "CodeCache GC Threshold"}; GCGarbageCollectionUtil.test(testID, vmFlags, gcNames, gcCauses); } } diff --git a/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithSerial.java b/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithSerial.java index 403bd077585..344c61043a2 100644 --- a/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithSerial.java +++ b/test/jdk/jdk/jfr/event/gc/collection/TestGCCauseWithSerial.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -39,7 +39,8 @@ public static void main(String[] args) throws Exception { String testID = "Serial"; String[] vmFlags = {"-XX:+UseSerialGC"}; String[] gcNames = {GCHelper.gcDefNew, GCHelper.gcSerialOld}; - String[] gcCauses = {"Allocation Failure", "System.gc()", "GCLocker Initiated GC"}; + String[] gcCauses = {"Allocation Failure", "System.gc()", "GCLocker Initiated GC", + "CodeCache GC Threshold"}; GCGarbageCollectionUtil.test(testID, vmFlags, gcNames, gcCauses); } } diff --git a/test/jdk/security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java b/test/jdk/security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java index ab04391b1f3..924f58cc80f 100644 --- a/test/jdk/security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java +++ b/test/jdk/security/infra/java/security/cert/CertPathValidator/certification/CAInterop.java @@ -535,6 +535,28 @@ * @run main/othervm/manual -Djava.security.debug=certpath CAInterop globalsigne46 CRL */ +/* + * @test id=ssltlsrootecc2022 + * @bug 8341057 + * @summary Interoperability tests with SSL TLS 2022 root CAs + * @library /test/lib + * @build jtreg.SkippedException ValidatePathWithURL CAInterop + * @run main/othervm/manual -Djava.security.debug=certpath,ocsp CAInterop ssltlsrootecc2022 DEFAULT + * @run main/othervm/manual -Djava.security.debug=certpath,ocsp -Dcom.sun.security.ocsp.useget=false CAInterop ssltlsrootecc2022 DEFAULT + * @run main/othervm/manual -Djava.security.debug=certpath CAInterop ssltlsrootecc2022 CRL + */ + +/* + * @test id=ssltlsrootrsa2022 + * @bug 8341057 + * @summary Interoperability tests with SSL TLS 2022 root CAs + * @library /test/lib + * @build jtreg.SkippedException ValidatePathWithURL CAInterop + * @run main/othervm/manual -Djava.security.debug=certpath,ocsp CAInterop ssltlsrootrsa2022 DEFAULT + * @run main/othervm/manual -Djava.security.debug=certpath,ocsp -Dcom.sun.security.ocsp.useget=false CAInterop ssltlsrootrsa2022 DEFAULT + * @run main/othervm/manual -Djava.security.debug=certpath CAInterop ssltlsrootrsa2022 CRL + */ + /** * Collection of certificate validation tests for interoperability with external CAs. * These tests are marked as manual as they depend on external infrastructure and may fail @@ -713,6 +735,13 @@ private CATestURLs getTestURLs(String alias) { new CATestURLs("https://valid.e46.roots.globalsign.com", "https://revoked.e46.roots.globalsign.com"); + case "ssltlsrootecc2022" -> + new CATestURLs("https://test-root-2022-ecc.ssl.com", + "https://revoked-root-2022-ecc.ssl.com"); + case "ssltlsrootrsa2022" -> + new CATestURLs("https://test-root-2022-rsa.ssl.com", + "https://revoked-root-2022-rsa.ssl.com"); + default -> throw new RuntimeException("No test setup found for: " + alias); }; } diff --git a/test/jdk/sun/awt/font/CacheFlushTest.java b/test/jdk/sun/awt/font/CacheFlushTest.java new file mode 100644 index 00000000000..f3b32931275 --- /dev/null +++ b/test/jdk/sun/awt/font/CacheFlushTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 1999, 2024, 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 4286726 + * @summary Java2D raster printing: large text may overflow glyph cache. + * Draw a large glyphvector, the 'A' glyph should appear and not get flushed. +*/ + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; +import java.awt.geom.Point2D; +import java.awt.image.BufferedImage; +import java.util.HashMap; + +/** + * Draw a very large glyphvector on a surface. + * If the cache was flushed the first glyph is not rendered. + * Note: the implementation no longer uses glyphs for rendering large text, + * but in principle the test is still useful. + */ +public class CacheFlushTest { + + static final int WIDTH = 400, HEIGHT = 600; + static final int FONTSIZE = 250; + static final String TEST = "ABCDEFGHIJKLMNOP"; + static final HashMap HINTS = new HashMap<>(); + + static { + HINTS.put(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + HINTS.put(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + HINTS.put(RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_ON); + } + + public static void main(String args[]) { + BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); + + Graphics2D g2d = bi.createGraphics(); + g2d.addRenderingHints(HINTS); + g2d.setColor(Color.white); + g2d.fillRect(0, 0, WIDTH, HEIGHT); + g2d.setColor(Color.black); + + FontRenderContext frc = g2d.getFontRenderContext(); + Font font = new Font(Font.DIALOG, Font.PLAIN, 250); + GlyphVector gv = font.createGlyphVector(frc, TEST); + + /* Set the positions of all but the first glyph to be offset vertically but + * FONTSIZE pixels. So if the first glyph "A" is not flushed we can tell this + * by checking for non-white pixels in the range for the default y offset of 0 + * from the specified y location. + */ + Point2D.Float pt = new Point2D.Float(20f, FONTSIZE); + for (int i = 1; i < gv.getNumGlyphs(); ++i) { + gv.setGlyphPosition(i, pt); + pt.x += 25f; + pt.y = FONTSIZE; + } + g2d.drawGlyphVector(gv, 20, FONTSIZE); + /* Now expect to find at least one black pixel in the rect (0,0) -> (WIDTH, FONTSIZE) */ + boolean found = false; + int blackPixel = Color.black.getRGB(); + for (int y = 0; y < FONTSIZE; y++) { + for (int x = 0; x < WIDTH; x++) { + if (bi.getRGB(x, y) == blackPixel) { + found = true; + break; + } + } + if (found == true) { + break; + } + } + if (!found) { + throw new RuntimeException("NO BLACK PIXELS"); + } + } +} diff --git a/test/jdk/sun/awt/font/TestArabicHebrew.java b/test/jdk/sun/awt/font/TestArabicHebrew.java new file mode 100644 index 00000000000..61cbe931c32 --- /dev/null +++ b/test/jdk/sun/awt/font/TestArabicHebrew.java @@ -0,0 +1,215 @@ +/* + * Copyright (c) 1999, 2024, 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 4198081 + * @key headful + * @summary Arabic characters should appear instead of boxes and be correctly shaped. + * Hebrew characters should appear instead of boxes. + * Test is made headful so there's no excuse for test systems not having the fonts. + */ + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GridLayout; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Panel; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; +import java.awt.geom.Rectangle2D; + +public class TestArabicHebrew extends Panel { + + static volatile Frame frame; + static volatile Font font = new Font(Font.DIALOG, Font.PLAIN, 36); + + static void createUI() { + frame = new Frame("Test Arabic/Hebrew"); + frame.setLayout(new BorderLayout()); + TestArabicHebrew panel = new TestArabicHebrew(); + frame.add(panel, BorderLayout.CENTER); + frame.pack(); + frame.setVisible(true); + } + + public static void main(String args[]) throws Exception { + EventQueue.invokeAndWait(TestArabicHebrew::createUI); + try { + checkStrings(); + } finally { + if (frame != null && args.length == 0) { + EventQueue.invokeAndWait(frame::dispose); + } + } + } + + static void checkString(String script, String str) { + int index = font.canDisplayUpTo(str); + if (index != -1) { + throw new RuntimeException("Cannot display char " + index + " for " + script); + } + } + + static void checkStrings() { + checkString("Arabic", arabic); + checkString("Hebrew", hebrew); + checkString("Latin-1 Supplement", latin1sup); + } + + // Table of arabic unicode characters - minimal support level + // Includes arabic chars from basic block up to 0652 and + // corresponding shaped characters from the arabic + // extended-B block from fe80 to fefc (does include lam-alef + // ligatures). + // Does not include arabic-indic digits nor "arabic extended" + // range. + + static final String arabic = + "\u060c\u061b\u061f\u0621\u0622\u0623\u0624\u0625\u0626\u0627" + + "\u0628\u0629\u062a\u062b\u062c\u062d\u062e\u062f\u0630\u0631" + + "\u0632\u0633\u0634\u0635\u0636\u0637\u0638\u0639\u063a\u0640" + + "\u0641\u0642\u0643\u0644\u0645\u0646\u0647\u0648\u0649\u064a" + + "\u064b\u064c\u064d\u064e\u064f\u0650\u0651\u0652\ufe80\ufe81" + + "\ufe82\ufe83\ufe84\ufe85\ufe86\ufe87\ufe88\ufe89\ufe8a\ufe8b" + + "\ufe8c\ufe8d\ufe8e\ufe8f\ufe90\ufe91\ufe92\ufe93\ufe94\ufe95" + + "\ufe96\ufe97\ufe98\ufe99\ufe9a\ufe9b\ufe9c\ufe9d\ufe9e\ufe9f" + + "\ufea0\ufea1\ufea2\ufea3\ufea4\ufea5\ufea6\ufea7\ufea8\ufea9" + + "\ufeaa\ufeab\ufeac\ufead\ufeae\ufeaf\ufeb0\ufeb1\ufeb2\ufeb3" + + "\ufeb4\ufeb5\ufeb6\ufeb7\ufeb8\ufeb9\ufeba\ufebb\ufebc\ufebd" + + "\ufebe\ufebf\ufec0\ufec1\ufec2\ufec3\ufec4\ufec5\ufec6\ufec7" + + "\ufec8\ufec9\ufeca\ufecb\ufecc\ufecd\ufece\ufecf\ufed0\ufed1" + + "\ufed2\ufed3\ufed4\ufed5\ufed6\ufed7\ufed8\ufed9\ufeda\ufedb" + + "\ufedc\ufedd\ufede\ufedf\ufee0\ufee1\ufee2\ufee3\ufee4\ufee5" + + "\ufee6\ufee7\ufee8\ufee9\ufeea\ufeeb\ufeec\ufeed\ufeee\ufeef" + + "\ufef0\ufef1\ufef2\ufef3\ufef4\ufef5\ufef6\ufef7\ufef8\ufef9" + + "\ufefa\ufefb\ufefc"; + + // hebrew table includes all characters in hebrew block + + static final String hebrew = + "\u0591\u0592\u0593\u0594\u0595\u0596\u0597\u0598\u0599\u059a" + + "\u059b\u059c\u059d\u059e\u059f\u05a0\u05a1\u05a3\u05a4\u05a5" + + "\u05a6\u05a7\u05a8\u05a9\u05aa\u05ab\u05ac\u05ad\u05ae\u05af" + + "\u05b0\u05b1\u05b2\u05b3\u05b4\u05b5\u05b6\u05b7\u05b8\u05b9" + + "\u05bb\u05bc\u05bd\u05be\u05bf\u05c0\u05c1\u05c2\u05c3\u05c4" + + "\u05d0\u05d1\u05d2\u05d3\u05d4\u05d5\u05d6\u05d7\u05d8\u05d9" + + "\u05da\u05db\u05dc\u05dd\u05de\u05df\u05e0\u05e1\u05e2\u05e3" + + "\u05e4\u05e5\u05e6\u05e7\u05e8\u05e9\u05ea\u05f0\u05f1\u05f2" + + "\u05f3\u05f4"; + + // latin 1 supplement table includes all non-control characters + // in this range. Included because of comment in code that claims + // some problems displaying this range with some SJIS fonts. + + static final String latin1sup = + "\u00a0\u00a1\u00a2\u00a3\u00a4\u00a5\u00a6\u00a7" + + "\u00a8\u00a9\u00aa\u00ab\u00ac\u00ad\u00ae\u00af\u00b0\u00b1" + + "\u00b2\u00b3\u00b4\u00b5\u00b6\u00b7\u00b8\u00b9\u00ba\u00bb" + + "\u00bc\u00bd\u00be\u00bf\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5" + + "\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf" + + "\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d7\u00d8\u00d9" + + "\u00da\u00db\u00dc\u00dd\u00de\u00df\u00e0\u00e1\u00e2\u00e3" + + "\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed" + + "\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f7" + + "\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u00ff"; + + public TestArabicHebrew() { + setLayout(new GridLayout(3, 1)); + + FontRenderContext frc = new FontRenderContext(null, false, false); + add(new SubGlyphPanel("Arabic", arabic, font, frc)); + add(new SubGlyphPanel("Hebrew", hebrew, font, frc)); + add(new SubGlyphPanel("Latin-1 Supplement", latin1sup, font, frc)); + } + + static class SubGlyphPanel extends Panel { + String title; + Dimension extent; + GlyphVector[] vectors; + + static final int kGlyphsPerLine = 20; + + SubGlyphPanel(String title, String chars, Font font, FontRenderContext frc) { + + this.title = title; + setBackground(Color.white); + + double width = 0; + double height = 0; + + int max = chars.length(); + vectors = new GlyphVector[(max + kGlyphsPerLine - 1) / kGlyphsPerLine]; + for (int i = 0; i < vectors.length; i++) { + int start = i * 20; + int limit = Math.min(max, (i + 1) * kGlyphsPerLine); + String substr = ""; + for (int j = start; j < limit; ++j) { + substr = substr.concat(chars.charAt(j) + " "); + } + GlyphVector gv = font.createGlyphVector(frc, substr); + vectors[i] = gv; + Rectangle2D bounds = gv.getLogicalBounds(); + + width = Math.max(width, bounds.getWidth()); + height += bounds.getHeight(); + } + + extent = new Dimension((int)(width + 1), (int)(height + 1 + 30)); // room for title + + setSize(getPreferredSize()); + } + + public Dimension getPreferredSize() { + return new Dimension(extent); + } + + public Dimension getMinimumSize() { + return getPreferredSize(); + } + + public Dimension getMaximumSize() { + return getPreferredSize(); + } + + public void paint(Graphics g) { + Graphics2D g2d = (Graphics2D)g; + + g.drawString(title, 10, 20); + + float x = 10; + float y = 30; + for (int i = 0; i < vectors.length; ++i) { + GlyphVector gv = vectors[i]; + Rectangle2D bounds = gv.getLogicalBounds(); + g2d.drawGlyphVector(gv, x, (float)(y - bounds.getY())); + y += bounds.getHeight(); + } + } + } +} diff --git a/test/jdk/sun/awt/font/TestDevTransform.java b/test/jdk/sun/awt/font/TestDevTransform.java new file mode 100644 index 00000000000..035cb0b13d7 --- /dev/null +++ b/test/jdk/sun/awt/font/TestDevTransform.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 1999, 2024, 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 4269775 + * @summary Check that different text rendering APIs agree + */ + +/** + * Draw into an image rendering the same text string nine different + * ways: as a TextLayout, a simple String, and a GlyphVector, each + * with three different x scale factors. The expectation is that each + * set of three strings would appear the same although offset in y to + * avoid overlap. The bug was that the y positions of the individual characters + * of the TextLayout and GlyphVector were wrong, so the strings appeared + * to be rendered at different angles. + */ + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.font.FontRenderContext; +import java.awt.font.GlyphVector; +import java.awt.font.TextLayout; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; +import java.util.HashMap; + +public class TestDevTransform { + + static HashMap hints = new HashMap<>(); + + static { + hints.put(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + hints.put(RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_ON); + } + + static String test = "This is only a test"; + static double angle = Math.PI / 6.0; // Rotate 30 degrees + static final int W = 400, H = 400; + + static void draw(Graphics2D g2d, TextLayout layout, + float x, float y, float scalex) { + AffineTransform saveTransform = g2d.getTransform(); + g2d.translate(x, y); + g2d.rotate(angle); + g2d.scale(scalex, 1f); + layout.draw(g2d, 0f, 0f); + g2d.setTransform(saveTransform); + } + + static void draw(Graphics2D g2d, String string, + float x, float y, float scalex) { + AffineTransform saveTransform = g2d.getTransform(); + g2d.translate(x, y); + g2d.rotate(angle); + g2d.scale(scalex, 1f); + g2d.drawString(string, 0f, 0f); + g2d.setTransform(saveTransform); + } + + static void draw(Graphics2D g2d, GlyphVector gv, + float x, float y, float scalex) { + AffineTransform saveTransform = g2d.getTransform(); + g2d.translate(x, y); + g2d.rotate(angle); + g2d.scale(scalex, 1f); + g2d.drawGlyphVector(gv, 0f, 0f); + g2d.setTransform(saveTransform); + } + + static void init(Graphics2D g2d) { + g2d.setColor(Color.white); + g2d.fillRect(0, 0, W, H); + g2d.setColor(Color.black); + g2d.scale(1.481f, 1.481); // Convert to 108 dpi + g2d.addRenderingHints(hints); + Font font = new Font(Font.DIALOG, Font.PLAIN, 12); + g2d.setFont(font); + } + + static void compare(BufferedImage bi1, BufferedImage bi2) { + for (int x = 0; x < bi1.getWidth(); x++) { + for (int y = 0; y < bi1.getHeight(); y++) { + if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) { + throw new RuntimeException("Different rendering"); + } + } + } + } + + public static void main(String args[]) { + + BufferedImage tl_Image = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB); + { + Graphics2D tl_g2d = tl_Image.createGraphics(); + init(tl_g2d); + FontRenderContext frc = tl_g2d.getFontRenderContext(); + // Specify font from graphics to be sure it is the same as the other cases. + TextLayout tl = new TextLayout(test, tl_g2d.getFont(), frc); + draw(tl_g2d, tl, 10f, 12f, 3.0f); + draw(tl_g2d, tl, 10f, 24f, 1.0f); + draw(tl_g2d, tl, 10f, 36f, 0.33f); + } + + BufferedImage st_Image = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB); + { + Graphics2D st_g2d = st_Image.createGraphics(); + init(st_g2d); + draw(st_g2d, test, 10f, 12f, 3.0f); + draw(st_g2d, test, 10f, 24f, 1.0f); + draw(st_g2d, test, 10f, 36f, .33f); + } + + BufferedImage gv_Image = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB); + { + Graphics2D gv_g2d = gv_Image.createGraphics(); + init(gv_g2d); + FontRenderContext frc = gv_g2d.getFontRenderContext(); + GlyphVector gv = gv_g2d.getFont().createGlyphVector(frc, test); + draw(gv_g2d, gv, 10f, 12f, 3.0f); + draw(gv_g2d, gv, 10f, 24f, 1.0f); + draw(gv_g2d, gv, 10f, 36f, .33f); + } + + compare(tl_Image, st_Image); + compare(gv_Image, st_Image); + } +} diff --git a/test/jdk/sun/awt/windows/TestPen.java b/test/jdk/sun/awt/windows/TestPen.java new file mode 100644 index 00000000000..25b7304bdc8 --- /dev/null +++ b/test/jdk/sun/awt/windows/TestPen.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 1999, 2024, 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 4277201 + * @summary verifies that invoking a fill on a brand new Graphics object + * does not stroke the shape in addition to filling it + * @key headful + */ + +/* + * This test case tests for a problem with initializing GDI graphics + * contexts (HDCs) where a pen is left installed in the graphics object + * even though the AWT believes that there is no Pen installed. The + * result is that when you try to fill a shape, GDI will both fill and + * stroke it. +*/ + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Panel; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.image.BufferedImage; + +public class TestPen extends Panel { + + static volatile TestPen pen; + static volatile Frame frame; + + public TestPen() { + setForeground(Color.black); + setBackground(Color.white); + } + + public Dimension getPreferredSize() { + return new Dimension(200, 200); + } + + public void paint(Graphics g) { + g.setColor(Color.green); + g.fillOval(50, 50, 100, 100); + } + + static void createUI() { + frame = new Frame(); + pen = new TestPen(); + frame.add(pen); + frame.pack(); + frame.setVisible(true); + } + + public static void main(String argv[]) throws Exception { + try { + EventQueue.invokeAndWait(TestPen::createUI); + Robot robot = new Robot(); + robot.waitForIdle(); + robot.delay(2000); + Point p = pen.getLocationOnScreen(); + Dimension d = pen.getSize(); + Rectangle r = new Rectangle(p.x + 1, p.y + 1, d.width - 2, d.height - 2); + BufferedImage bi = robot.createScreenCapture(r); + int blackPixel = Color.black.getRGB(); + for (int y = 0; y < bi.getHeight(); y++ ) { + for (int x = 0; x < bi.getWidth(); x++ ) { + if (bi.getRGB(x, y) == blackPixel) { + throw new RuntimeException("Black pixel !"); + } + } + } + } finally { + if (frame != null) { + EventQueue.invokeAndWait(frame::dispose); + } + } + } +} diff --git a/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java b/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java index 83427f1a33a..d64c5d7c52b 100644 --- a/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java +++ b/test/jdk/sun/security/lib/cacerts/VerifyCACerts.java @@ -19,17 +19,16 @@ * 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 8189131 8198240 8191844 8189949 8191031 8196141 8204923 8195774 8199779 * 8209452 8209506 8210432 8195793 8216577 8222089 8222133 8222137 8222136 * 8223499 8225392 8232019 8234245 8233223 8225068 8225069 8243321 8243320 * 8243559 8225072 8258630 8259312 8256421 8225081 8225082 8225083 8245654 * 8305975 8304760 8307134 8295894 8314960 8317373 8317374 8318759 8319187 - * 8321408 8316138 + * 8321408 8316138 8341057 * @summary Check root CA entries in cacerts file */ import java.io.ByteArrayInputStream; @@ -48,12 +47,12 @@ public class VerifyCACerts { + File.separator + "security" + File.separator + "cacerts"; // The numbers of certs now. - private static final int COUNT = 110; + private static final int COUNT = 112; // SHA-256 of cacerts, can be generated with // shasum -a 256 cacerts | sed -e 's/../&:/g' | tr '[:lower:]' '[:upper:]' | cut -c1-95 private static final String CHECKSUM - = "BD:80:65:81:68:E5:6C:51:64:ED:B9:08:53:9F:BB:2F:D9:6C:5D:D4:06:D4:16:59:39:10:8E:F8:24:81:8B:78"; + = "21:68:E7:16:5B:94:23:D2:60:5C:BB:F2:AF:C1:66:5C:EC:36:BC:20:FF:5C:54:AF:91:D1:2C:38:AE:55:D3:27"; // Hex formatter to upper case with ":" delimiter private static final HexFormat HEX = HexFormat.ofDelimiter(":").withUpperCase(); @@ -282,6 +281,10 @@ public class VerifyCACerts { "4F:A3:12:6D:8D:3A:11:D1:C4:85:5A:4F:80:7C:BA:D6:CF:91:9D:3A:5A:88:B0:3B:EA:2C:63:72:D9:3C:40:C9"); put("globalsigne46 [jdk]", "CB:B9:C4:4D:84:B8:04:3E:10:50:EA:31:A6:9F:51:49:55:D7:BF:D2:E2:C6:B4:93:01:01:9A:D6:1D:9F:50:58"); + put("ssltlsrootecc2022 [jdk]", + "C3:2F:FD:9F:46:F9:36:D1:6C:36:73:99:09:59:43:4B:9A:D6:0A:AF:BB:9E:7C:F3:36:54:F1:44:CC:1B:A1:43"); + put("ssltlsrootrsa2022 [jdk]", + "8F:AF:7D:2E:2C:B4:70:9B:B8:E0:B3:36:66:BF:75:A5:DD:45:B5:DE:48:0F:8E:A8:D4:BF:E6:BE:BC:17:F2:ED"); } }; diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/Distrust.java b/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/Distrust.java deleted file mode 100644 index ba008c68cdc..00000000000 --- a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/Distrust.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright (c) 2018, 2022, 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. - */ - -import java.io.*; -import java.math.BigInteger; -import java.security.*; -import java.security.cert.*; -import java.time.*; -import java.util.*; -import javax.net.ssl.*; -import sun.security.validator.Validator; -import sun.security.validator.ValidatorException; - -import jdk.test.lib.security.SecurityUtils; - -/** - * @test - * @bug 8207258 8216280 - * @summary Check that TLS Server certificates chaining back to distrusted - * Symantec roots are invalid - * @library /test/lib - * @modules java.base/sun.security.validator - * @run main/othervm Distrust after policyOn invalid - * @run main/othervm Distrust after policyOff valid - * @run main/othervm Distrust before policyOn valid - * @run main/othervm Distrust before policyOff valid - */ - -public class Distrust { - - private static final String TEST_SRC = System.getProperty("test.src", "."); - private static CertificateFactory cf; - - // Each of the roots have a test certificate chain stored in a file - // named "-chain.pem". - private static String[] rootsToTest = new String[] { - "geotrustprimarycag2", "geotrustprimarycag3", - "geotrustuniversalca", "thawteprimaryrootca", "thawteprimaryrootcag2", - "thawteprimaryrootcag3", "verisignclass3g3ca", "verisignclass3g4ca", - "verisignclass3g5ca", "verisignuniversalrootca" }; - - // Each of the subCAs with a delayed distrust date have a test certificate - // chain stored in a file named "-chain.pem". - private static String[] subCAsToTest = new String[]{"appleistca8g1"}; - - // A date that is after the restrictions take affect - private static final Date APRIL_17_2019 = - Date.from(LocalDate.of(2019, 4, 17) - .atStartOfDay(ZoneOffset.UTC) - .toInstant()); - - // A date that is a second before the restrictions take affect - private static final Date BEFORE_APRIL_17_2019 = - Date.from(LocalDate.of(2019, 4, 17) - .atStartOfDay(ZoneOffset.UTC) - .minusSeconds(1) - .toInstant()); - - // A date that is after the subCA restrictions take affect - private static final Date JANUARY_1_2020 = - Date.from(LocalDate.of(2020, 1, 1) - .atStartOfDay(ZoneOffset.UTC) - .toInstant()); - - // A date that is a second before the subCA restrictions take affect - private static final Date BEFORE_JANUARY_1_2020 = - Date.from(LocalDate.of(2020, 1, 1) - .atStartOfDay(ZoneOffset.UTC) - .minusSeconds(1) - .toInstant()); - - public static void main(String[] args) throws Exception { - - cf = CertificateFactory.getInstance("X.509"); - - boolean before = args[0].equals("before"); - boolean policyOn = args[1].equals("policyOn"); - boolean isValid = args[2].equals("valid"); - - if (!policyOn) { - // disable policy (default is on) - Security.setProperty("jdk.security.caDistrustPolicies", ""); - } - - Date notBefore = before ? BEFORE_APRIL_17_2019 : APRIL_17_2019; - - X509TrustManager pkixTM = getTMF("PKIX", null); - X509TrustManager sunX509TM = getTMF("SunX509", null); - for (String test : rootsToTest) { - System.err.println("Testing " + test); - X509Certificate[] chain = loadCertificateChain(test); - - testTM(sunX509TM, chain, notBefore, isValid); - testTM(pkixTM, chain, notBefore, isValid); - } - - // test chain if params are passed to TrustManager - System.err.println("Testing verisignuniversalrootca with params"); - testTM(getTMF("PKIX", getParams()), - loadCertificateChain("verisignuniversalrootca"), - notBefore, isValid); - - // test code-signing chain (should be valid as restrictions don't apply) - System.err.println("Testing verisignclass3g5ca code-signing chain"); - Validator v = Validator.getInstance(Validator.TYPE_PKIX, - Validator.VAR_CODE_SIGNING, - getParams()); - // set validation date so this will still pass when cert expires - v.setValidationDate(new Date(1544197375493l)); - v.validate(loadCertificateChain("verisignclass3g5ca-codesigning")); - - // test chains issued through subCAs - notBefore = before ? BEFORE_JANUARY_1_2020 : JANUARY_1_2020; - for (String test : subCAsToTest) { - System.err.println("Testing " + test); - X509Certificate[] chain = loadCertificateChain(test); - - testTM(sunX509TM, chain, notBefore, isValid); - testTM(pkixTM, chain, notBefore, isValid); - } - } - - private static X509TrustManager getTMF(String type, - PKIXBuilderParameters params) throws Exception { - TrustManagerFactory tmf = TrustManagerFactory.getInstance(type); - if (params == null) { - tmf.init((KeyStore)null); - } else { - tmf.init(new CertPathTrustManagerParameters(params)); - } - TrustManager[] tms = tmf.getTrustManagers(); - for (TrustManager tm : tms) { - X509TrustManager xtm = (X509TrustManager)tm; - return xtm; - } - throw new Exception("No TrustManager for " + type); - } - - private static PKIXBuilderParameters getParams() throws Exception { - PKIXBuilderParameters pbp = - new PKIXBuilderParameters(SecurityUtils.getCacertsKeyStore(), - new X509CertSelector()); - pbp.setRevocationEnabled(false); - return pbp; - } - - private static void testTM(X509TrustManager xtm, X509Certificate[] chain, - Date notBefore, boolean valid) throws Exception { - // Check if TLS Server certificate (the first element of the chain) - // is issued after the specified notBefore date (should be rejected - // unless distrust property is false). To do this, we need to - // fake the notBefore date since none of the test certs are issued - // after then. - chain[0] = new DistrustedTLSServerCert(chain[0], notBefore); - - try { - xtm.checkServerTrusted(chain, "ECDHE_RSA"); - if (!valid) { - throw new Exception("chain should be invalid"); - } - } catch (CertificateException ce) { - // expired TLS certificates should not be treated as failure - if (expired(ce)) { - System.err.println("Test is N/A, chain is expired"); - return; - } - if (valid) { - throw new Exception("Unexpected exception, chain " + - "should be valid", ce); - } - if (ce instanceof ValidatorException) { - ValidatorException ve = (ValidatorException)ce; - if (ve.getErrorType() != ValidatorException.T_UNTRUSTED_CERT) { - ce.printStackTrace(System.err); - throw new Exception("Unexpected exception: " + ce); - } - } else { - throw new Exception("Unexpected exception: " + ce); - } - } - } - - // check if a cause of exception is an expired cert - private static boolean expired(CertificateException ce) { - if (ce instanceof CertificateExpiredException) { - return true; - } - Throwable t = ce.getCause(); - while (t != null) { - if (t instanceof CertificateExpiredException) { - return true; - } - t = t.getCause(); - } - return false; - } - - private static X509Certificate[] loadCertificateChain(String name) - throws Exception { - try (InputStream in = new FileInputStream(TEST_SRC + File.separator + - name + "-chain.pem")) { - Collection certs = - (Collection)cf.generateCertificates(in); - return certs.toArray(new X509Certificate[0]); - } - } - - private static class DistrustedTLSServerCert extends X509Certificate { - private final X509Certificate cert; - private final Date notBefore; - DistrustedTLSServerCert(X509Certificate cert, Date notBefore) { - this.cert = cert; - this.notBefore = notBefore; - } - public Set getCriticalExtensionOIDs() { - return cert.getCriticalExtensionOIDs(); - } - public byte[] getExtensionValue(String oid) { - return cert.getExtensionValue(oid); - } - public Set getNonCriticalExtensionOIDs() { - return cert.getNonCriticalExtensionOIDs(); - } - public boolean hasUnsupportedCriticalExtension() { - return cert.hasUnsupportedCriticalExtension(); - } - public void checkValidity() throws CertificateExpiredException, - CertificateNotYetValidException { - // always pass - } - public void checkValidity(Date date) throws CertificateExpiredException, - CertificateNotYetValidException { - // always pass - } - public int getVersion() { return cert.getVersion(); } - public BigInteger getSerialNumber() { return cert.getSerialNumber(); } - public Principal getIssuerDN() { return cert.getIssuerDN(); } - public Principal getSubjectDN() { return cert.getSubjectDN(); } - public Date getNotBefore() { return notBefore; } - public Date getNotAfter() { return cert.getNotAfter(); } - public byte[] getTBSCertificate() throws CertificateEncodingException { - return cert.getTBSCertificate(); - } - public byte[] getSignature() { return cert.getSignature(); } - public String getSigAlgName() { return cert.getSigAlgName(); } - public String getSigAlgOID() { return cert.getSigAlgOID(); } - public byte[] getSigAlgParams() { return cert.getSigAlgParams(); } - public boolean[] getIssuerUniqueID() { - return cert.getIssuerUniqueID(); - } - public boolean[] getSubjectUniqueID() { - return cert.getSubjectUniqueID(); - } - public boolean[] getKeyUsage() { return cert.getKeyUsage(); } - public int getBasicConstraints() { return cert.getBasicConstraints(); } - public byte[] getEncoded() throws CertificateEncodingException { - return cert.getEncoded(); - } - public void verify(PublicKey key) throws CertificateException, - InvalidKeyException, NoSuchAlgorithmException, - NoSuchProviderException, SignatureException { - cert.verify(key); - } - public void verify(PublicKey key, String sigProvider) throws - CertificateException, InvalidKeyException, NoSuchAlgorithmException, - NoSuchProviderException, SignatureException { - cert.verify(key, sigProvider); - } - public PublicKey getPublicKey() { return cert.getPublicKey(); } - public String toString() { return cert.toString(); } - } -} diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/Distrust.java b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/Distrust.java similarity index 54% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/Distrust.java rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/Distrust.java index a9a47bf834c..18178f65ec1 100644 --- a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/Distrust.java +++ b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/Distrust.java @@ -25,7 +25,7 @@ import java.math.BigInteger; import java.security.*; import java.security.cert.*; -import java.time.*; +import java.time.ZonedDateTime; import java.util.*; import javax.net.ssl.*; import sun.security.validator.Validator; @@ -34,95 +34,80 @@ import jdk.test.lib.security.SecurityUtils; /** - * @test - * @bug 8337664 - * @summary Check that TLS Server certificates chaining back to distrusted - * Entrust roots are invalid - * @library /test/lib - * @modules java.base/sun.security.validator - * @run main/othervm Distrust after policyOn invalid - * @run main/othervm Distrust after policyOff valid - * @run main/othervm Distrust before policyOn valid - * @run main/othervm Distrust before policyOff valid + * Helper class that provides methods to facilitate testing of distrusted roots. */ - -public class Distrust { +public final class Distrust { private static final String TEST_SRC = System.getProperty("test.src", "."); private static CertificateFactory cf; - // Each of the roots have a test certificate chain stored in a file - // named "-chain.pem". - private static String[] rootsToTest = new String[] { - "entrustevca", "entrustrootcaec1", "entrustrootcag2", "entrustrootcag4", - "entrust2048ca", "affirmtrustcommercialca", "affirmtrustnetworkingca", - "affirmtrustpremiumca", "affirmtrustpremiumeccca" }; - - // A date that is after the restrictions take effect - private static final Date NOVEMBER_1_2024 = - Date.from(LocalDate.of(2024, 11, 1) - .atStartOfDay(ZoneOffset.UTC) - .toInstant()); - - // A date that is a second before the restrictions take effect - private static final Date BEFORE_NOVEMBER_1_2024 = - Date.from(LocalDate.of(2024, 11, 1) - .atStartOfDay(ZoneOffset.UTC) - .minusSeconds(1) - .toInstant()); - - public static void main(String[] args) throws Exception { + private final boolean before; + private final boolean policyOn; + private final boolean isValid; - cf = CertificateFactory.getInstance("X.509"); - - boolean before = args[0].equals("before"); - boolean policyOn = args[1].equals("policyOn"); - boolean isValid = args[2].equals("valid"); + public Distrust(String[] args) { + before = args[0].equals("before"); + policyOn = args[1].equals("policyOn"); + isValid = args[2].equals("valid"); if (!policyOn) { // disable policy (default is on) Security.setProperty("jdk.security.caDistrustPolicies", ""); } + } + + public Date getNotBefore(ZonedDateTime distrustDate) { + ZonedDateTime notBefore = before ? distrustDate.minusSeconds(1) : distrustDate; + return Date.from(notBefore.toInstant()); + } - Date notBefore = before ? BEFORE_NOVEMBER_1_2024 : NOVEMBER_1_2024; + public void testCodeSigningChain(String certPath, String name, Date validationDate) + throws Exception { + System.err.println("Testing " + name + " code-signing chain"); + Validator v = Validator.getInstance(Validator.TYPE_PKIX, + Validator.VAR_CODE_SIGNING, + getParams()); + // set validation date so this will still pass when cert expires + v.setValidationDate(validationDate); + v.validate(loadCertificateChain(certPath, name)); + } - X509TrustManager pkixTM = getTMF("PKIX", null); - X509TrustManager sunX509TM = getTMF("SunX509", null); - for (String test : rootsToTest) { + public void testCertificateChain(String certPath, Date notBefore, X509TrustManager[] tms, + String... tests) throws Exception { + for (String test : tests) { System.err.println("Testing " + test); - X509Certificate[] chain = loadCertificateChain(test); + X509Certificate[] chain = loadCertificateChain(certPath, test); - testTM(sunX509TM, chain, notBefore, isValid); - testTM(pkixTM, chain, notBefore, isValid); + for (X509TrustManager tm : tms) { + testTM(tm, chain, notBefore, isValid); + } } } - private static X509TrustManager getTMF(String type, - PKIXBuilderParameters params) throws Exception { + public X509TrustManager getTMF(String type, PKIXBuilderParameters params) throws Exception { TrustManagerFactory tmf = TrustManagerFactory.getInstance(type); if (params == null) { - tmf.init((KeyStore)null); + tmf.init((KeyStore) null); } else { tmf.init(new CertPathTrustManagerParameters(params)); } TrustManager[] tms = tmf.getTrustManagers(); for (TrustManager tm : tms) { - X509TrustManager xtm = (X509TrustManager)tm; - return xtm; + return (X509TrustManager) tm; } - throw new Exception("No TrustManager for " + type); + throw new RuntimeException("No TrustManager for " + type); } - private static PKIXBuilderParameters getParams() throws Exception { + public PKIXBuilderParameters getParams() throws Exception { PKIXBuilderParameters pbp = - new PKIXBuilderParameters(SecurityUtils.getCacertsKeyStore(), - new X509CertSelector()); + new PKIXBuilderParameters(SecurityUtils.getCacertsKeyStore(), + new X509CertSelector()); pbp.setRevocationEnabled(false); return pbp; } - private static void testTM(X509TrustManager xtm, X509Certificate[] chain, - Date notBefore, boolean valid) throws Exception { + public void testTM(X509TrustManager xtm, X509Certificate[] chain, + Date notBefore, boolean valid) { // Check if TLS Server certificate (the first element of the chain) // is issued after the specified notBefore date (should be rejected // unless distrust property is false). To do this, we need to @@ -130,67 +115,54 @@ private static void testTM(X509TrustManager xtm, X509Certificate[] chain, // after then. chain[0] = new DistrustedTLSServerCert(chain[0], notBefore); + // Wrap the intermediate and root CA certs in NonExpiringTLSServerCert + // so it will never throw a CertificateExpiredException + for (int i = 1; i < chain.length; i++) { + chain[i] = new NonExpiringTLSServerCert(chain[i]); + } + try { xtm.checkServerTrusted(chain, "ECDHE_RSA"); if (!valid) { - throw new Exception("chain should be invalid"); + throw new RuntimeException("chain should be invalid"); } } catch (CertificateException ce) { - // expired TLS certificates should not be treated as failure - if (expired(ce)) { - System.err.println("Test is N/A, chain is expired"); - return; - } if (valid) { - throw new Exception("Unexpected exception, chain " + - "should be valid", ce); + throw new RuntimeException("Unexpected exception, chain " + + "should be valid", ce); } if (ce instanceof ValidatorException) { - ValidatorException ve = (ValidatorException)ce; + ValidatorException ve = (ValidatorException) ce; if (ve.getErrorType() != ValidatorException.T_UNTRUSTED_CERT) { ce.printStackTrace(System.err); - throw new Exception("Unexpected exception: " + ce); + throw new RuntimeException("Unexpected exception: " + ce); } } else { - throw new Exception("Unexpected exception: " + ce); + throw new RuntimeException(ce); } } } - // check if a cause of exception is an expired cert - private static boolean expired(CertificateException ce) { - if (ce instanceof CertificateExpiredException) { - return true; - } - Throwable t = ce.getCause(); - while (t != null) { - if (t instanceof CertificateExpiredException) { - return true; - } - t = t.getCause(); - } - return false; - } - - private static X509Certificate[] loadCertificateChain(String name) + private X509Certificate[] loadCertificateChain(String certPath, String name) throws Exception { - try (InputStream in = new FileInputStream(TEST_SRC + File.separator + - name + "-chain.pem")) { + if (cf == null) { + cf = CertificateFactory.getInstance("X.509"); + } + try (InputStream in = new FileInputStream(TEST_SRC + File.separator + certPath + + File.separator + name + "-chain.pem")) { Collection certs = - (Collection)cf.generateCertificates(in); + (Collection) cf.generateCertificates(in); return certs.toArray(new X509Certificate[0]); } } - private static class DistrustedTLSServerCert extends X509Certificate { + private static class NonExpiringTLSServerCert extends X509Certificate { private final X509Certificate cert; - private final Date notBefore; - DistrustedTLSServerCert(X509Certificate cert, Date notBefore) { + NonExpiringTLSServerCert(X509Certificate cert) { this.cert = cert; - this.notBefore = notBefore; } public Set getCriticalExtensionOIDs() { - return cert.getCriticalExtensionOIDs(); + return cert.getCriticalExtensionOIDs(); } public byte[] getExtensionValue(String oid) { return cert.getExtensionValue(oid); @@ -201,19 +173,17 @@ public Set getNonCriticalExtensionOIDs() { public boolean hasUnsupportedCriticalExtension() { return cert.hasUnsupportedCriticalExtension(); } - public void checkValidity() throws CertificateExpiredException, - CertificateNotYetValidException { + public void checkValidity() { // always pass } - public void checkValidity(Date date) throws CertificateExpiredException, - CertificateNotYetValidException { + public void checkValidity(Date date) { // always pass } public int getVersion() { return cert.getVersion(); } public BigInteger getSerialNumber() { return cert.getSerialNumber(); } public Principal getIssuerDN() { return cert.getIssuerDN(); } public Principal getSubjectDN() { return cert.getSubjectDN(); } - public Date getNotBefore() { return notBefore; } + public Date getNotBefore() { return cert.getNotBefore(); } public Date getNotAfter() { return cert.getNotAfter(); } public byte[] getTBSCertificate() throws CertificateEncodingException { return cert.getTBSCertificate(); @@ -234,16 +204,25 @@ public byte[] getEncoded() throws CertificateEncodingException { return cert.getEncoded(); } public void verify(PublicKey key) throws CertificateException, - InvalidKeyException, NoSuchAlgorithmException, - NoSuchProviderException, SignatureException { + InvalidKeyException, NoSuchAlgorithmException, + NoSuchProviderException, SignatureException { cert.verify(key); } public void verify(PublicKey key, String sigProvider) throws - CertificateException, InvalidKeyException, NoSuchAlgorithmException, - NoSuchProviderException, SignatureException { + CertificateException, InvalidKeyException, NoSuchAlgorithmException, + NoSuchProviderException, SignatureException { cert.verify(key, sigProvider); } public PublicKey getPublicKey() { return cert.getPublicKey(); } public String toString() { return cert.toString(); } } + + private static class DistrustedTLSServerCert extends NonExpiringTLSServerCert { + private final Date notBefore; + DistrustedTLSServerCert(X509Certificate cert, Date notBefore) { + super(cert); + this.notBefore = notBefore; + } + public Date getNotBefore() { return notBefore; } + } } diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/Entrust.java b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/Entrust.java new file mode 100644 index 00000000000..809674e8f20 --- /dev/null +++ b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/Entrust.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024, 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. + */ + +import java.io.File; +import java.time.*; +import java.util.*; +import javax.net.ssl.*; + +/** + * @test + * @bug 8337664 8341059 + * @summary Check that TLS Server certificates chaining back to distrusted + * Entrust roots are invalid + * @library /test/lib + * @modules java.base/sun.security.validator + * @run main/othervm Entrust after policyOn invalid + * @run main/othervm Entrust after policyOff valid + * @run main/othervm Entrust before policyOn valid + * @run main/othervm Entrust before policyOff valid + */ + +public class Entrust { + + private static final String certPath = "chains" + File.separator + "entrust"; + + // Each of the roots have a test certificate chain stored in a file + // named "-chain.pem". + private static String[] rootsToTest = new String[]{ + "entrustevca", "entrustrootcaec1", "entrustrootcag2", "entrustrootcag4", + "entrust2048ca", "affirmtrustcommercialca", "affirmtrustnetworkingca", + "affirmtrustpremiumca", "affirmtrustpremiumeccca"}; + + // Date when the restrictions take effect + private static final ZonedDateTime DISTRUST_DATE = + LocalDate.of(2024, 11, 12).atStartOfDay(ZoneOffset.UTC); + + public static void main(String[] args) throws Exception { + Distrust distrust = new Distrust(args); + + X509TrustManager[] tms = new X509TrustManager[]{ + distrust.getTMF("PKIX", null), + distrust.getTMF("SunX509", null) + }; + + Date notBefore = distrust.getNotBefore(DISTRUST_DATE); + distrust.testCertificateChain(certPath, notBefore, tms, rootsToTest); + } +} diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/Symantec.java b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/Symantec.java new file mode 100644 index 00000000000..4e099a8de8d --- /dev/null +++ b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/Symantec.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2018, 2024, 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. + */ + +import javax.net.ssl.X509TrustManager; +import java.io.File; +import java.time.*; +import java.util.*; + + +/** + * @test + * @bug 8207258 8216280 + * @summary Check that TLS Server certificates chaining back to distrusted + * Symantec roots are invalid + * @library /test/lib + * @modules java.base/sun.security.validator + * @run main/othervm Symantec after policyOn invalid + * @run main/othervm Symantec after policyOff valid + * @run main/othervm Symantec before policyOn valid + * @run main/othervm Symantec before policyOff valid + */ + +public class Symantec { + + private static final String certPath = "chains" + File.separator + "symantec"; + + // Each of the roots have a test certificate chain stored in a file + // named "-chain.pem". + private static final String[] rootsToTest = new String[]{ + "geotrustprimarycag2", "geotrustprimarycag3", "geotrustuniversalca", + "thawteprimaryrootca", "thawteprimaryrootcag2", "thawteprimaryrootcag3", + "verisignclass3g3ca", "verisignclass3g4ca", "verisignclass3g5ca", + "verisignuniversalrootca" + }; + + // Each of the subCAs with a delayed distrust date have a test certificate + // chain stored in a file named "-chain.pem". + private static String[] subCAsToTest = new String[]{"appleistca8g1"}; + + // Date when the restrictions take effect + private static final ZonedDateTime ROOTS_DISTRUST_DATE = + LocalDate.of(2019, 4, 17).atStartOfDay(ZoneOffset.UTC); + + // Date when the subCA restrictions take effect + private static final ZonedDateTime SUBCA_DISTRUST_DATE = + LocalDate.of(2020, 1, 1).atStartOfDay(ZoneOffset.UTC); + + public static void main(String[] args) throws Exception { + Distrust distrust = new Distrust(args); + X509TrustManager[] tms = new X509TrustManager[]{ + distrust.getTMF("PKIX", null), + distrust.getTMF("SunX509", null) + }; + + // test chains issued through roots + Date notBefore = distrust.getNotBefore(ROOTS_DISTRUST_DATE); + distrust.testCertificateChain(certPath, notBefore, tms, rootsToTest); + + // test chain if params are passed to TrustManager + System.err.println("Testing verisignuniversalrootca with params"); + X509TrustManager[] tmsParams = new X509TrustManager[]{ + distrust.getTMF("PKIX", distrust.getParams()) + }; + distrust.testCertificateChain(certPath, notBefore, tmsParams, + "verisignuniversalrootca"); + + // test code-signing chain (should be valid as restrictions don't apply) + Date validationDate = new Date(1544197375493L); + distrust.testCodeSigningChain(certPath, "verisignclass3g5ca-codesigning", validationDate); + + // test chains issued through subCAs + notBefore = distrust.getNotBefore(SUBCA_DISTRUST_DATE); + distrust.testCertificateChain(certPath, notBefore, tms, subCAsToTest); + } +} diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/affirmtrustcommercialca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/affirmtrustcommercialca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/affirmtrustcommercialca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/affirmtrustcommercialca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/affirmtrustnetworkingca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/affirmtrustnetworkingca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/affirmtrustnetworkingca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/affirmtrustnetworkingca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/affirmtrustpremiumca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/affirmtrustpremiumca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/affirmtrustpremiumca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/affirmtrustpremiumca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/affirmtrustpremiumeccca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/affirmtrustpremiumeccca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/affirmtrustpremiumeccca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/affirmtrustpremiumeccca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/entrust2048ca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/entrust2048ca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/entrust2048ca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/entrust2048ca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/entrustevca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/entrustevca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/entrustevca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/entrustevca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/entrustrootcaec1-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/entrustrootcaec1-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/entrustrootcaec1-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/entrustrootcaec1-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/entrustrootcag2-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/entrustrootcag2-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/entrustrootcag2-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/entrustrootcag2-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/entrustrootcag4-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/entrustrootcag4-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Entrust/entrustrootcag4-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/entrust/entrustrootcag4-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/appleistca8g1-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/appleistca8g1-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/appleistca8g1-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/appleistca8g1-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/geotrustprimarycag2-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/geotrustprimarycag2-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/geotrustprimarycag2-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/geotrustprimarycag2-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/geotrustprimarycag3-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/geotrustprimarycag3-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/geotrustprimarycag3-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/geotrustprimarycag3-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/geotrustuniversalca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/geotrustuniversalca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/geotrustuniversalca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/geotrustuniversalca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/thawteprimaryrootca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/thawteprimaryrootca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/thawteprimaryrootca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/thawteprimaryrootca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/thawteprimaryrootcag2-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/thawteprimaryrootcag2-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/thawteprimaryrootcag2-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/thawteprimaryrootcag2-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/thawteprimaryrootcag3-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/thawteprimaryrootcag3-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/thawteprimaryrootcag3-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/thawteprimaryrootcag3-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/verisignclass3g3ca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/verisignclass3g3ca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/verisignclass3g3ca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/verisignclass3g3ca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/verisignclass3g4ca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/verisignclass3g4ca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/verisignclass3g4ca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/verisignclass3g4ca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/verisignclass3g5ca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/verisignclass3g5ca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/verisignclass3g5ca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/verisignclass3g5ca-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/verisignclass3g5ca-codesigning-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/verisignclass3g5ca-codesigning-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/verisignclass3g5ca-codesigning-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/verisignclass3g5ca-codesigning-chain.pem diff --git a/test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/verisignuniversalrootca-chain.pem b/test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/verisignuniversalrootca-chain.pem similarity index 100% rename from test/jdk/sun/security/ssl/X509TrustManagerImpl/Symantec/verisignuniversalrootca-chain.pem rename to test/jdk/sun/security/ssl/X509TrustManagerImpl/distrust/chains/symantec/verisignuniversalrootca-chain.pem diff --git a/test/jdk/sun/security/tools/jarsigner/RemovedFiles.java b/test/jdk/sun/security/tools/jarsigner/RemovedFiles.java new file mode 100644 index 00000000000..598e25a9a70 --- /dev/null +++ b/test/jdk/sun/security/tools/jarsigner/RemovedFiles.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2024, 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 8309841 + * @summary Jarsigner should print a warning if an entry is removed + * @library /test/lib + */ + +import jdk.test.lib.SecurityTools; +import jdk.test.lib.util.JarUtils; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.jar.Attributes; +import java.util.jar.Manifest; + +public class RemovedFiles { + + private static final String NONEXISTENT_ENTRIES_FOUND + = "This jar contains signed entries for files that do not exist. See the -verbose output for more details."; + + public static void main(String[] args) throws Exception { + JarUtils.createJarFile( + Path.of("a.jar"), + Path.of("."), + Files.writeString(Path.of("a"), "a"), + Files.writeString(Path.of("b"), "b")); + SecurityTools.keytool("-genkeypair -storepass changeit -keystore ks -alias x -dname CN=x -keyalg ed25519"); + SecurityTools.jarsigner("-storepass changeit -keystore ks a.jar x"); + + // All is fine at the beginning. + SecurityTools.jarsigner("-verify a.jar") + .shouldNotContain(NONEXISTENT_ENTRIES_FOUND); + + // Remove an entry after signing. There will be a warning. + JarUtils.deleteEntries(Path.of("a.jar"), "a"); + SecurityTools.jarsigner("-verify a.jar") + .shouldContain(NONEXISTENT_ENTRIES_FOUND); + SecurityTools.jarsigner("-verify -verbose a.jar") + .shouldContain(NONEXISTENT_ENTRIES_FOUND) + .shouldContain("Warning: nonexistent signed entries: [a]"); + + // Remove one more entry. + JarUtils.deleteEntries(Path.of("a.jar"), "b"); + SecurityTools.jarsigner("-verify a.jar") + .shouldContain(NONEXISTENT_ENTRIES_FOUND); + SecurityTools.jarsigner("-verify -verbose a.jar") + .shouldContain(NONEXISTENT_ENTRIES_FOUND) + .shouldContain("Warning: nonexistent signed entries: [a, b]"); + + // Re-sign will not clear the warning. + SecurityTools.jarsigner("-storepass changeit -keystore ks a.jar x"); + SecurityTools.jarsigner("-verify a.jar") + .shouldContain(NONEXISTENT_ENTRIES_FOUND); + + // Unfortunately, if there is a non-file entry in manifest, there will be + // a false alarm. See https://bugs.openjdk.org/browse/JDK-8334261. + var man = new Manifest(); + man.getMainAttributes().putValue("Manifest-Version", "1.0"); + man.getEntries().computeIfAbsent("Hello", _ -> new Attributes()) + .putValue("Foo", "Bar"); + JarUtils.createJarFile(Path.of("b.jar"), + man, + Path.of("."), + Path.of("a")); + SecurityTools.jarsigner("-storepass changeit -keystore ks b.jar x"); + SecurityTools.jarsigner("-verbose -verify b.jar") + .shouldContain("Warning: nonexistent signed entries: [Hello]") + .shouldContain(NONEXISTENT_ENTRIES_FOUND); + + } +} diff --git a/test/jtreg-ext/requires/VMProps.java b/test/jtreg-ext/requires/VMProps.java index 5aa703c5b26..539a1f23208 100644 --- a/test/jtreg-ext/requires/VMProps.java +++ b/test/jtreg-ext/requires/VMProps.java @@ -128,8 +128,7 @@ public Map call() { map.put("vm.graal.enabled", this::isGraalEnabled); // jdk.hasLibgraal is true if the libgraal shared library file is present map.put("jdk.hasLibgraal", this::hasLibgraal); - // vm.libgraal.enabled is true if libgraal is used as JIT - map.put("vm.libgraal.enabled", this::isLibgraalEnabled); + map.put("vm.libgraal.jit", this::isLibgraalJIT); map.put("vm.compiler1.enabled", this::isCompiler1Enabled); map.put("vm.compiler2.enabled", this::isCompiler2Enabled); map.put("docker.support", this::dockerSupport); @@ -560,8 +559,8 @@ protected String hasLibgraal() { * * @return true if libgraal is used as JIT compiler. */ - protected String isLibgraalEnabled() { - return "" + Compiler.isLibgraalEnabled(); + protected String isLibgraalJIT() { + return "" + Compiler.isLibgraalJIT(); } /** diff --git a/test/langtools/jdk/javadoc/tool/subpackageNoModules/SubpackageNoModules.java b/test/langtools/jdk/javadoc/tool/subpackageNoModules/SubpackageNoModules.java new file mode 100644 index 00000000000..164ec1f19e4 --- /dev/null +++ b/test/langtools/jdk/javadoc/tool/subpackageNoModules/SubpackageNoModules.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024, 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 8325090 + * @summary javadoc fails when -subpackages option is used with non-modular -source + * @modules jdk.javadoc/jdk.javadoc.internal.api + * jdk.javadoc/jdk.javadoc.internal.tool + * @library /tools/lib + * @build toolbox.TestRunner toolbox.ToolBox + * @run main SubpackageNoModules + */ + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import toolbox.*; +import toolbox.Task.Expect; + +public class SubpackageNoModules extends TestRunner { + + final ToolBox tb = new ToolBox(); + + public SubpackageNoModules() { + super(System.err); + } + + public static void main(String[] args) throws Exception { + SubpackageNoModules t = new SubpackageNoModules(); + t.runTests(m -> new Object[] { Paths.get(m.getName()) }); + } + + @Test + public void testSubpackageNoModules(Path base) throws Exception { + Files.createDirectories(base); + tb.writeFile(base.resolve("pkg/A.java"), "package pkg;\npublic class A {}\n"); + + Path outDir = base.resolve("out"); + Files.createDirectory(outDir); + // Combine -subpackages option with -source release that doesn't support modules + new JavadocTask(tb) + .outdir(outDir) + .sourcepath(base) + .options("-source", "8", + "-subpackages", "pkg") + .run(Expect.SUCCESS); + // Check for presence of generated docs + if (!Files.isRegularFile(outDir.resolve("pkg/A.html"))) { + error("File not found: " + outDir.resolve("pkg/A.html")); + } + } +} diff --git a/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java b/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java index acd91eac8c7..904e4e78cad 100644 --- a/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java +++ b/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java @@ -41,6 +41,8 @@ import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Method; import java.util.ArrayList; @@ -93,13 +95,15 @@ public class BasicAnnoTests extends JavacTestingAbstractProcessor { private static final Map> nameToAnnotation = Map.ofEntries(new NameToAnnotationEntry("java.lang.Override", Override.class), new NameToAnnotationEntry("java.lang.annotation.Repeatable", Repeatable.class), + new NameToAnnotationEntry("java.lang.annotation.Retention", Target.class), new NameToAnnotationEntry("java.lang.annotation.Target", Target.class), new NameToAnnotationEntry("BasicAnnoTests.Test", BasicAnnoTests.Test.class), new NameToAnnotationEntry("BasicAnnoTests.Tests",BasicAnnoTests.Tests.class), new NameToAnnotationEntry("BasicAnnoTests.TA", BasicAnnoTests.TA.class), new NameToAnnotationEntry("BasicAnnoTests.TB", BasicAnnoTests.TB.class), new NameToAnnotationEntry("BasicAnnoTests.TC", BasicAnnoTests.TC.class), - new NameToAnnotationEntry("BasicAnnoTests.TCs", BasicAnnoTests.TCs.class)); + new NameToAnnotationEntry("BasicAnnoTests.TCs", BasicAnnoTests.TCs.class), + new NameToAnnotationEntry("BasicAnnoTests.TD", BasicAnnoTests.TD.class)); static class NameToAnnotationEntry extends AbstractMap.SimpleEntry> { public NameToAnnotationEntry(String key, Class entry) { @@ -520,6 +524,12 @@ R scan(Iterable iter, P p) { TC[] value(); } + @Target(ElementType.TYPE_USE) + @Retention(RetentionPolicy.RUNTIME) + public @interface TD { + int value(); + } + // Test cases // TODO: add more cases for arrays @@ -657,6 +667,10 @@ public class Inner6 {} @Test(posn=1, annoType=TA.class, expect="23") public Set<@TA(23) ? super Object> f9; + @Test(posn=0, annoType=TA.class, expect="1") + @Test(posn=0, annoType=TD.class, expect="2") + public @TA(1) @TD(2) int f10; + // Test type use annotations on uses of type variables @Test(posn=6, annoType = TA.class, expect = "25") @Test(posn=6, annoType = TB.class, expect = "26") diff --git a/test/langtools/tools/javac/processing/model/util/types/TestInvalidInputs.java b/test/langtools/tools/javac/processing/model/util/types/TestInvalidInputs.java new file mode 100644 index 00000000000..3cc1e246e41 --- /dev/null +++ b/test/langtools/tools/javac/processing/model/util/types/TestInvalidInputs.java @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2024, 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 8340721 + * @summary Test invalid inputs to javax.lang.model.util.Types methods + * @library /tools/javac/lib + * @modules java.compiler + * @build JavacTestingAbstractProcessor TestInvalidInputs + * @compile -processor TestInvalidInputs -proc:only TestInvalidInputs.java + */ + +import java.util.*; +import javax.annotation.processing.*; +import javax.lang.model.element.*; +import javax.lang.model.type.*; +import javax.lang.model.util.*; + +/** + * Test if exceptions are thrown for invalid arguments as expected. + */ +public class TestInvalidInputs extends JavacTestingAbstractProcessor { + + // Reference types are ArrayType, DeclaredType, ErrorType, NullType, and TypeVariable + + private TypeMirror objectType; // Notable DeclaredType + private TypeMirror stringType; // Another notable DeclaredType + private ArrayType arrayType; + // private ErrorType errorType; // skip for now + private ExecutableType executableType; + private IntersectionType intersectionType; + + private NoType noTypeVoid; + private NoType noTypeNone; + private NoType noTypePackage; + private NoType noTypeModule; + + private NullType nullType; + private PrimitiveType primitiveType; + private UnionType unionType; + private WildcardType wildcardType; + + /** + * Check expected behavior on classes and packages. + */ + public boolean process(Set annotations, + RoundEnvironment roundEnv) { + if (!roundEnv.processingOver()) { + initializeTypes(); + testUnboxedType(); + testGetWildcardType(); + } + return true; + } + + void initializeTypes() { + objectType = elements.getTypeElement("java.lang.Object").asType(); + stringType = elements.getTypeElement("java.lang.String").asType(); + + arrayType = types.getArrayType(objectType); // Object[] + executableType = extractExecutableType(); + intersectionType = extractIntersectionType(); + + noTypeVoid = types.getNoType(TypeKind.VOID); + noTypeNone = types.getNoType(TypeKind.NONE); + noTypePackage = (NoType)(elements.getPackageElement("java.lang").asType()); + noTypeModule = (NoType)(elements.getModuleElement("java.base").asType()); + + nullType = types.getNullType(); + primitiveType = types.getPrimitiveType(TypeKind.DOUBLE); + // unionType; // more work here + wildcardType = types.getWildcardType(objectType, null); + + return; + } + + ExecutableType extractExecutableType() { + var typeElement = elements.getTypeElement("TestInvalidInputs.InvalidInputsHost"); + for (var method : ElementFilter.methodsIn(typeElement.getEnclosedElements())) { + if ("foo7".equals(method.getSimpleName().toString())) { + return (ExecutableType)method.asType(); + } + } + throw new RuntimeException("Expected method not found"); + } + + IntersectionType extractIntersectionType() { + var typeElement = elements.getTypeElement("TestInvalidInputs.InvalidInputsHost"); + for (var method : ElementFilter.methodsIn(typeElement.getEnclosedElements())) { + if ("foo9".equals(method.getSimpleName().toString())) { + return (IntersectionType) ((TypeVariable)method.getReturnType()).getUpperBound(); + } + } + throw new RuntimeException("Expected method not found"); + } + + /* + * Class to host inputs for testing. + */ + class InvalidInputsHost { + // Use a method to get an ExecutableType + public static String foo7(int arg) {return null;} + + // Type variable with intersection type + public static S foo9() {return null;} + } + + /** + * @throws IllegalArgumentException if the given type has no + * unboxing conversion, including for types that are not + * {@linkplain ReferenceType reference types} + */ + void testUnboxedType() { + // Only DeclaredType's for wrapper classes should have unboxing conversions defined. + + // Reference types are ArrayType, DeclaredType, ErrorType, NullType, TypeVariable + // non-reference: ExecutableType, IntersectionType, NoType, PrimitiveType, UnionType, WildcardType + var invalidInputs = List.of(objectType, stringType, arrayType, + executableType, intersectionType, + noTypeVoid, noTypeNone, noTypePackage, noTypeModule, nullType, + primitiveType, /*unionType, */ wildcardType); + + for (TypeMirror tm : invalidInputs) { + try { + PrimitiveType pt = types.unboxedType(tm); + throw new RuntimeException("Should not reach " + tm); + } catch(IllegalArgumentException iae) { + ; // Expected + } + } + return; + } + + /** + * @throws IllegalArgumentException if bounds are not valid, + * including for types that are not {@linkplain ReferenceType + * reference types} + */ + void testGetWildcardType() { + // Reference types are ArrayType, DeclaredType, ErrorType, NullType, TypeVariable + // non-reference: ExecutableType, IntersectionType, NoType, PrimitiveType, UnionType, WildcardType + var invalidInputs = List.of(executableType, intersectionType, + noTypeVoid, noTypeNone, noTypePackage, noTypeModule, nullType, + primitiveType, /*unionType, */ wildcardType); + + for (TypeMirror tm : invalidInputs) { + try { + WildcardType wc1 = types.getWildcardType(tm, null); + throw new RuntimeException("Should not reach " + tm); + } catch(IllegalArgumentException iae) { + ; // Expected + } + + try { + WildcardType wc2 = types.getWildcardType(null, tm); + throw new RuntimeException("Should not reach " + tm); + } catch(IllegalArgumentException iae) { + ; // Expected + } + } + return; + } +} diff --git a/test/lib-test/jdk/test/lib/util/JarUtilsTest.java b/test/lib-test/jdk/test/lib/util/JarUtilsTest.java new file mode 100644 index 00000000000..eb9dced3256 --- /dev/null +++ b/test/lib-test/jdk/test/lib/util/JarUtilsTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024, 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 8309841 + * @summary Unit Test for a common Test API in jdk.test.lib.util.JarUtils + * @library /test/lib + */ + +import jdk.test.lib.Asserts; +import jdk.test.lib.util.JarUtils; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.stream.Collectors; + +public class JarUtilsTest { + public static void main(String[] args) throws Exception { + Files.createDirectory(Path.of("bx")); + JarUtils.createJarFile(Path.of("a.jar"), + Path.of("."), + Files.writeString(Path.of("a"), ""), + Files.writeString(Path.of("b1"), ""), + Files.writeString(Path.of("b2"), ""), + Files.writeString(Path.of("bx/x"), ""), + Files.writeString(Path.of("c"), ""), + Files.writeString(Path.of("e1"), ""), + Files.writeString(Path.of("e2"), "")); + checkContent("a", "b1", "b2", "bx/x", "c", "e1", "e2"); + + JarUtils.deleteEntries(Path.of("a.jar"), "a"); + checkContent("b1", "b2", "bx/x", "c", "e1", "e2"); + + // Note: b* covers everything starting with b, even bx/x + JarUtils.deleteEntries(Path.of("a.jar"), "b*"); + checkContent("c", "e1", "e2"); + + // d* does not match + JarUtils.deleteEntries(Path.of("a.jar"), "d*"); + checkContent("c", "e1", "e2"); + + // multiple patterns + JarUtils.deleteEntries(Path.of("a.jar"), "d*", "e*"); + checkContent("c"); + } + + static void checkContent(String... expected) throws IOException { + try (var jf = new JarFile("a.jar")) { + Asserts.assertEquals(Set.of(expected), + jf.stream().map(JarEntry::getName).collect(Collectors.toSet())); + } + } +} diff --git a/test/lib/jdk/test/lib/util/JarUtils.java b/test/lib/jdk/test/lib/util/JarUtils.java index e1b3ccac19f..3aa4ada5197 100644 --- a/test/lib/jdk/test/lib/util/JarUtils.java +++ b/test/lib/jdk/test/lib/util/JarUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -320,6 +320,57 @@ public static void updateManifest(String src, String dest, Manifest man) updateJar(src, dest, Map.of(JarFile.MANIFEST_NAME, bout.toByteArray())); } + /** + * Remove entries from a ZIP file. + * + * Each entry can be a name or a name ending with "*". + * + * @return number of removed entries + * @throws IOException if there is any I/O error + */ + public static int deleteEntries(Path jarfile, String... patterns) + throws IOException { + Path tmpfile = Files.createTempFile("jar", "jar"); + int count = 0; + + try (OutputStream out = Files.newOutputStream(tmpfile); + JarOutputStream jos = new JarOutputStream(out)) { + try (JarFile jf = new JarFile(jarfile.toString())) { + Enumeration jentries = jf.entries(); + top: while (jentries.hasMoreElements()) { + JarEntry jentry = jentries.nextElement(); + String name = jentry.getName(); + for (String pattern : patterns) { + if (pattern.endsWith("*")) { + if (name.startsWith(pattern.substring( + 0, pattern.length() - 1))) { + // Go directly to next entry. This + // one is not written into `jos` and + // therefore removed. + count++; + continue top; + } + } else { + if (name.equals(pattern)) { + // Same as above + count++; + continue top; + } + } + } + // No pattern matched, file retained + jos.putNextEntry(copyEntry(jentry)); + jf.getInputStream(jentry).transferTo(jos); + } + } + } + + // replace the original JAR file + Files.move(tmpfile, jarfile, StandardCopyOption.REPLACE_EXISTING); + + return count; + } + private static void updateEntry(JarOutputStream jos, String name, Object content) throws IOException { if (content instanceof Boolean) { diff --git a/test/lib/jdk/test/whitebox/code/Compiler.java b/test/lib/jdk/test/whitebox/code/Compiler.java index 2f8447700d5..69d79ab9d71 100644 --- a/test/lib/jdk/test/whitebox/code/Compiler.java +++ b/test/lib/jdk/test/whitebox/code/Compiler.java @@ -91,12 +91,12 @@ public static boolean isGraalEnabled() { /** * Check if libgraal is used as JIT compiler. * - * libraal is enabled if isGraalEnabled is true and: + * libraal JIT is enabled if isGraalEnabled is true and: * - UseJVMCINativeLibrary flag is true * * @return true if libgraal is used as JIT compiler. */ - public static boolean isLibgraalEnabled() { + public static boolean isLibgraalJIT() { if (!isGraalEnabled()) { return false; } diff --git a/test/micro/org/openjdk/bench/javax/crypto/full/AESGCMBench.java b/test/micro/org/openjdk/bench/javax/crypto/full/AESGCMBench.java index e46f50678ef..8355e4aed72 100644 --- a/test/micro/org/openjdk/bench/javax/crypto/full/AESGCMBench.java +++ b/test/micro/org/openjdk/bench/javax/crypto/full/AESGCMBench.java @@ -35,7 +35,7 @@ public class AESGCMBench extends BenchBase { - @Param({"128"}) + @Param({"128", "192", "256"}) int keyLength; public static final int IV_MODULO = 16; diff --git a/test/micro/org/openjdk/bench/javax/crypto/full/BenchBase.java b/test/micro/org/openjdk/bench/javax/crypto/full/BenchBase.java index 0c5df20d9cb..94c8ef30ea5 100644 --- a/test/micro/org/openjdk/bench/javax/crypto/full/BenchBase.java +++ b/test/micro/org/openjdk/bench/javax/crypto/full/BenchBase.java @@ -45,7 +45,7 @@ public abstract class BenchBase extends CryptoBase { int keyLength = 256; // Default data sizes for full tests - @Param({"1024", "1500", "4096", "16384"}) + @Param({"128", "256", "512", "1024", "1500", "4096", "16384"}) int dataSize; static final int IV_BUFFER_SIZE = 36; diff --git a/test/micro/org/openjdk/bench/vm/lang/LockUnlock.java b/test/micro/org/openjdk/bench/vm/lang/LockUnlock.java index 3ed862e8218..39c8569532e 100644 --- a/test/micro/org/openjdk/bench/vm/lang/LockUnlock.java +++ b/test/micro/org/openjdk/bench/vm/lang/LockUnlock.java @@ -309,10 +309,11 @@ private synchronized int fact(int n) { } /** - * With two threads lockObject1 will be contended so should be - * inflated. + * With three threads lockObject1 will be contended so should be + * inflated. Three threads is also needed to ensure a high level + * of code coverage in the locking code. */ - @Threads(2) + @Threads(3) @Benchmark public void testContendedLock() { synchronized (lockObject1) {