|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, 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 | + |
| 25 | +#include "precompiled.hpp" |
| 26 | +#include "gc/shared/pretouchTask.hpp" |
| 27 | +#include "runtime/atomic.hpp" |
| 28 | +#include "runtime/globals.hpp" |
| 29 | +#include "runtime/os.hpp" |
| 30 | + |
| 31 | +PretouchTask::PretouchTask(const char* task_name, char* start_address, char* end_address, size_t page_size) : |
| 32 | + AbstractGangTask(task_name), |
| 33 | + _cur_addr(start_address), |
| 34 | + _start_addr(start_address), |
| 35 | + _end_addr(end_address), |
| 36 | + _page_size(0) { |
| 37 | +#ifdef LINUX |
| 38 | + _page_size = UseTransparentHugePages ? (size_t)os::vm_page_size(): page_size; |
| 39 | +#else |
| 40 | + _page_size = page_size; |
| 41 | +#endif |
| 42 | +} |
| 43 | + |
| 44 | +size_t PretouchTask::chunk_size() { |
| 45 | + return PreTouchParallelChunkSize; |
| 46 | +} |
| 47 | + |
| 48 | +void PretouchTask::work(uint worker_id) { |
| 49 | + size_t const actual_chunk_size = MAX2(chunk_size(), _page_size); |
| 50 | + |
| 51 | + while (true) { |
| 52 | + char* touch_addr = Atomic::fetch_and_add(&_cur_addr, actual_chunk_size); |
| 53 | + if (touch_addr < _start_addr || touch_addr >= _end_addr) { |
| 54 | + break; |
| 55 | + } |
| 56 | + |
| 57 | + char* end_addr = touch_addr + MIN2(actual_chunk_size, pointer_delta(_end_addr, touch_addr, sizeof(char))); |
| 58 | + |
| 59 | + os::pretouch_memory(touch_addr, end_addr, _page_size); |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +void PretouchTask::pretouch(const char* task_name, char* start_address, char* end_address, |
| 64 | + size_t page_size, WorkGang* pretouch_gang) { |
| 65 | + PretouchTask task(task_name, start_address, end_address, page_size); |
| 66 | + size_t total_bytes = pointer_delta(end_address, start_address, sizeof(char)); |
| 67 | + |
| 68 | + if (pretouch_gang != NULL) { |
| 69 | + size_t num_chunks = MAX2((size_t)1, total_bytes / MAX2(PretouchTask::chunk_size(), page_size)); |
| 70 | + |
| 71 | + uint num_workers = MIN2((uint)num_chunks, pretouch_gang->total_workers()); |
| 72 | + log_debug(gc, heap)("Running %s with %u workers for " SIZE_FORMAT " work units pre-touching " SIZE_FORMAT "B.", |
| 73 | + task.name(), num_workers, num_chunks, total_bytes); |
| 74 | + |
| 75 | + pretouch_gang->run_task(&task, num_workers); |
| 76 | + } else { |
| 77 | + log_debug(gc, heap)("Running %s pre-touching " SIZE_FORMAT "B.", |
| 78 | + task.name(), total_bytes); |
| 79 | + task.work(0); |
| 80 | + } |
| 81 | +} |
| 82 | + |
0 commit comments