< prev index next >

src/hotspot/share/gc/z/zMemory.cpp

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2015, 2017, 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. --- 1,7 ---- /* ! * Copyright (c) 2015, 2019, 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.
*** 47,56 **** --- 47,80 ---- // Out of memory return UINTPTR_MAX; } + uintptr_t ZMemoryManager::alloc_from_front_at_most(size_t size, size_t* allocated) { + ZMemory* area = _freelist.first(); + if (area != NULL) { + if (area->size() <= size) { + // Smaller than or equal to requested, remove area + const uintptr_t start = area->start(); + *allocated = area->size(); + _freelist.remove(area); + delete area; + return start; + } else { + // Larger than requested, shrink area + const uintptr_t start = area->start(); + area->shrink_from_front(size); + *allocated = size; + return start; + } + } + + // Out of memory + *allocated = 0; + return UINTPTR_MAX; + } + uintptr_t ZMemoryManager::alloc_from_back(size_t size) { ZListReverseIterator<ZMemory> iter(&_freelist); for (ZMemory* area; iter.next(&area);) { if (area->size() >= size) { if (area->size() == size) {
*** 69,78 **** --- 93,125 ---- // Out of memory return UINTPTR_MAX; } + uintptr_t ZMemoryManager::alloc_from_back_at_most(size_t size, size_t* allocated) { + ZMemory* area = _freelist.last(); + if (area != NULL) { + if (area->size() <= size) { + // Smaller than or equal to requested, remove area + const uintptr_t start = area->start(); + *allocated = area->size(); + _freelist.remove(area); + delete area; + return start; + } else { + // Larger than requested, shrink area + area->shrink_from_back(size); + *allocated = size; + return area->end(); + } + } + + // Out of memory + *allocated = 0; + return UINTPTR_MAX; + } + void ZMemoryManager::free(uintptr_t start, size_t size) { assert(start != UINTPTR_MAX, "Invalid address"); const uintptr_t end = start + size; ZListIterator<ZMemory> iter(&_freelist);
< prev index next >