Beispiel #1
0
void
site_update_stats(SiteIndex index, jint size, jint hits)
{
    SiteInfo *info;
    
    table_lock_enter(gdata->site_table); {
	info = get_info(index);
	
	info->n_live_instances          += hits;
	info->n_live_bytes              += size;
	info->changed                   = 1;
	
	gdata->total_live_bytes         += size;
	gdata->total_live_instances     += hits;
	 
	if ( size > 0 ) {
	    info->n_alloced_instances   += hits;
	    info->n_alloced_bytes       += size;
	    gdata->total_alloced_bytes = 
		jlong_add(gdata->total_alloced_bytes, jint_to_jlong(size));
	    gdata->total_alloced_instances = 
		jlong_add(gdata->total_alloced_instances, jint_to_jlong(hits));
	}
    } table_lock_exit(gdata->site_table);
}
void hprof_gc_finish_event(JNIEnv *env_id, jlong used_objects,
			   jlong used_object_space, jlong total_object_space)
{
    jlong gc_time;
    hprof_thread_local_t *info;

    if (cpu_timing) { /* for subtracting GC time from method time */
        info = (hprof_thread_local_t *)(CALL(GetThreadLocalStorage)(env_id));
    
	if (info == NULL) {
	    fprintf(stderr, "HPROF ERROR: gc_end on an unknown thread %p\n",
		    env_id);
	    return;
	}

	if (info->gc_start_time == (jlong)-1) {
	    fprintf(stderr, "HPROF ERROR: got gc_end instead of gc_start\n");
	    return;
	}

	gc_time = CVMlongSub(CALL(GetCurrentThreadCpuTime)(),
			     info->gc_start_time);
	
        if ((info->stack_top - info->stack) > 0) {
	    (info->stack_top - 1)->time_in_gc =
		CVMlongAdd((info->stack_top - 1)->time_in_gc, gc_time);
	}
	info->gc_start_time = jint_to_jlong(-1); /* reset gc_start_time */
    }
    
    CALL(RawMonitorExit)(data_access_lock); /* we grabbed this in gc_start */
}
void hprof_gc_start_event(JNIEnv *env_id)
{
    jlong start_time;
    hprof_thread_local_t *info; 

    /* grab the data_access_lock here, because obj_move and obj_free come
     * in single threaded mode and we could run into deadlocks by grabbing
     * the lock in those handlers. */
    CALL(RawMonitorEnter)(data_access_lock);  

    if (cpu_timing) {
        start_time = CALL(GetCurrentThreadCpuTime)();
	info = (hprof_thread_local_t *)(CALL(GetThreadLocalStorage)(env_id));
	if (info == NULL) {
	    fprintf(stderr, "HPROF ERROR: gc_start on an unknown thread %p\n",
		    env_id);
	    return;
	}

	if (CVMlongNe(info->gc_start_time, jint_to_jlong(-1))) {
	    fprintf(stderr, "HPROF ERROR: got gc_start instead of gc_end\n");
	    return;
	}
    
	info->gc_start_time = start_time;
    }
}
static void hprof_bill_frames_cost(hprof_frames_cost_t *fc, JNIEnv *env_id, jmethodID *frames)
{
    jlong self_time = jlong_div(fc->self_time, jint_to_jlong(1000000));/* convert to ms */
    jlong cost = jlong_zero;
    int num_hits = fc->num_hits;
    int bill_it = 0;
            
    if ((timing_format == OLD_PROF_OUTPUT_FORMAT) && (num_hits > 0)) {
        env_id = NULL;                   /* no thread info for old prof */
	cost = jlong_div(fc->total_time, jint_to_jlong(1000000));    /* convert to ms */
	bill_it = 1;
    } else if ((timing_format == NEW_PROF_OUTPUT_FORMAT) &&
	       CVMlongGt(self_time, jlong_zero)) {
        cost = self_time;
	bill_it = 1;
    }
    
    /* if we are billing */
    if (bill_it) {
        int i;
	int n_frames = fc->num_frames;
	hprof_trace_t *trace_tmp = hprof_alloc_tmp_trace(n_frames, env_id);
        hprof_trace_t *result;

	for (i = 0; i < n_frames; i++) {
	    hprof_frame_t *frame = hprof_intern_jvmpi_frame(frames[i],-1);
	    if (frame == NULL) {
	        fprintf(stderr, 
		    "HPROF ERROR: got a NULL frame in bill_frames_cost\n");
		hprof_free(trace_tmp);
		return;
	    } 
	    trace_tmp->frames[i] = frame;
	}
	result = hprof_intern_tmp_trace(trace_tmp);

	/* bill the cost and num_hits and zero out the values in frames_cost
	 * to prevent them from getting billed more than once */
	result->cost = jlong_add(result->cost, cost);
	result->num_hits += num_hits;
	    
	fc->self_time = jlong_zero;
	fc->total_time = jlong_zero;
	fc->num_hits = 0;
    }
}
static hprof_thread_local_t *hprof_alloc_thread_local_info(void)
{
    hprof_thread_local_t *info =
        HPROF_CALLOC(ALLOC_TYPE_THREAD_LOCAL, sizeof(hprof_thread_local_t));
    
    if (cpu_timing) {
        char lockname[128];
	static int lock_serial_number = 0;
	
        info->stack = HPROF_CALLOC(ALLOC_TYPE_METHOD_TIME,
	    sizeof(hprof_method_time_t) * HPROF_STACK_LIMIT);
	info->stack_top = info->stack;
	info->stack_limit = HPROF_STACK_LIMIT;
	sprintf(lockname, "_hprof_thread_local_lock-%d", lock_serial_number++);
	info->table_lock = CALL(RawMonitorCreate)(lockname);
	info->frames_array_limit = HPROF_FRAMES_ARRAY_LIMIT;
	info->frames_array = HPROF_CALLOC(ALLOC_TYPE_JMETHODID,
	    sizeof(jmethodID) * info->frames_array_limit);
	info->cur_frame_index = 0;
	info->table =
	    HPROF_CALLOC(ALLOC_TYPE_HASH_TABLES + ALLOC_HASH_FRAMES_COST,
	        sizeof(hprof_frames_cost_t *) * HPROF_FRAMES_TABLE_SIZE);
#ifdef HASH_STATS
        info->table_hits   = 0;
        info->table_misses = 0;
	info->thread_name  = NULL;
	info->group_name   = NULL;
	info->parent_name  = NULL;
#endif /* HASH_STATS */
	info->gc_start_time = jint_to_jlong(-1);
    }
    
    if (monitor_tracing) {
        info->mon = HPROF_CALLOC(ALLOC_TYPE_CONTENDED_MONITOR,
	    sizeof(hprof_contended_monitor_t));
	info->mon->time = jint_to_jlong(-1);
	info->mon->trace_serial_num = 0;
	info->mon->num_hits = 0;
    }
    
    return info;
}
Beispiel #6
0
/*
 * Find the bit pattern corresponding to a given double float, collapsing NaNs
 */
JNIEXPORT jlong JNICALL
Java_java_lang_Double_doubleToLongBits(JNIEnv *env, jclass unused, jdouble v)
{
    union {
	jlong l;
	double d;
    } u;
    if (JVM_IsNaN((double)v)) {
        u.l = jint_to_jlong(0x7ff80000);
	return jlong_shl(u.l, 32);
    }
    jdouble_to_jlong_bits(&v);
    u.d = (double)v;
    return u.l;
}