< prev index next >

src/hotspot/share/memory/allocation.cpp

Print this page
rev 53414 : imported patch 8217330-split-collectionsetchooser
   1 /*
   2  * Copyright (c) 1997, 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  *


 152 void ResourceObj::operator delete(void* p) {
 153   assert(((ResourceObj *)p)->allocated_on_C_heap(),
 154          "delete only allowed for C_HEAP objects");
 155   DEBUG_ONLY(((ResourceObj *)p)->_allocation_t[0] = (uintptr_t)badHeapOopVal;)
 156   FreeHeap(p);
 157 }
 158 
 159 void ResourceObj::operator delete [](void* p) {
 160   operator delete(p);
 161 }
 162 
 163 #ifdef ASSERT
 164 void ResourceObj::set_allocation_type(address res, allocation_type type) {
 165   // Set allocation type in the resource object
 166   uintptr_t allocation = (uintptr_t)res;
 167   assert((allocation & allocation_mask) == 0, "address should be aligned to 4 bytes at least: " INTPTR_FORMAT, p2i(res));
 168   assert(type <= allocation_mask, "incorrect allocation type");
 169   ResourceObj* resobj = (ResourceObj *)res;
 170   resobj->_allocation_t[0] = ~(allocation + type);
 171   if (type != STACK_OR_EMBEDDED) {
 172     // Called from operator new() and CollectionSetChooser(),
 173     // set verification value.
 174     resobj->_allocation_t[1] = (uintptr_t)&(resobj->_allocation_t[1]) + type;
 175   }
 176 }
 177 
 178 ResourceObj::allocation_type ResourceObj::get_allocation_type() const {
 179   assert(~(_allocation_t[0] | allocation_mask) == (uintptr_t)this, "lost resource object");
 180   return (allocation_type)((~_allocation_t[0]) & allocation_mask);
 181 }
 182 
 183 bool ResourceObj::is_type_set() const {
 184   allocation_type type = (allocation_type)(_allocation_t[1] & allocation_mask);
 185   return get_allocation_type()  == type &&
 186          (_allocation_t[1] - type) == (uintptr_t)(&_allocation_t[1]);
 187 }
 188 
 189 // This whole business of passing information from ResourceObj::operator new
 190 // to the ResourceObj constructor via fields in the "object" is technically UB.
 191 // But it seems to work within the limitations of HotSpot usage (such as no
 192 // multiple inheritance) with the compilers and compiler options we're using.
 193 // And it gives some possibly useful checking for misuse of ResourceObj.


   1 /*
   2  * Copyright (c) 1997, 2019, 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  *


 152 void ResourceObj::operator delete(void* p) {
 153   assert(((ResourceObj *)p)->allocated_on_C_heap(),
 154          "delete only allowed for C_HEAP objects");
 155   DEBUG_ONLY(((ResourceObj *)p)->_allocation_t[0] = (uintptr_t)badHeapOopVal;)
 156   FreeHeap(p);
 157 }
 158 
 159 void ResourceObj::operator delete [](void* p) {
 160   operator delete(p);
 161 }
 162 
 163 #ifdef ASSERT
 164 void ResourceObj::set_allocation_type(address res, allocation_type type) {
 165   // Set allocation type in the resource object
 166   uintptr_t allocation = (uintptr_t)res;
 167   assert((allocation & allocation_mask) == 0, "address should be aligned to 4 bytes at least: " INTPTR_FORMAT, p2i(res));
 168   assert(type <= allocation_mask, "incorrect allocation type");
 169   ResourceObj* resobj = (ResourceObj *)res;
 170   resobj->_allocation_t[0] = ~(allocation + type);
 171   if (type != STACK_OR_EMBEDDED) {
 172     // Called from operator new(), set verification value.

 173     resobj->_allocation_t[1] = (uintptr_t)&(resobj->_allocation_t[1]) + type;
 174   }
 175 }
 176 
 177 ResourceObj::allocation_type ResourceObj::get_allocation_type() const {
 178   assert(~(_allocation_t[0] | allocation_mask) == (uintptr_t)this, "lost resource object");
 179   return (allocation_type)((~_allocation_t[0]) & allocation_mask);
 180 }
 181 
 182 bool ResourceObj::is_type_set() const {
 183   allocation_type type = (allocation_type)(_allocation_t[1] & allocation_mask);
 184   return get_allocation_type()  == type &&
 185          (_allocation_t[1] - type) == (uintptr_t)(&_allocation_t[1]);
 186 }
 187 
 188 // This whole business of passing information from ResourceObj::operator new
 189 // to the ResourceObj constructor via fields in the "object" is technically UB.
 190 // But it seems to work within the limitations of HotSpot usage (such as no
 191 // multiple inheritance) with the compilers and compiler options we're using.
 192 // And it gives some possibly useful checking for misuse of ResourceObj.


< prev index next >