< prev index next >

src/share/vm/runtime/jniHandles.cpp

Print this page
rev 8910 : full patch for jfr
   1 /*
   2  * Copyright (c) 1998, 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  *


 396         } else {
 397           // The weakly referenced object is not alive, clear the reference by storing NULL
 398           if (TraceReferenceGC) {
 399             tty->print_cr("Clearing JNI weak reference (" INTPTR_FORMAT ")", root);
 400           }
 401           *root = NULL;
 402         }
 403       }
 404     }
 405     // the next handle block is valid only if current block is full
 406     if (current->_top < block_size_in_oops) {
 407       break;
 408     }
 409   }
 410 
 411   /*
 412    * JVMTI data structures may also contain weak oops.  The iteration of them
 413    * is placed here so that we don't need to add it to each of the collectors.
 414    */
 415   JvmtiExport::weak_oops_do(is_alive, f);

 416 }
 417 
 418 
 419 jobject JNIHandleBlock::allocate_handle(oop obj) {
 420   assert(Universe::heap()->is_in_reserved(obj), "sanity check");
 421   if (_top == 0) {
 422     // This is the first allocation or the initial block got zapped when
 423     // entering a native function. If we have any following blocks they are
 424     // not valid anymore.
 425     for (JNIHandleBlock* current = _next; current != NULL;
 426          current = current->_next) {
 427       assert(current->_last == NULL, "only first block should have _last set");
 428       assert(current->_free_list == NULL,
 429              "only first block should have _free_list set");
 430       current->_top = 0;
 431       if (ZapJNIHandleArea) current->zap();
 432     }
 433     // Clear initial block
 434     _free_list = NULL;
 435     _allocate_before_rebuild = 0;


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


 396         } else {
 397           // The weakly referenced object is not alive, clear the reference by storing NULL
 398           if (TraceReferenceGC) {
 399             tty->print_cr("Clearing JNI weak reference (" INTPTR_FORMAT ")", root);
 400           }
 401           *root = NULL;
 402         }
 403       }
 404     }
 405     // the next handle block is valid only if current block is full
 406     if (current->_top < block_size_in_oops) {
 407       break;
 408     }
 409   }
 410 
 411   /*
 412    * JVMTI data structures may also contain weak oops.  The iteration of them
 413    * is placed here so that we don't need to add it to each of the collectors.
 414    */
 415   JvmtiExport::weak_oops_do(is_alive, f);
 416   TRACE_WEAK_OOPS_DO(is_alive, f);
 417 }
 418 
 419 
 420 jobject JNIHandleBlock::allocate_handle(oop obj) {
 421   assert(Universe::heap()->is_in_reserved(obj), "sanity check");
 422   if (_top == 0) {
 423     // This is the first allocation or the initial block got zapped when
 424     // entering a native function. If we have any following blocks they are
 425     // not valid anymore.
 426     for (JNIHandleBlock* current = _next; current != NULL;
 427          current = current->_next) {
 428       assert(current->_last == NULL, "only first block should have _last set");
 429       assert(current->_free_list == NULL,
 430              "only first block should have _free_list set");
 431       current->_top = 0;
 432       if (ZapJNIHandleArea) current->zap();
 433     }
 434     // Clear initial block
 435     _free_list = NULL;
 436     _allocate_before_rebuild = 0;


< prev index next >