<commit_before>/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/** 
 * @author <NAME>
 * @version $Revision: 1.1.2.1.4.4 $
 */  

#define LOG_DOMAIN "enumeration"
#include "cxxlog.h"

#include "platform_lowlevel.h"
#include <assert.h>

//MVM
#include <iostream>

using namespace std;


#include "open/types.h"
#include "open/jthread.h"
#include "object_layout.h"
#include "vm_threads.h"
#include "jit_runtime_support.h"
#include "exceptions.h"
#include "stack_iterator.h"
#include "Class.h"
#include "jit_intf_cpp.h"
#include "cci.h"

#include "mon_enter_exit.h"
#include "thread_generic.h"

#include "object_generic.h"
#include "vm_stats.h"
#include "object_handles.h"

#include "vm_process.h"
//#include "java_mrte.h"
#include "port_atomic.h"

static void vm_monitor_exit_default(ManagedObject *p_obj);
static void vm_monitor_enter_default(ManagedObject *p_obj);
static uint32 vm_monitor_try_enter_default(ManagedObject *p_obj);
static uint32 vm_monitor_try_exit_default(ManagedObject *p_obj);


void (*vm_monitor_enter)(ManagedObject *p_obj) = 0;
void (*vm_monitor_exit)(ManagedObject *p_obj) = 0;
uint32 (*vm_monitor_try_enter)(ManagedObject *p_obj) = 0;
uint32 (*vm_monitor_try_exit)(ManagedObject *p_obj) = 0;


void vm_enumerate_root_set_mon_arrays()
{
}

void vm_monitor_init()
{
    vm_monitor_enter = vm_monitor_enter_default;
    vm_monitor_try_enter = vm_monitor_try_enter_default;
    vm_monitor_exit = vm_monitor_exit_default;
    vm_monitor_try_exit = vm_monitor_try_exit_default;
}

void vm_monitor_exit_synchronized_method(StackIterator *si)
{
    assert(!si_is_native(si));
    CodeChunkInfo *cci = si_get_code_chunk_info(si);
    assert(cci);
    Method *method = cci->get_method();

    if (method->is_synchronized()) {
        bool unwindable = set_unwindable(false);
        if (method->is_static()) {
            assert(!hythread_is_suspend_enabled());
            TRACE2("tm.locks", ("unlock static sync methods...%x",
                struct_Class_to_java_lang_Class(method->get_class())));
            vm_monitor_exit(struct_Class_to_java_lang_Class(method->
                    get_class()));
        }
        else {
            JIT *jit = cci->get_jit();
            void **p_this =
                (void **) jit->get_address_of_this(method,
                si_get_jit_context(si));
            TRACE2("tm.locks", ("unlock sync methods...%x" , *p_this));
            vm_monitor_exit((ManagedObject *) * p_this);
        }
        exn_clear();
        set_unwindable(unwindable);
    }
}

static void vm_monitor_enter_default(ManagedObject *p_obj)
{
    assert(managed_object_is_valid(p_obj));
    //
    assert(!hythread_is_suspend_enabled());
    assert(p_obj);
    jobject jobj = oh_allocate_local_handle();
    jobj->object = p_obj;
    jthread_monitor_enter(jobj); 
}

static void vm_monitor_exit_default(ManagedObject *p_obj)
{
#ifdef _IPF_
    // FIXME: HelloWorld passes on ipf with assert disaibled
    // ASSERT_RAISE_AREA;
#else<commit_msg>HARMONY-3410 [drlvm] Exception shouldn't be thrown from vm_monitor_exit_synchronized_method()<commit_after>/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/** 
 * @author <NAME>
 * @version $Revision: 1.1.2.1.4.4 $
 */  

#define LOG_DOMAIN "enumeration"
#include "cxxlog.h"

#include "platform_lowlevel.h"
#include <assert.h>

//MVM
#include <iostream>

using namespace std;


#include "open/types.h"
#include "open/jthread.h"
#include "object_layout.h"
#include "vm_threads.h"
#include "jit_runtime_support.h"
#include "exceptions.h"
#include "stack_iterator.h"
#include "Class.h"
#include "jit_intf_cpp.h"
#include "cci.h"

#include "mon_enter_exit.h"
#include "thread_generic.h"

#include "object_generic.h"
#include "vm_stats.h"
#include "object_handles.h"

#include "vm_process.h"
//#include "java_mrte.h"
#include "port_atomic.h"

static void vm_monitor_exit_default(ManagedObject *p_obj);
static void vm_monitor_enter_default(ManagedObject *p_obj);
static uint32 vm_monitor_try_enter_default(ManagedObject *p_obj);
static uint32 vm_monitor_try_exit_default(ManagedObject *p_obj);


void (*vm_monitor_enter)(ManagedObject *p_obj) = 0;
void (*vm_monitor_exit)(ManagedObject *p_obj) = 0;
uint32 (*vm_monitor_try_enter)(ManagedObject *p_obj) = 0;
uint32 (*vm_monitor_try_exit)(ManagedObject *p_obj) = 0;


void vm_enumerate_root_set_mon_arrays()
{
}

void vm_monitor_init()
{
    vm_monitor_enter = vm_monitor_enter_default;
    vm_monitor_try_enter = vm_monitor_try_enter_default;
    vm_monitor_exit = vm_monitor_exit_default;
    vm_monitor_try_exit = vm_monitor_try_exit_default;
}

void vm_monitor_exit_synchronized_method(StackIterator *si)
{
    assert(!si_is_native(si));
    CodeChunkInfo *cci = si_get_code_chunk_info(si);
    assert(cci);
    Method *method = cci->get_method();

    assert(!hythread_is_suspend_enabled());
    if (method->is_synchronized()) {
        if (method->is_static()) {
            TRACE2("tm.locks", ("unlock static sync methods...%x",
                struct_Class_to_java_lang_Class(method->get_class())));
            IDATA UNREF status = vm_monitor_try_exit(
                struct_Class_to_java_lang_Class(method->get_class()));
        }
        else {
            JIT *jit = cci->get_jit();
            void **p_this =
                (void **) jit->get_address_of_this(method,
                si_get_jit_context(si));
            TRACE2("tm.locks", ("unlock sync methods...%x" , *p_this));
            IDATA UNREF status = vm_monitor_try_exit((ManagedObject *) * p_this);
        }
    }
}

static void vm_monitor_enter_default(ManagedObject *p_obj)
{
    assert(managed_object_is_valid(p_obj));
    //
    assert(!hythread_is_suspend_enabled());
    assert(p_obj);
    jobject jobj = oh_allocate_local_handle();
    jobj->object = p_obj;
    jthread_monitor_enter(jobj); 
}

static void vm_monitor_exit_default(ManagedObject *p_obj)
{
#ifdef _IPF_
    // FIXME: HelloWorld passes on ipf with assert disaibled
    // ASSERT_RAISE_AREA;
#else
{'fraction_non_alphanumeric': 0.10909575886903174, 'fraction_numerical': 0.006935182715390771, 'mean_word_length': 4.036265950302217, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6612634', 'n_tokens_mistral': 2537, 'n_tokens_neox': 2485, 'n_words': 581}