00001 /* Copyright 1996, LongView Technologies L.L.C. $Revision: 1.2 $ */ 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 # include "incls/_precompiled.incl" 00025 # include "incls/_systemAverage.cpp.incl" 00026 00027 char SlidingSystemAverage::buffer[buffer_size]; 00028 unsigned int SlidingSystemAverage::stat[number_of_cases]; 00029 unsigned int SlidingSystemAverage::pos; 00030 00031 void SlidingSystemAverage::reset() { 00032 for (int index = 0; index < buffer_size; index++) { 00033 buffer[index] = nowhere; 00034 } 00035 } 00036 00037 unsigned int* SlidingSystemAverage::update() { 00038 // clear the array; 00039 for (unsigned int index = 0; index < number_of_cases; index++) { 00040 stat[index] = 0; 00041 } 00042 00043 index = pos; 00044 do { 00045 stat[buffer[index]]++; 00046 index = (index + 1) % buffer_size; 00047 } while (index != pos); 00048 return stat; 00049 } 00050 00051 void SlidingSystemAverage::add(char type) { 00052 buffer[pos] = type; 00053 pos = (pos + 1) % buffer_size; 00054 } 00055 00056 // The sweeper task is activated every second (1000 milliseconds). 00057 class SystemAverageTask : public PeriodicTask { 00058 public: 00059 SystemAverageTask() : PeriodicTask(10) { } 00060 00061 void task() { 00062 char type; 00063 if (last_Delta_fp) { 00064 if (theCompiler) { 00065 type = SlidingSystemAverage::in_compiler; 00066 } else if (GCInProgress) { 00067 type = SlidingSystemAverage::in_garbage_collect; 00068 } else if (DeltaProcess::is_idle()) { 00069 type = SlidingSystemAverage::is_idle; 00070 } else { 00071 type = SlidingSystemAverage::in_vm; 00072 } 00073 } else { 00074 // interpreted code / compiled code / runtime routine 00075 frame fr = DeltaProcess::active()->profile_top_frame(); 00076 if (fr.is_interpreted_frame()) { 00077 type = SlidingSystemAverage::in_interpreted_code; 00078 } else if (fr.is_compiled_frame()) { 00079 type = SlidingSystemAverage::in_compiled_code; 00080 } else if (PIC::in_heap(fr.pc())) { 00081 type = SlidingSystemAverage::in_pic_code; 00082 } else if (StubRoutines::contains(fr.pc())) { 00083 type = SlidingSystemAverage::in_stub_code; 00084 } 00085 } 00086 SlidingSystemAverage::add(type); 00087 } 00088 }; 00089 00090 void systemAverage_init() { 00091 SlidingSystemAverage::reset(); 00092 if (UseSlidingSystemAverage) { 00093 (new SystemAverageTask)->enroll(); 00094 } 00095 }