mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-07 17:08:53 +00:00
8289633: Forbid raw C-heap allocation functions in hotspot and fix findings
Reviewed-by: kbarrett, dholmes
This commit is contained in:
parent
df063f7db1
commit
688712f75c
@ -23,6 +23,7 @@
|
||||
// (http://www.iwar.org.uk/comsec/resources/cipher/sha256-384-512.pdf).
|
||||
|
||||
#include "asm/macroAssembler.inline.hpp"
|
||||
#include "runtime/os.hpp" // malloc
|
||||
#include "runtime/stubRoutines.hpp"
|
||||
|
||||
/**********************************************************************
|
||||
@ -402,7 +403,7 @@ void MacroAssembler::sha256(bool multi_block) {
|
||||
#ifdef AIX
|
||||
// malloc provides 16 byte alignment
|
||||
if (((uintptr_t)sha256_round_consts & 0xF) != 0) {
|
||||
uint32_t *new_round_consts = (uint32_t*)malloc(sizeof(sha256_round_table));
|
||||
uint32_t *new_round_consts = (uint32_t*)os::malloc(sizeof(sha256_round_table), mtCompiler);
|
||||
guarantee(new_round_consts, "oom");
|
||||
memcpy(new_round_consts, sha256_round_consts, sizeof(sha256_round_table));
|
||||
sha256_round_consts = (const uint32_t*)new_round_consts;
|
||||
@ -957,7 +958,7 @@ void MacroAssembler::sha512(bool multi_block) {
|
||||
#ifdef AIX
|
||||
// malloc provides 16 byte alignment
|
||||
if (((uintptr_t)sha512_round_consts & 0xF) != 0) {
|
||||
uint64_t *new_round_consts = (uint64_t*)malloc(sizeof(sha512_round_table));
|
||||
uint64_t *new_round_consts = (uint64_t*)os::malloc(sizeof(sha512_round_table), mtCompiler);
|
||||
guarantee(new_round_consts, "oom");
|
||||
memcpy(new_round_consts, sha512_round_consts, sizeof(sha512_round_table));
|
||||
sha512_round_consts = (const uint64_t*)new_round_consts;
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "asm/macroAssembler.inline.hpp"
|
||||
#include "runtime/os.hpp" // malloc
|
||||
#include "runtime/stubRoutines.hpp"
|
||||
#include "runtime/vm_version.hpp"
|
||||
|
||||
@ -89,7 +90,7 @@ address StubRoutines::ppc::generate_crc_constants(juint reverse_poly) {
|
||||
const int vector_size = 16 * (CRC32_UNROLL_FACTOR2 + CRC32_UNROLL_FACTOR / CRC32_UNROLL_FACTOR2);
|
||||
|
||||
const int size = use_vector ? CRC32_TABLE_SIZE + vector_size : (4 BIG_ENDIAN_ONLY(+1)) * CRC32_TABLE_SIZE;
|
||||
const address consts = (address)malloc(size);
|
||||
const address consts = (address)os::malloc(size, mtInternal);
|
||||
if (consts == NULL) {
|
||||
vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CRC constants: no enough space");
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#include "runtime/os.hpp"
|
||||
#include "utilities/decoder_elf.hpp"
|
||||
#include "utilities/elfFile.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
|
||||
#include <cxxabi.h>
|
||||
|
||||
@ -46,7 +47,7 @@ bool ElfDecoder::demangle(const char* symbol, char *buf, int buflen) {
|
||||
if ((result = abi::__cxa_demangle(symbol, NULL, NULL, &status)) != NULL) {
|
||||
jio_snprintf(buf, buflen, "%s", result);
|
||||
// call c library's free
|
||||
::free(result);
|
||||
ALLOW_C_FUNCTION(::free, ::free(result);)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
ZMountPoint::ZMountPoint(const char* filesystem, const char** preferred_mountpoints) {
|
||||
if (AllocateHeapAt != NULL) {
|
||||
// Use specified path
|
||||
_path = strdup(AllocateHeapAt);
|
||||
_path = os::strdup(AllocateHeapAt, mtGC);
|
||||
} else {
|
||||
// Find suitable path
|
||||
_path = find_mountpoint(filesystem, preferred_mountpoints);
|
||||
@ -46,7 +46,7 @@ ZMountPoint::ZMountPoint(const char* filesystem, const char** preferred_mountpoi
|
||||
}
|
||||
|
||||
ZMountPoint::~ZMountPoint() {
|
||||
free(_path);
|
||||
os::free(_path);
|
||||
_path = NULL;
|
||||
}
|
||||
|
||||
@ -61,11 +61,11 @@ char* ZMountPoint::get_mountpoint(const char* line, const char* filesystem) cons
|
||||
strcmp(line_filesystem, filesystem) != 0 ||
|
||||
access(line_mountpoint, R_OK|W_OK|X_OK) != 0) {
|
||||
// Not a matching or accessible filesystem
|
||||
free(line_mountpoint);
|
||||
os::free(line_mountpoint);
|
||||
line_mountpoint = NULL;
|
||||
}
|
||||
|
||||
free(line_filesystem);
|
||||
os::free(line_filesystem);
|
||||
|
||||
return line_mountpoint;
|
||||
}
|
||||
@ -88,14 +88,14 @@ void ZMountPoint::get_mountpoints(const char* filesystem, ZArray<char*>* mountpo
|
||||
}
|
||||
}
|
||||
|
||||
free(line);
|
||||
os::free(line);
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
void ZMountPoint::free_mountpoints(ZArray<char*>* mountpoints) const {
|
||||
ZArrayIterator<char*> iter(mountpoints);
|
||||
for (char* mountpoint; iter.next(&mountpoint);) {
|
||||
free(mountpoint);
|
||||
os::free(mountpoint);
|
||||
}
|
||||
mountpoints->clear();
|
||||
}
|
||||
@ -109,7 +109,7 @@ char* ZMountPoint::find_preferred_mountpoint(const char* filesystem,
|
||||
for (const char** preferred = preferred_mountpoints; *preferred != NULL; preferred++) {
|
||||
if (!strcmp(mountpoint, *preferred)) {
|
||||
// Preferred mount point found
|
||||
return strdup(mountpoint);
|
||||
return os::strdup(mountpoint, mtGC);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -135,7 +135,7 @@ char* ZMountPoint::find_mountpoint(const char* filesystem, const char** preferre
|
||||
log_error_p(gc)("Failed to find an accessible %s filesystem", filesystem);
|
||||
} else if (mountpoints.length() == 1) {
|
||||
// One mount point found
|
||||
path = strdup(mountpoints.at(0));
|
||||
path = os::strdup(mountpoints.at(0), mtGC);
|
||||
} else {
|
||||
// More than one mount point found
|
||||
path = find_preferred_mountpoint(filesystem, &mountpoints, preferred_mountpoints);
|
||||
|
||||
@ -73,6 +73,7 @@
|
||||
#include "utilities/events.hpp"
|
||||
#include "utilities/elfFile.hpp"
|
||||
#include "utilities/growableArray.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
#include "utilities/macros.hpp"
|
||||
#include "utilities/powerOfTwo.hpp"
|
||||
#include "utilities/vmError.hpp"
|
||||
|
||||
@ -785,7 +785,7 @@ char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_path() {
|
||||
|
||||
jio_snprintf(buffer, PATH_MAX, "/proc/%s/exe", _entry->d_name);
|
||||
buffer[PATH_MAX - 1] = '\0';
|
||||
return realpath(buffer, _exePath);
|
||||
return os::Posix::realpath(buffer, _exePath, PATH_MAX);
|
||||
}
|
||||
|
||||
char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
|
||||
|
||||
@ -24,13 +24,16 @@
|
||||
#include "precompiled.hpp"
|
||||
#include "gc/z/zUtils.hpp"
|
||||
#include "utilities/debug.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
uintptr_t ZUtils::alloc_aligned(size_t alignment, size_t size) {
|
||||
void* res = NULL;
|
||||
|
||||
if (posix_memalign(&res, alignment, size) != 0) {
|
||||
// Use raw posix_memalign as long as we have no wrapper for it
|
||||
ALLOW_C_FUNCTION(::posix_memalign, int rc = posix_memalign(&res, alignment, size);)
|
||||
if (rc != 0) {
|
||||
fatal("posix_memalign() failed");
|
||||
}
|
||||
|
||||
|
||||
@ -33,7 +33,6 @@
|
||||
#include "os_posix.inline.hpp"
|
||||
#include "runtime/globals_extension.hpp"
|
||||
#include "runtime/osThread.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
#include "runtime/frame.inline.hpp"
|
||||
#include "runtime/interfaceSupport.inline.hpp"
|
||||
#include "runtime/sharedRuntime.hpp"
|
||||
@ -48,6 +47,7 @@
|
||||
#include "utilities/align.hpp"
|
||||
#include "utilities/events.hpp"
|
||||
#include "utilities/formatBuffer.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
#include "utilities/macros.hpp"
|
||||
#include "utilities/vmError.hpp"
|
||||
|
||||
@ -905,7 +905,7 @@ char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen)
|
||||
// This assumes platform realpath() is implemented according to POSIX.1-2008.
|
||||
// POSIX.1-2008 allows to specify NULL for the output buffer, in which case
|
||||
// output buffer is dynamically allocated and must be ::free()'d by the caller.
|
||||
char* p = ::realpath(filename, NULL);
|
||||
ALLOW_C_FUNCTION(::realpath, char* p = ::realpath(filename, NULL);)
|
||||
if (p != NULL) {
|
||||
if (strlen(p) < outbuflen) {
|
||||
strcpy(outbuf, p);
|
||||
@ -913,7 +913,7 @@ char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen)
|
||||
} else {
|
||||
errno = ENAMETOOLONG;
|
||||
}
|
||||
::free(p); // *not* os::free
|
||||
ALLOW_C_FUNCTION(::free, ::free(p);) // *not* os::free
|
||||
} else {
|
||||
// Fallback for platforms struggling with modern Posix standards (AIX 5.3, 6.1). If realpath
|
||||
// returns EINVAL, this may indicate that realpath is not POSIX.1-2008 compatible and
|
||||
@ -922,7 +922,7 @@ char* os::Posix::realpath(const char* filename, char* outbuf, size_t outbuflen)
|
||||
// a memory overwrite.
|
||||
if (errno == EINVAL) {
|
||||
outbuf[outbuflen - 1] = '\0';
|
||||
p = ::realpath(filename, outbuf);
|
||||
ALLOW_C_FUNCTION(::realpath, p = ::realpath(filename, outbuf);)
|
||||
if (p != NULL) {
|
||||
guarantee(outbuf[outbuflen - 1] == '\0', "realpath buffer overwrite detected.");
|
||||
result = p;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 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
|
||||
@ -29,6 +29,7 @@
|
||||
#include "jfr/metadata/jfrSerializer.hpp"
|
||||
#include "runtime/interfaceSupport.inline.hpp"
|
||||
#include "runtime/javaThread.hpp"
|
||||
#include "runtime/os.hpp" // malloc
|
||||
#include "runtime/semaphore.inline.hpp"
|
||||
#include "utilities/growableArray.hpp"
|
||||
|
||||
@ -101,7 +102,7 @@ int CompilerEvent::PhaseEvent::get_phase_id(const char* phase_name, bool may_exi
|
||||
}
|
||||
|
||||
index = phase_names->length();
|
||||
phase_names->append(use_strdup ? strdup(phase_name) : phase_name);
|
||||
phase_names->append(use_strdup ? os::strdup(phase_name) : phase_name);
|
||||
}
|
||||
if (register_jfr_serializer) {
|
||||
JfrSerializer::register_serializer(TYPE_COMPILERPHASETYPE, false, new CompilerPhaseTypeConstant());
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "gc/shared/gcLogPrecious.hpp"
|
||||
#include "runtime/mutex.hpp"
|
||||
#include "runtime/mutexLocker.hpp"
|
||||
#include "runtime/os.hpp" // malloc
|
||||
#include "utilities/ostream.hpp"
|
||||
|
||||
stringStream* GCLogPrecious::_lines = NULL;
|
||||
@ -67,7 +68,7 @@ void GCLogPrecious::vwrite_and_debug(LogTargetHandle log,
|
||||
{
|
||||
MutexLocker locker(_lock, Mutex::_no_safepoint_check_flag);
|
||||
vwrite_inner(log, format, args);
|
||||
DEBUG_ONLY(debug_message = strdup(_temp->base()));
|
||||
DEBUG_ONLY(debug_message = os::strdup(_temp->base()));
|
||||
}
|
||||
|
||||
// report error outside lock scope, since report_vm_error will call print_on_error
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
#include "memory/universe.hpp"
|
||||
#include "runtime/arguments.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/os.hpp" // malloc
|
||||
#include "utilities/events.hpp"
|
||||
|
||||
JVMCIRuntime* JVMCI::_compiler_runtimes = nullptr;
|
||||
@ -91,7 +92,7 @@ void* JVMCI::get_shared_library(char*& path, bool load) {
|
||||
fatal("Unable to load JVMCI shared library from %s: %s", path, ebuf);
|
||||
}
|
||||
_shared_library_handle = handle;
|
||||
_shared_library_path = strdup(path);
|
||||
_shared_library_path = os::strdup(path);
|
||||
|
||||
JVMCI_event_1("loaded JVMCI shared library from %s", path);
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@
|
||||
#include "prims/methodHandles.hpp"
|
||||
#include "runtime/interfaceSupport.inline.hpp"
|
||||
#include "runtime/jniHandles.inline.hpp"
|
||||
#include "runtime/os.hpp" // malloc
|
||||
#include "runtime/sharedRuntime.hpp"
|
||||
#include "utilities/align.hpp"
|
||||
|
||||
@ -705,7 +706,7 @@ JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
|
||||
if (name == nullptr) {
|
||||
JVMCI_ERROR_OK("stub should have a name");
|
||||
}
|
||||
name = strdup(name);
|
||||
name = os::strdup(name); // Note: this leaks. See JDK-8289632
|
||||
cb = RuntimeStub::new_runtime_stub(name,
|
||||
&buffer,
|
||||
_offsets.value(CodeOffsets::Frame_Complete),
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
#include "logging/logTagSet.hpp"
|
||||
#include "logging/logTagSetDescriptions.hpp"
|
||||
#include "memory/allocation.inline.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
#include "utilities/ostream.hpp"
|
||||
|
||||
LogTagSet* LogTagSet::_list = NULL;
|
||||
@ -150,7 +151,8 @@ void LogTagSet::vwrite(LogLevelType level, const char* fmt, va_list args) {
|
||||
log(level, buf);
|
||||
} else {
|
||||
// Buffer too small, allocate a large enough buffer using malloc/free to avoid circularity.
|
||||
char* newbuf = (char*)::malloc(newbuf_len * sizeof(char));
|
||||
// Since logging is a very basic function, conceivably used within NMT itself, avoid os::malloc/free
|
||||
ALLOW_C_FUNCTION(::malloc, char* newbuf = (char*)::malloc(newbuf_len * sizeof(char));)
|
||||
if (newbuf != nullptr) {
|
||||
prefix_len = _write_prefix(newbuf, newbuf_len);
|
||||
ret = os::vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, saved_args);
|
||||
@ -160,7 +162,7 @@ void LogTagSet::vwrite(LogLevelType level, const char* fmt, va_list args) {
|
||||
if (ret < 0) {
|
||||
log(level, "Log message newbuf issue");
|
||||
}
|
||||
::free(newbuf);
|
||||
ALLOW_C_FUNCTION(::free, ::free(newbuf);)
|
||||
} else {
|
||||
// Native OOM, use buf to output the least message. At this moment buf is full of either
|
||||
// truncated prefix or truncated prefix + string. Put trunc_msg at the end of buf.
|
||||
|
||||
@ -658,7 +658,7 @@ void* os::malloc(size_t size, MEMFLAGS memflags, const NativeCallStack& stack) {
|
||||
|
||||
const size_t outer_size = size + MemTracker::overhead_per_malloc();
|
||||
|
||||
void* const outer_ptr = ::malloc(outer_size);
|
||||
ALLOW_C_FUNCTION(::malloc, void* const outer_ptr = ::malloc(outer_size);)
|
||||
if (outer_ptr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -708,7 +708,7 @@ void* os::realloc(void *memblock, size_t size, MEMFLAGS memflags, const NativeCa
|
||||
// If NMT is enabled, this checks for heap overwrites, then de-accounts the old block.
|
||||
void* const old_outer_ptr = MemTracker::record_free(memblock);
|
||||
|
||||
void* const new_outer_ptr = ::realloc(old_outer_ptr, new_outer_size);
|
||||
ALLOW_C_FUNCTION(::realloc, void* const new_outer_ptr = ::realloc(old_outer_ptr, new_outer_size);)
|
||||
if (new_outer_ptr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -736,7 +736,7 @@ void os::free(void *memblock) {
|
||||
// If NMT is enabled, this checks for heap overwrites, then de-accounts the old block.
|
||||
void* const old_outer_ptr = MemTracker::record_free(memblock);
|
||||
|
||||
::free(old_outer_ptr);
|
||||
ALLOW_C_FUNCTION(::free, ::free(old_outer_ptr);)
|
||||
}
|
||||
|
||||
void os::init_random(unsigned int initval) {
|
||||
|
||||
@ -33,9 +33,9 @@
|
||||
|
||||
// Obviously we cannot use os::malloc for any dynamic allocation during pre-NMT-init, so we must use
|
||||
// raw malloc; to make this very clear, wrap them.
|
||||
static void* raw_malloc(size_t s) { return ::malloc(s); }
|
||||
static void* raw_realloc(void* old, size_t s) { return ::realloc(old, s); }
|
||||
static void raw_free(void* p) { ::free(p); }
|
||||
static void* raw_malloc(size_t s) { ALLOW_C_FUNCTION(::malloc, return ::malloc(s);) }
|
||||
static void* raw_realloc(void* old, size_t s) { ALLOW_C_FUNCTION(::realloc, return ::realloc(old, s);) }
|
||||
static void raw_free(void* p) { ALLOW_C_FUNCTION(::free, ::free(p);) }
|
||||
|
||||
// We must ensure that the start of the payload area of the nmt lookup table nodes is malloc-aligned
|
||||
static const size_t malloc_alignment = 2 * sizeof(void*); // could we use max_align_t?
|
||||
|
||||
@ -169,6 +169,22 @@ FORBID_C_FUNCTION(char* strtok(char*, const char*), "use strtok_r");
|
||||
FORBID_C_FUNCTION(int vsprintf(char*, const char*, va_list), "use os::vsnprintf");
|
||||
FORBID_C_FUNCTION(int vsnprintf(char*, size_t, const char*, va_list), "use os::vsnprintf");
|
||||
|
||||
// All of the following functions return raw C-heap pointers (sometimes as an option, e.g. realpath or getwd)
|
||||
// or, in case of free(), take raw C-heap pointers. Don't use them unless you are really sure you must.
|
||||
FORBID_C_FUNCTION(void* malloc(size_t size), "use os::malloc");
|
||||
FORBID_C_FUNCTION(void* calloc(size_t nmemb, size_t size), "use os::malloc and zero out manually");
|
||||
FORBID_C_FUNCTION(void free(void *ptr), "use os::free");
|
||||
FORBID_C_FUNCTION(void* realloc(void *ptr, size_t size), "use os::realloc");
|
||||
FORBID_C_FUNCTION(char* strdup(const char *s), "use os::strdup");
|
||||
FORBID_C_FUNCTION(char* strndup(const char *s, size_t n), "don't use");
|
||||
FORBID_C_FUNCTION(int posix_memalign(void **memptr, size_t alignment, size_t size), "don't use");
|
||||
FORBID_C_FUNCTION(void* aligned_alloc(size_t alignment, size_t size), "don't use");
|
||||
FORBID_C_FUNCTION(char* realpath(const char* path, char* resolved_path), "use os::Posix::realpath");
|
||||
FORBID_C_FUNCTION(char* get_current_dir_name(void), "use os::get_current_directory()");
|
||||
FORBID_C_FUNCTION(char* getwd(char *buf), "use os::get_current_directory()");
|
||||
FORBID_C_FUNCTION(wchar_t* wcsdup(const wchar_t *s), "don't use");
|
||||
FORBID_C_FUNCTION(void* reallocf(void *ptr, size_t size), "don't use");
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Constants
|
||||
|
||||
|
||||
@ -40,6 +40,7 @@
|
||||
|
||||
#include "runtime/os.hpp"
|
||||
#include "runtime/thread.inline.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
|
||||
// Default value for -new-thread option: true on AIX because we run into
|
||||
// problems when attempting to initialize the JVM on the primordial thread.
|
||||
@ -193,7 +194,7 @@ static int num_args_to_skip(char* arg) {
|
||||
|
||||
static char** remove_test_runner_arguments(int* argcp, char **argv) {
|
||||
int argc = *argcp;
|
||||
char** new_argv = (char**) malloc(sizeof(char*) * argc);
|
||||
ALLOW_C_FUNCTION(::malloc, char** new_argv = (char**) malloc(sizeof(char*) * argc);)
|
||||
int new_argc = 0;
|
||||
|
||||
int i = 0;
|
||||
@ -289,6 +290,8 @@ static void runUnitTestsInner(int argc, char** argv) {
|
||||
|
||||
int result = RUN_ALL_TESTS();
|
||||
|
||||
ALLOW_C_FUNCTION(::free, ::free(argv);)
|
||||
|
||||
// vm_assert and other_vm tests never reach this point as they either abort, or call
|
||||
// exit() - see TEST_OTHER_VM macro. We will reach here when all same_vm tests have
|
||||
// completed for this run, so we can terminate the VM used for that case.
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "jvm.h"
|
||||
#include "logging/logDecorators.hpp"
|
||||
#include "unittest.hpp"
|
||||
#include "runtime/os.hpp" // malloc
|
||||
|
||||
static LogDecorators::Decorator decorator_array[] = {
|
||||
#define DECORATOR(name, abbr) LogDecorators::name##_decorator,
|
||||
@ -79,10 +80,10 @@ TEST(LogDecorators, from_and_to_name) {
|
||||
EXPECT_EQ(decorator, decorator2);
|
||||
|
||||
// Test case insensitivity
|
||||
char* name_cpy = strdup(name);
|
||||
char* name_cpy = os::strdup(name, mtTest);
|
||||
name_cpy[0] = toupper(name_cpy[0]);
|
||||
decorator2 = LogDecorators::from_string(name_cpy);
|
||||
free(name_cpy);
|
||||
os::free(name_cpy);
|
||||
EXPECT_EQ(decorator, decorator2);
|
||||
}
|
||||
}
|
||||
@ -99,10 +100,10 @@ TEST(LogDecorators, from_and_to_abbr) {
|
||||
ASSERT_EQ(decorator, decorator2);
|
||||
|
||||
// Test case insensitivity
|
||||
char* abbr_cpy = strdup(abbr);
|
||||
char* abbr_cpy = os::strdup(abbr);
|
||||
abbr_cpy[0] = toupper(abbr_cpy[0]);
|
||||
decorator2 = LogDecorators::from_string(abbr_cpy);
|
||||
free(abbr_cpy);
|
||||
os::free(abbr_cpy);
|
||||
EXPECT_EQ(decorator, decorator2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "runtime/os.hpp" // malloc
|
||||
#include "utilities/align.hpp"
|
||||
#include "utilities/bitMap.inline.hpp"
|
||||
#include "utilities/copy.hpp"
|
||||
@ -45,11 +46,11 @@ private:
|
||||
public:
|
||||
BitMapMemory(idx_t bits) :
|
||||
_words(BitMap::calc_size_in_words(bits)),
|
||||
_memory(static_cast<bm_word_t*>(malloc(_words * sizeof(bm_word_t))))
|
||||
_memory(static_cast<bm_word_t*>(os::malloc(_words * sizeof(bm_word_t), mtTest)))
|
||||
{ }
|
||||
|
||||
~BitMapMemory() {
|
||||
free(_memory);
|
||||
os::free(_memory);
|
||||
}
|
||||
|
||||
BitMapView make_view(idx_t bits, bm_word_t value) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
@ -23,6 +23,7 @@
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "runtime/mutex.hpp"
|
||||
#include "runtime/os.hpp" // malloc
|
||||
#include "runtime/semaphore.hpp"
|
||||
#include "runtime/thread.hpp"
|
||||
#include "runtime/vmThread.hpp"
|
||||
@ -42,10 +43,10 @@ struct Pointer : public AllStatic {
|
||||
return (uintx)value;
|
||||
}
|
||||
static void* allocate_node(void* context, size_t size, const Value& value) {
|
||||
return ::malloc(size);
|
||||
return os::malloc(size, mtTest);
|
||||
}
|
||||
static void free_node(void* context, void* memory, const Value& value) {
|
||||
::free(memory);
|
||||
os::free(memory);
|
||||
}
|
||||
};
|
||||
|
||||
@ -60,7 +61,7 @@ struct Allocator {
|
||||
uint cur_index;
|
||||
|
||||
Allocator() : cur_index(0) {
|
||||
elements = (TableElement*)::malloc(nelements * sizeof(TableElement));
|
||||
elements = (TableElement*)os::malloc(nelements * sizeof(TableElement), mtTest);
|
||||
}
|
||||
|
||||
void* allocate_node() {
|
||||
@ -74,7 +75,7 @@ struct Allocator {
|
||||
}
|
||||
|
||||
~Allocator() {
|
||||
::free(elements);
|
||||
os::free(elements);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user