/**
 * Destroys the thin monitor and releases any associated resources.
 *
 * @param[in] lockword_ptr monitor addr 
 */
IDATA hythread_thin_monitor_destroy(hythread_thin_monitor_t *lockword_ptr) {
    hythread_monitor_t fat_monitor;
    hythread_thin_monitor_t lockword = *lockword_ptr;
    
    if (IS_FAT_LOCK(lockword)) {
        fat_monitor = locktable_delete_entry(FAT_LOCK_ID(lockword));
        assert(fat_monitor);
        return hythread_monitor_destroy(fat_monitor); 
    }
    return TM_ERROR_NONE;
}
void VMCALL hythread_reclaim_resources()
{
    U_32 i = 0;

#ifdef DEBUG_NATIVE_RESOURCE_COLLECTION
    int old_slots_occupied = 0;
    int new_slots_occupied = 0;
    
    for (;i < lock_table->size; i++) {
        if (FAT_LOCK(i))
            old_slots_occupied++;
    }
#endif

    locktable_reader_enter();
    // If major collection didn't happen, do nothing
    // reset the flag (major collection happened)

    if (!live_objs_were_reported) {
        locktable_reader_exit();
        return;
    }    
    locktable_reader_exit();

    locktable_writer_enter();
    live_objs_were_reported = 0;  

    for(i = 0; i < lock_table->size; i++) {
        if (lock_table->live_objs[i]) {
            assert(FAT_LOCK(i));
#ifdef DEBUG_NATIVE_RESOURCE_COLLECTION
            new_slots_occupied++;
#endif

            // reset the live array for the next major GC cycle
            lock_table->live_objs[i] = 0;  
        } else {
            if (FAT_LOCK(i)) {
                hythread_monitor_destroy(FAT_LOCK(i));
                FAT_LOCK(i)  = 0;
            }
        }
    }
    locktable_writer_exit();
#ifdef DEBUG_NATIVE_RESOURCE_COLLECTION
    CTRACE(("hythread_reclaim_resources(): old = %d, new = %d\n", 
           old_slots_occupied,
           new_slots_occupied));
#endif
}
Beispiel #3
0
/**
 * Releases thread structure.
 */
IDATA VMCALL hythread_struct_release(hythread_t thread)
{
    IDATA status;

    assert(thread);

    // Release thread primitives
    status = hysem_destroy(thread->resume_event);
    assert(status == TM_ERROR_NONE);
    status = port_mutex_destroy(&thread->mutex);
    assert(status == TM_ERROR_NONE);
    status = hythread_monitor_destroy(thread->monitor);
    assert(status == TM_ERROR_NONE);

    memset(thread, 0, hythread_get_struct_size());
    return TM_ERROR_NONE;
}
Beispiel #4
0
/**
 * Destroys raw monitor. 
 *
 * @param[in] mon_ptr address where monitor needs to be destroyed.
 */
IDATA VMCALL jthread_raw_monitor_destroy(jrawMonitorID mon_ptr)
{
    hythread_monitor_t monitor =
         (hythread_monitor_t)array_get(jvmti_monitor_table, (UDATA)mon_ptr);
    if (!monitor) {
        return TM_ERROR_INVALID_MONITOR;
    }

    while (hythread_monitor_destroy((hythread_monitor_t)monitor) != TM_ERROR_NONE)
    {
        IDATA status = hythread_monitor_exit((hythread_monitor_t) monitor);
        if (status != TM_ERROR_NONE) {
            return status;
        }
    }

    IDATA status = port_mutex_lock(&jvmti_monitor_table_lock);
    if (status != TM_ERROR_NONE) {
        return status;
    }
    array_delete(jvmti_monitor_table, (UDATA) mon_ptr);
    status = port_mutex_unlock(&jvmti_monitor_table_lock);
    return status;
} // jthread_raw_monitor_destroy