< prev index next >

test/hotspot/gtest/utilities/test_align.cpp

Print this page


   1 /*
   2  * Copyright (c) 2017, 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 "utilities/align.hpp"
  26 #include "utilities/formatBuffer.hpp"
  27 #include "utilities/globalDefinitions.hpp"
  28 #include "unittest.hpp"
  29 
  30 #include <limits>
  31 
  32 // A few arbitrarily chosen values to test the align functions on.
  33 static uint64_t values[] = {1, 3, 10, 345, 1023, 1024, 1025, 23909034, INT_MAX, uint64_t(-1) / 2, uint64_t(-1) / 2 + 100, -1 };
  34 
  35 template <typename T>
  36 static T max_alignment() {
  37   T max = std::numeric_limits<T>::max();
  38   return max ^ (max >> 1);
  39 }
  40 
  41 #define log(...) SCOPED_TRACE(err_msg(__VA_ARGS__).buffer())
  42 
  43 template <typename T, typename A>
  44 static void test_alignments() {
  45   log("### Test: %c" SIZE_FORMAT " " UINT64_FORMAT " : %c" SIZE_FORMAT " " UINT64_FORMAT " ###\n",
  46       std::numeric_limits<T>::is_signed ? 's' : 'u', sizeof(T), (uint64_t)std::numeric_limits<T>::max(),
  47       std::numeric_limits<A>::is_signed ? 's' : 'u', sizeof(A), (uint64_t)std::numeric_limits<A>::max());
  48 
  49   // Test all possible alignment values that fit in type A.
  50   for (A alignment = max_alignment<A>(); alignment > 0; alignment >>= 1) {
  51     log("=== Alignment: " UINT64_FORMAT " ===\n", (uint64_t)alignment);
  52 
  53     for (size_t i = 0; i < ARRAY_SIZE(values); i++) {


   1 /*
   2  * Copyright (c) 2017, 2018, 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 "utilities/align.hpp"
  26 #include "utilities/formatBuffer.hpp"
  27 #include "utilities/globalDefinitions.hpp"
  28 #include "unittest.hpp"
  29 
  30 #include <limits>
  31 
  32 // A few arbitrarily chosen values to test the align functions on.
  33 static uint64_t values[] = {1, 3, 10, 345, 1023, 1024, 1025, 23909034, INT_MAX, uint64_t(-1) / 2, uint64_t(-1) / 2 + 100, uint64_t(-1)};
  34 
  35 template <typename T>
  36 static T max_alignment() {
  37   T max = std::numeric_limits<T>::max();
  38   return max ^ (max >> 1);
  39 }
  40 
  41 #define log(...) SCOPED_TRACE(err_msg(__VA_ARGS__).buffer())
  42 
  43 template <typename T, typename A>
  44 static void test_alignments() {
  45   log("### Test: %c" SIZE_FORMAT " " UINT64_FORMAT " : %c" SIZE_FORMAT " " UINT64_FORMAT " ###\n",
  46       std::numeric_limits<T>::is_signed ? 's' : 'u', sizeof(T), (uint64_t)std::numeric_limits<T>::max(),
  47       std::numeric_limits<A>::is_signed ? 's' : 'u', sizeof(A), (uint64_t)std::numeric_limits<A>::max());
  48 
  49   // Test all possible alignment values that fit in type A.
  50   for (A alignment = max_alignment<A>(); alignment > 0; alignment >>= 1) {
  51     log("=== Alignment: " UINT64_FORMAT " ===\n", (uint64_t)alignment);
  52 
  53     for (size_t i = 0; i < ARRAY_SIZE(values); i++) {


< prev index next >