1 /*
   2  * Copyright (c) 1997, 2010, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_MEMORY_UNIVERSE_INLINE_HPP
  26 #define SHARE_VM_MEMORY_UNIVERSE_INLINE_HPP
  27 
  28 #include "memory/universe.hpp"
  29 #include "runtime/atomic.hpp"
  30 
  31 // Check whether an element of a typeArrayOop with the given type must be
  32 // aligned 0 mod 8.  The typeArrayOop itself must be aligned at least this
  33 // strongly.
  34 
  35 inline bool Universe::element_type_should_be_aligned(BasicType type) {
  36   return type == T_DOUBLE || type == T_LONG;
  37 }
  38 
  39 // Check whether an object field (static/non-static) of the given type must be aligned 0 mod 8.
  40 
  41 inline bool Universe::field_type_should_be_aligned(BasicType type) {
  42   return type == T_DOUBLE || type == T_LONG;
  43 }
  44 
  45 
  46 // Helper methods to cache the first user class loader
  47 
  48 inline oop Universe::get_cached_loader() { 
  49   return _primordial_loader_cache;
  50 }
  51 
  52 inline bool Universe::check_or_set_cached_loader(oop loader) {
  53   // System loader is null or cache is already invalidated stop here
  54   if (loader == NULL || (_primordial_loader_cache == (void*) -1)) {
  55     return false;
  56   }
  57 
  58   // atomically set _primordial_loader_cache
  59   void* old = Atomic::cmpxchg_ptr((void *)loader, (void*)&_primordial_loader_cache, (void *)NULL);
  60   if (old != NULL) {
  61     // loader must have already been set, is it the same loader on another thread?
  62     if (loader == old) {
  63       // Yes it's the same loader
  64 #ifdef ASSERT      
  65       tty->print("FOUND SAME IN LDR CACHE was " INTPTR_FORMAT "\n", old);
  66 #endif
  67       return false;
  68     } else if (old != (void*) -1) {
  69       // No, we must have more than 1 user class loader, so shut off the cache
  70       Atomic::store_ptr((void*) -1, (void*)&_primordial_loader_cache);
  71 #ifdef ASSERT      
  72       tty->print("CLEARED LDR CACHE was " INTPTR_FORMAT " curr " INTPTR_FORMAT"\n", old, loader);
  73 #endif
  74       return false;
  75     } else {
  76       // Already cleared
  77       return false;
  78     }
  79   }
  80   
  81   // We won to set the cache
  82 #ifdef ASSERT      
  83   tty->print("SET LDR CACHE to " INTPTR_FORMAT"\n", loader);
  84 #endif
  85   return true;
  86 }
  87 
  88 #endif // SHARE_VM_MEMORY_UNIVERSE_INLINE_HPP
--- EOF ---