< prev index next >

test/hotspot/gtest/memory/test_guardedMemory.cpp

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, 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.

@@ -26,10 +26,12 @@
 #include "memory/allocation.inline.hpp"
 #include "memory/guardedMemory.hpp"
 #include "runtime/os.hpp"
 #include "unittest.hpp"
 
+#define GEN_PURPOSE_TAG ((void *) ((uintptr_t)0xf000f000))
+
 static void guarded_memory_test_check(void* p, size_t sz, void* tag) {
   ASSERT_TRUE(p != NULL) << "NULL pointer given to check";
   u_char* c = (u_char*) p;
   GuardedMemory guarded(c);
   EXPECT_EQ(guarded.get_tag(), tag) << "Tag is not the same as supplied";

@@ -58,19 +60,19 @@
 
 // Test the basic characteristics
 TEST(GuardedMemory, basic) {
   u_char* basep =
           (u_char*) os::malloc(GuardedMemory::get_total_size(1), mtInternal);
-  GuardedMemory guarded(basep, 1, (void*) 0xf000f000);
+  GuardedMemory guarded(basep, 1, GEN_PURPOSE_TAG);
 
   EXPECT_EQ(badResourceValue, *basep)
           << "Expected guard in the form of badResourceValue";
 
   u_char* userp = guarded.get_user_ptr();
   EXPECT_EQ(uninitBlockPad, *userp)
           << "Expected uninitialized data in the form of uninitBlockPad";
-  guarded_memory_test_check(userp, 1, (void*) 0xf000f000);
+  guarded_memory_test_check(userp, 1, GEN_PURPOSE_TAG);
 
   void* freep = guarded.release_for_freeing();
   EXPECT_EQ((u_char*) freep, basep) << "Expected the same pointer guard was ";
   EXPECT_EQ(freeBlockPad, *userp) << "Expected user data to be free block padded";
   EXPECT_FALSE(guarded.verify_guards());

@@ -79,11 +81,11 @@
 
 // Test a number of odd sizes
 TEST(GuardedMemory, odd_sizes) {
   u_char* basep =
           (u_char*) os::malloc(GuardedMemory::get_total_size(1), mtInternal);
-  GuardedMemory guarded(basep, 1, (void*) 0xf000f000);
+  GuardedMemory guarded(basep, 1, GEN_PURPOSE_TAG);
 
   size_t sz = 0;
   do {
     void* p = os::malloc(GuardedMemory::get_total_size(sz), mtInternal);
     void* up = guarded.wrap_with_guards(p, sz, (void*) 1);

@@ -100,11 +102,11 @@
 
 // Test buffer overrun into head...
 TEST(GuardedMemory, buffer_overrun_head) {
   u_char* basep =
           (u_char*) os::malloc(GuardedMemory::get_total_size(1), mtInternal);
-  GuardedMemory guarded(basep, 1, (void*) 0xf000f000);
+  GuardedMemory guarded(basep, 1, GEN_PURPOSE_TAG);
 
   guarded.wrap_with_guards(basep, 1);
   *basep = 0;
   EXPECT_FALSE(guarded.verify_guards());
   os::free(basep);

@@ -112,11 +114,11 @@
 
 // Test buffer overrun into tail with a number of odd sizes
 TEST(GuardedMemory, buffer_overrun_tail) {
   u_char* basep =
           (u_char*) os::malloc(GuardedMemory::get_total_size(1), mtInternal);
-  GuardedMemory guarded(basep, 1, (void*) 0xf000f000);
+  GuardedMemory guarded(basep, 1, GEN_PURPOSE_TAG);
 
   size_t sz = 1;
   do {
     void* p = os::malloc(GuardedMemory::get_total_size(sz), mtInternal);
     void* up = guarded.wrap_with_guards(p, sz, (void*) 1);
< prev index next >