universe_more.cpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.50 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 
00025 # include "incls/_precompiled.incl"
00026 # include "incls/_universe.more.cpp.incl"
00027 
00028 bool GCInProgress = false;
00029 
00030 oop Universe::tenure(oop p) {
00031   tenuring_threshold = 0;               // tenure everything
00032   scavenge(&p);
00033 # define checkIt(s) assert(s->used() == 0, "new spaces should be empty");
00034   APPLY_TO_YOUNG_SPACES(checkIt)
00035 # undef checkIt
00036   return p;
00037 }
00038 
00039 bool Universe::can_scavenge() {
00040   // don't scavenge if we're in critical vm operation
00041   if (processSemaphore) return false;
00042 
00043   if (BlockScavenge::is_blocked()) return false;
00044 
00045   // don't scavenge if we're allocating in the VM process.
00046   if (DeltaProcess::active()->in_vm_operation()) return false;
00047 
00048   return true;
00049 }
00050 
00051 extern "C" void scavenge_and_allocate(int size) {
00052   Universe::scavenge_and_allocate(size, NULL);
00053 }
00054 
00055 oop* Universe::scavenge_and_allocate(int size, oop* p) {
00056   // Fix this:
00057   //  If it is a huge object we are allocating we should
00058   //  allocate it in old_space and return without doing a scavenge  
00059   if (!can_scavenge()) return allocate_tenured(size);
00060 
00061   VM_Scavenge op(p);
00062   VMProcess::execute(&op);
00063   assert(DeltaProcess::active()->last_Delta_fp() != NULL, "last Delta fp should be present");
00064   assert(DeltaProcess::active()->last_Delta_sp() != NULL, "last Delta fp should be present");
00065   return allocate_without_scavenge(size);
00066 }
00067 
00068 void Universe::scavenge_oop(oop* p) { *p = (*p)->scavenge(); }
00069 
00070 bool Universe::needs_garbage_collection() {
00071   return old_gen.free() < new_gen.to()->capacity();
00072 }
00073 
00074 void Universe::scavenge(oop* p) {
00075   // %note
00076   //   the symbol_table can be ignored during scavenge since all
00077   //   all symbols are tenured.
00078   FlagSetting fl(GCInProgress, true);
00079   ResourceMark rm;
00080   scavengeCount++;
00081   assert(!processSemaphore, "processSemaphore shouldn't be set");
00082   {
00083     EventMarker m("scavenging");
00084     TraceTime   t("Scavenge", PrintScavenge);
00085 
00086     if (PrintScavenge && WizardMode) {
00087       std->print(" %d",tenuring_threshold);
00088     }
00089     
00090     if (VerifyBeforeScavenge) verify();
00091 
00092     WeakArrayRegister::begin_scavenge();
00093 
00094     // Getting ready for scavenge
00095     age_table->clear();
00096 
00097     new_gen.to_space->clear();
00098 
00099     // Save top of to_space and old_gen
00100     NewWaterMark to_mark  = new_gen.to_space->top_mark();
00101     OldWaterMark old_mark =           old_gen.top_mark();
00102 
00103     // Scavenge all roots
00104     if (p) SCAVENGE_TEMPLATE(p);
00105 
00106     Universe::roots_do(scavenge_oop);
00107     Handles::oops_do(scavenge_oop);
00108 
00109     {FOR_EACH_OLD_SPACE(s) s->scavenge_recorded_stores();}
00110 
00111     Processes::scavenge_contents();
00112     NotificationQueue::oops_do(&Universe::scavenge_oop);
00113 
00114     // Scavenge promoted contents in to_space and old_gen until done.
00115 
00116     while (   (old_mark != old_gen.top_mark()) 
00117            || (to_mark != new_gen.to_space->top_mark())) {
00118       old_gen.scavenge_contents_from(&old_mark);
00119       new_gen.to_space->scavenge_contents_from(&to_mark);
00120     }
00121 
00122     WeakArrayRegister::check_and_scavenge_contents();
00123 
00124     new_gen.swap_spaces();
00125 
00126     // Set the desired survivor size to half the real survivor space
00127     int desired_survivor_size = new_gen.to()->capacity()/2;
00128     tenuring_threshold = age_table->tenuring_threshold(desired_survivor_size/oopSize);
00129     
00130     if (VerifyAfterScavenge) verify(true);
00131     
00132     // do this at end so an overflow during a scavenge doesnt cause another one
00133     NeedScavenge = false;
00134   }
00135 }
00136 
00137 space* Universe::spaceFor(void* p) {
00138   if (new_gen.from()->contains(p)) return new_gen.from();
00139   if (new_gen.eden()->contains(p)) return new_gen.eden();
00140   {FOR_EACH_OLD_SPACE(s) if (s->contains(p)) return s;}
00141   ShouldNotReachHere(); // not in any space
00142   return NULL;
00143 }

Generated on Mon Oct 9 13:37:29 2006 for Strongtalk VM by  doxygen 1.4.7