src/hotspot/share/memory/operator_new.cpp
author naoto
Tue, 09 Jul 2019 08:05:38 -0700
changeset 55627 9c1885fb2a42
parent 47216 71c04702a3d5
child 58898 4ec9fc2b2f0d
permissions -rw-r--r--
8227127: Era designator not displayed correctly using the COMPAT provider Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38254
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
     1
/*
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
     4
 *
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
     8
 *
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    14
 *
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    18
 *
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    21
 * questions.
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    22
 *
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    23
 */
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    24
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    25
#include "precompiled.hpp"
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    26
#include "utilities/debug.hpp"
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    27
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    28
#include <new>
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    29
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    30
//--------------------------------------------------------------------------------------
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    31
// Non-product code
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    32
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    33
#ifndef PRODUCT
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    34
// The global operator new should never be called since it will usually indicate
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    35
// a memory leak.  Use CHeapObj as the base class of such objects to make it explicit
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    36
// that they're allocated on the C heap.
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    37
// Commented out in product version to avoid conflicts with third-party C++ native code.
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    38
//
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    39
// In C++98/03 the throwing new operators are defined with the following signature:
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    40
//
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    41
// void* operator new(std::size_tsize) throw(std::bad_alloc);
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    42
// void* operator new[](std::size_tsize) throw(std::bad_alloc);
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    43
//
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    44
// while all the other (non-throwing) new and delete operators are defined with an empty
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    45
// throw clause (i.e. "operator delete(void* p) throw()") which means that they do not
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    46
// throw any exceptions (see section 18.4 of the C++ standard).
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    47
//
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    48
// In the new C++11/14 standard, the signature of the throwing new operators was changed
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    49
// by completely omitting the throw clause (which effectively means they could throw any
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    50
// exception) while all the other new/delete operators where changed to have a 'nothrow'
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    51
// clause instead of an empty throw clause.
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    52
//
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    53
// Unfortunately, the support for exception specifications among C++ compilers is still
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    54
// very fragile. While some more strict compilers like AIX xlC or HP aCC reject to
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    55
// override the default throwing new operator with a user operator with an empty throw()
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    56
// clause, the MS Visual C++ compiler warns for every non-empty throw clause like
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    57
// throw(std::bad_alloc) that it will ignore the exception specification. The following
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    58
// operator definitions have been checked to correctly work with all currently supported
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    59
// compilers and they should be upwards compatible with C++11/14. Therefore
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    60
// PLEASE BE CAREFUL if you change the signature of the following operators!
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    61
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    62
static void * zero = (void *) 0;
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    63
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    64
void* operator new(size_t size) /* throw(std::bad_alloc) */ {
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    65
  fatal("Should not call global operator new");
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    66
  return zero;
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    67
}
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    68
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    69
void* operator new [](size_t size) /* throw(std::bad_alloc) */ {
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    70
  fatal("Should not call global operator new[]");
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    71
  return zero;
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    72
}
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    73
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    74
void* operator new(size_t size, const std::nothrow_t&  nothrow_constant) throw() {
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    75
  fatal("Should not call global operator new");
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    76
  return 0;
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    77
}
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    78
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    79
void* operator new [](size_t size, std::nothrow_t&  nothrow_constant) throw() {
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    80
  fatal("Should not call global operator new[]");
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    81
  return 0;
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    82
}
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    83
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    84
void operator delete(void* p) throw() {
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    85
  fatal("Should not call global delete");
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    86
}
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    87
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    88
void operator delete [](void* p) throw() {
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    89
  fatal("Should not call global delete []");
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    90
}
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    91
05e46b580b4e 8149591: Prepare hotspot for GTest
iignatyev
parents:
diff changeset
    92
#endif // Non-product