
// java -Xcomp -XX:CompileCommand=compileonly,Test*::* -XX:CompileCommand=quiet -XX:+PrintCompilation -XX:-TieredCompilation Test.java

public class Test {

    public static void main(String[] args) throws Exception {
        // Triggers assert(this->held_monitor_count() == this->jni_monitor_count()) failed: held monitor count should be equal to jni: 1 != 0
        test1();
      
        // Triggers assert(current->held_monitor_count() == 0) failed: Should not be possible
        test2();
    }

    static void test1() throws Exception {
        Thread writeThread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 2; ++i) {
                    synchronized (new Object()) {
                        // Trigger OSR compilation
                        for (int j = 0; j < 100_000; ++j) {

                        }
                    }
                }
            }
        });
        writeThread.start();
        writeThread.join();
    }

    static void test2() {
        for (int i = 0; i < 2; ++i) {
            synchronized (new Object()) {
                // Trigger OSR compilation
                for (int j = 0; j < 100_000; ++j) {

                }
            }
        }
    }
}
