< prev index next >

src/share/vm/memory/allocation.cpp

Print this page
rev 7793 : 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
Summary: Relevant fixes in blockOffsetTable.cpp, os_linux.cpp, parCardTableModRefBS.cpp.
   1 /*
   2  * Copyright (c) 1997, 2014, 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  *


 544   _chunk = new (alloc_failmode, len) Chunk(len);
 545 
 546   if (_chunk == NULL) {
 547     _chunk = k;                 // restore the previous value of _chunk
 548     return NULL;
 549   }
 550   if (k) k->set_next(_chunk);   // Append new chunk to end of linked list
 551   else _first = _chunk;
 552   _hwm  = _chunk->bottom();     // Save the cached hwm, max
 553   _max =  _chunk->top();
 554   set_size_in_bytes(size_in_bytes() + len);
 555   void* result = _hwm;
 556   _hwm += x;
 557   return result;
 558 }
 559 
 560 
 561 
 562 // Reallocate storage in Arena.
 563 void *Arena::Arealloc(void* old_ptr, size_t old_size, size_t new_size, AllocFailType alloc_failmode) {
 564   assert(new_size >= 0, "bad size");
 565   if (new_size == 0) return NULL;
 566 #ifdef ASSERT
 567   if (UseMallocOnly) {
 568     // always allocate a new object  (otherwise we'll free this one twice)
 569     char* copy = (char*)Amalloc(new_size, alloc_failmode);
 570     if (copy == NULL) {
 571       return NULL;
 572     }
 573     size_t n = MIN2(old_size, new_size);
 574     if (n > 0) memcpy(copy, old_ptr, n);
 575     Afree(old_ptr,old_size);    // Mostly done to keep stats accurate
 576     return copy;
 577   }
 578 #endif
 579   char *c_old = (char*)old_ptr; // Handy name
 580   // Stupid fast special case
 581   if( new_size <= old_size ) {  // Shrink in-place
 582     if( c_old+old_size == _hwm) // Attempt to free the excess bytes
 583       _hwm = c_old+new_size;    // Adjust hwm
 584     return c_old;


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


 544   _chunk = new (alloc_failmode, len) Chunk(len);
 545 
 546   if (_chunk == NULL) {
 547     _chunk = k;                 // restore the previous value of _chunk
 548     return NULL;
 549   }
 550   if (k) k->set_next(_chunk);   // Append new chunk to end of linked list
 551   else _first = _chunk;
 552   _hwm  = _chunk->bottom();     // Save the cached hwm, max
 553   _max =  _chunk->top();
 554   set_size_in_bytes(size_in_bytes() + len);
 555   void* result = _hwm;
 556   _hwm += x;
 557   return result;
 558 }
 559 
 560 
 561 
 562 // Reallocate storage in Arena.
 563 void *Arena::Arealloc(void* old_ptr, size_t old_size, size_t new_size, AllocFailType alloc_failmode) {

 564   if (new_size == 0) return NULL;
 565 #ifdef ASSERT
 566   if (UseMallocOnly) {
 567     // always allocate a new object  (otherwise we'll free this one twice)
 568     char* copy = (char*)Amalloc(new_size, alloc_failmode);
 569     if (copy == NULL) {
 570       return NULL;
 571     }
 572     size_t n = MIN2(old_size, new_size);
 573     if (n > 0) memcpy(copy, old_ptr, n);
 574     Afree(old_ptr,old_size);    // Mostly done to keep stats accurate
 575     return copy;
 576   }
 577 #endif
 578   char *c_old = (char*)old_ptr; // Handy name
 579   // Stupid fast special case
 580   if( new_size <= old_size ) {  // Shrink in-place
 581     if( c_old+old_size == _hwm) // Attempt to free the excess bytes
 582       _hwm = c_old+new_size;    // Adjust hwm
 583     return c_old;


< prev index next >