hotspot/test/native/gc/shared/test_collectedHeap.cpp
changeset 42592 6c1ca562e05a
equal deleted inserted replaced
42591:821346dfd80d 42592:6c1ca562e05a
       
     1 /*
       
     2  * Copyright (c) 2001, 2016, 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 "gc/shared/collectedHeap.hpp"
       
    26 #include "unittest.hpp"
       
    27 
       
    28 TEST_VM(CollectedHeap, is_in) {
       
    29   CollectedHeap* heap = Universe::heap();
       
    30 
       
    31   uintptr_t epsilon = (uintptr_t) MinObjAlignment;
       
    32   uintptr_t heap_start = (uintptr_t) heap->reserved_region().start();
       
    33   uintptr_t heap_end = (uintptr_t) heap->reserved_region().end();
       
    34 
       
    35   // Test that NULL is not in the heap.
       
    36   ASSERT_FALSE(heap->is_in(NULL)) << "NULL is unexpectedly in the heap";
       
    37 
       
    38   // Test that a pointer to before the heap start is reported as outside the heap.
       
    39   ASSERT_GE(heap_start, ((uintptr_t) NULL + epsilon))
       
    40           << "Sanity check - heap should not start at 0";
       
    41 
       
    42   void* before_heap = (void*) (heap_start - epsilon);
       
    43   ASSERT_FALSE(heap->is_in(before_heap)) << "before_heap: " << p2i(before_heap)
       
    44           << " is unexpectedly in the heap";
       
    45 
       
    46   // Test that a pointer to after the heap end is reported as outside the heap.
       
    47   ASSERT_LE(heap_end, ((uintptr_t)-1 - epsilon))
       
    48           << "Sanity check - heap should not end at the end of address space";
       
    49 
       
    50   void* after_heap = (void*) (heap_end + epsilon);
       
    51   ASSERT_FALSE(heap->is_in(after_heap)) << "after_heap: " << p2i(after_heap)
       
    52           << " is unexpectedly in the heap";
       
    53 }