|
| 1 | +/* |
| 2 | + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + * |
| 23 | + */ |
| 24 | +#include "precompiled.hpp" |
| 25 | +#include "asm/macroAssembler.inline.hpp" |
| 26 | +#include "interpreter/interp_masm.hpp" |
| 27 | +#include "mmtkBarrierSet.hpp" |
| 28 | +#include "mmtkBarrierSetAssembler_riscv.hpp" |
| 29 | +#include "mmtkBarrierSetC1.hpp" |
| 30 | +#include "mmtkMutator.hpp" |
| 31 | +#include "runtime/sharedRuntime.hpp" |
| 32 | +#include "utilities/macros.hpp" |
| 33 | +#include "c1/c1_LIRAssembler.hpp" |
| 34 | +#include "c1/c1_MacroAssembler.hpp" |
| 35 | + |
| 36 | +#define __ masm-> |
| 37 | + |
| 38 | +void MMTkBarrierSetAssembler::eden_allocate(MacroAssembler* masm, Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register tmp1, Register tmp2, Label& slow_case, bool is_far) { |
| 39 | + // XXX tmp1 seems to be -1 |
| 40 | + assert_different_registers(obj, tmp2); |
| 41 | + assert_different_registers(obj, var_size_in_bytes); |
| 42 | + assert(tmp2->is_valid(), "need temp reg"); |
| 43 | + |
| 44 | + if (!MMTK_ENABLE_ALLOCATION_FASTPATH) { |
| 45 | + __ j(slow_case); |
| 46 | + } else { |
| 47 | + // printf("generating mmtk allocation fast path\n"); |
| 48 | + // MMTk size check. If the alloc size is larger than the allowed max size for non los, |
| 49 | + // we jump to slow path and allodate with LOS in slowpath. |
| 50 | + // Note that OpenJDK has a slow path check. Search for layout_helper_needs_slow_path and FastAllocateSizeLimit. |
| 51 | + // I tried to set FastAllocateSizeLimit in MMTkHeap::initialize(). But there are still large objects allocated into the |
| 52 | + // default space. |
| 53 | + assert(MMTkMutatorContext::max_non_los_default_alloc_bytes != 0, "max_non_los_default_alloc_bytes hasn't been initialized"); |
| 54 | + size_t max_non_los_bytes = MMTkMutatorContext::max_non_los_default_alloc_bytes; |
| 55 | + size_t extra_header = 0; |
| 56 | + // fastpath, we only use default allocator |
| 57 | + Allocator allocator = AllocatorDefault; |
| 58 | + // We need to figure out which allocator we are using by querying MMTk. |
| 59 | + AllocatorSelector selector = get_allocator_mapping(allocator); |
| 60 | + |
| 61 | + // XXX riscv: disallow markcompact and global alloc bit for now |
| 62 | + assert(selector.tag != TAG_MARK_COMPACT, "mark compact not supported for now"); |
| 63 | + |
| 64 | + if (var_size_in_bytes == noreg) { |
| 65 | + // constant alloc size. If it is larger than max_non_los_bytes, we directly go to slowpath. |
| 66 | + if ((size_t)con_size_in_bytes > max_non_los_bytes - extra_header) { |
| 67 | + __ j(slow_case); |
| 68 | + return; |
| 69 | + } |
| 70 | + } else { |
| 71 | + // var alloc size. We compare with max_non_los_bytes and conditionally jump to slowpath. |
| 72 | + // printf("max_non_los_bytes %lu\n",max_non_los_bytes); |
| 73 | + __ li(t0, max_non_los_bytes - extra_header); |
| 74 | + __ bgeu(var_size_in_bytes, t0, slow_case, is_far); |
| 75 | + } |
| 76 | + |
| 77 | + if (selector.tag == TAG_MALLOC || selector.tag == TAG_LARGE_OBJECT) { |
| 78 | + __ j(slow_case); |
| 79 | + return; |
| 80 | + } |
| 81 | + |
| 82 | + // Calculate offsets of TLAB top and end |
| 83 | + Address cursor, limit; |
| 84 | + MMTkAllocatorOffsets alloc_offsets = get_tlab_top_and_end_offsets(selector); |
| 85 | + |
| 86 | + cursor = Address(xthread, alloc_offsets.tlab_top_offset); |
| 87 | + limit = Address(xthread, alloc_offsets.tlab_end_offset); |
| 88 | + |
| 89 | + // XXX disassembly |
| 90 | + // 0x7fffe85597e0: ld a0,688(s7) |
| 91 | + // 0x7fffe85597e4: add a1,a0,a3 |
| 92 | + // 0x7fffe85597e8: bltu a1,a0,0x7fffe8559878 |
| 93 | + // 0x7fffe85597ec: ld t0,696(s7) |
| 94 | + // 0x7fffe85597f0: bltu t0,a1,0x7fffe8559878 |
| 95 | + // 0x7fffe85597f4: sd a1,688(s7) |
| 96 | + |
| 97 | + // obj = load lab.cursor |
| 98 | + __ ld(obj, cursor); |
| 99 | + // end = obj + size |
| 100 | + Register end = tmp2; |
| 101 | + if (var_size_in_bytes == noreg) { |
| 102 | + __ la(end, Address(obj, con_size_in_bytes)); |
| 103 | + } else { |
| 104 | + __ add(end, obj, var_size_in_bytes); |
| 105 | + } |
| 106 | + // slowpath if end < obj |
| 107 | + __ bltu(end, obj, slow_case, is_far); |
| 108 | + // slowpath if end > lab.limit |
| 109 | + __ ld(t0, limit); |
| 110 | + // XXX debug use, force slow path |
| 111 | + // __ bgtu(end, zr, slow_case, is_far); |
| 112 | + __ bgtu(end, t0, slow_case, is_far); |
| 113 | + // lab.cursor = end |
| 114 | + __ sd(end, cursor); |
| 115 | + |
| 116 | + // recover var_size_in_bytes if necessary |
| 117 | + if (var_size_in_bytes == end) { |
| 118 | + __ sub(var_size_in_bytes, var_size_in_bytes, obj); |
| 119 | + } |
| 120 | + // if the above is removed, and the register holding the object size is |
| 121 | + // clobbered, operations that rely on the size, such as array copy will |
| 122 | + // crash |
| 123 | + |
| 124 | + // XXX debug use, force segfault to disassemble in gdb |
| 125 | + // __ ld(t0, zr); |
| 126 | + |
| 127 | + // XXX debug use, force double allocation |
| 128 | + // __ j(slow_case); |
| 129 | + |
| 130 | + #ifdef MMTK_ENABLE_GLOBAL_ALLOC_BIT |
| 131 | + assert(false, "global alloc bit not supported"); |
| 132 | + #endif |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +#undef __ |
| 137 | + |
| 138 | +#define __ sasm-> |
| 139 | + |
| 140 | +void MMTkBarrierSetAssembler::generate_c1_write_barrier_runtime_stub(StubAssembler* sasm) const { |
| 141 | + // assert(false, "Not implemented"); |
| 142 | +} |
| 143 | + |
| 144 | +#undef __ |
| 145 | + |
| 146 | +#define __ ce->masm()-> |
| 147 | + |
| 148 | +void MMTkBarrierSetAssembler::generate_c1_write_barrier_stub_call(LIR_Assembler* ce, MMTkC1BarrierStub* stub) { |
| 149 | +// assert(false, "Not implemented"); |
| 150 | +} |
| 151 | + |
| 152 | +#undef __ |
0 commit comments