< prev index next >

src/share/vm/services/mallocSiteTable.cpp

Print this page
rev 9024 : 8218558: NMT stack traces in output should show mt component for virtual memory allocations
Reviewed-by: shade, stuefe, coleenp
   1 /*
   2  * Copyright (c) 2014, 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  *


 141   *bucket_idx = (size_t)index;
 142   *pos_idx = 0;
 143 
 144   // First entry for this hash bucket
 145   if (_table[index] == NULL) {
 146     MallocSiteHashtableEntry* entry = new_entry(key, flags);
 147     // OOM check
 148     if (entry == NULL) return NULL;
 149 
 150     // swap in the head
 151     if (Atomic::cmpxchg_ptr((void*)entry, (volatile void *)&_table[index], NULL) == NULL) {
 152       return entry->data();
 153     }
 154 
 155     delete entry;
 156   }
 157 
 158   MallocSiteHashtableEntry* head = _table[index];
 159   while (head != NULL && (*pos_idx) <= MAX_BUCKET_LENGTH) {
 160     MallocSite* site = head->data();
 161     if (site->flags() == flags && site->equals(key)) {
 162       return head->data();
 163     }
 164 
 165     if (head->next() == NULL && (*pos_idx) < MAX_BUCKET_LENGTH) {
 166       MallocSiteHashtableEntry* entry = new_entry(key, flags);
 167       // OOM check
 168       if (entry == NULL) return NULL;
 169       if (head->atomic_insert(entry)) {
 170         (*pos_idx) ++;
 171         return entry->data();
 172       }
 173       // contended, other thread won
 174       delete entry;
 175     }
 176     head = (MallocSiteHashtableEntry*)head->next();
 177     (*pos_idx) ++;
 178   }
 179   return NULL;
 180 }
 181 


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


 141   *bucket_idx = (size_t)index;
 142   *pos_idx = 0;
 143 
 144   // First entry for this hash bucket
 145   if (_table[index] == NULL) {
 146     MallocSiteHashtableEntry* entry = new_entry(key, flags);
 147     // OOM check
 148     if (entry == NULL) return NULL;
 149 
 150     // swap in the head
 151     if (Atomic::cmpxchg_ptr((void*)entry, (volatile void *)&_table[index], NULL) == NULL) {
 152       return entry->data();
 153     }
 154 
 155     delete entry;
 156   }
 157 
 158   MallocSiteHashtableEntry* head = _table[index];
 159   while (head != NULL && (*pos_idx) <= MAX_BUCKET_LENGTH) {
 160     MallocSite* site = head->data();
 161     if (site->flag() == flags && site->equals(key)) {
 162       return head->data();
 163     }
 164 
 165     if (head->next() == NULL && (*pos_idx) < MAX_BUCKET_LENGTH) {
 166       MallocSiteHashtableEntry* entry = new_entry(key, flags);
 167       // OOM check
 168       if (entry == NULL) return NULL;
 169       if (head->atomic_insert(entry)) {
 170         (*pos_idx) ++;
 171         return entry->data();
 172       }
 173       // contended, other thread won
 174       delete entry;
 175     }
 176     head = (MallocSiteHashtableEntry*)head->next();
 177     (*pos_idx) ++;
 178   }
 179   return NULL;
 180 }
 181 


< prev index next >