# HG changeset patch # User stuefe # Date 1562740488 -7200 # Wed Jul 10 08:34:48 2019 +0200 # Node ID f3b4a18cb6fac322aaf62ebeda510a9edf50f324 # Parent a3c6b22da80181ead9d18bb2f8dab471e6e9ca2d [mq]: nestegg-2 diff -r a3c6b22da801 -r f3b4a18cb6fa src/hotspot/share/utilities/simpleHeap.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hotspot/share/utilities/simpleHeap.cpp Wed Jul 10 08:34:48 2019 +0200 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1998, 2016, 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. + * + */ + +#include "precompiled.hpp" +#include "runtime/os.hpp" +#include "utilities/align.hpp" +#include "utilities/simpleHeap.hpp" +#include "utilities/globalDefinitions.hpp" + + + + +SimpleHeap::SimpleHeap(size_t size) +: _buf(os::malloc(size, mtInternal)) +, _size(size) +, _top(0) +, _free_list(NULL) +{ +} + +SimpleHeap::~SimpleHeap() { + os::free(_buf); +} + +#define ALLOC_ALIGNMENT sizeof(void*) + +void* SimpleHeap::alloc(size_t size) { + size_t payload_size = MAX2(size, sizeof(heap_used_block_t)); + size_t payload_size_aligned = align_up(payload_size, ALLOC_ALIGNMENT); + + + size_t needed = align_up(sizeof(MAX2(sizeof()))) + + if (_size - _top < size) { + + } + return NULL; +} diff -r a3c6b22da801 -r f3b4a18cb6fa src/hotspot/share/utilities/simpleHeap.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/hotspot/share/utilities/simpleHeap.hpp Wed Jul 10 08:34:48 2019 +0200 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, SAP. 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. + * + */ + +#ifndef SHARE_UTILITIES_SIMPLEHEAP_HPP +#define SHARE_UTILITIES_SIMPLEHEAP_HPP + +#include "memory/allocation.hpp" + +// A very simple heap, layed over a preallocated block of memory. + +// It is used during error handling in the error reporting thread, to make it +// independent from broken or simply full C-heap. + +// This heap does not have to be sophisticated. Its free/reuse functionality +// is very rarely used. + +class SimpleHeap : public CHeapObj { + + struct heap_used_block_t { + size_t size; + }; + + struct heap_free_block_t { + size_t size; + heap_free_block_t* next; + }; + + char* const _buf; + const size_t _size; + size_t _top; + heap_free_block_t* _free_list; + + bool is_valid_pointer(void* p) const { + return p >= _buf && p < _buf + _size; + } + +public: + + SimpleHeap(size_t size); + ~SimpleHeap(); + + void* alloc(size_t size); + void* realloc(size_t size); + void free(void* p); + +}; + +#endif // SHARE_UTILITIES_SIMPLEHEAP_HPP