1 /*
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
389
390 // Handle safepoint operations, pending suspend requests,
391 // and pending asynchronous exceptions.
392 if (SafepointSynchronize::do_call_back() ||
393 thread->has_special_condition_for_native_trans()) {
394 JavaThread::check_special_condition_for_native_trans(thread);
395 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops());
396 }
397
398 // Finally we can change the thread state to _thread_in_Java.
399 thread->set_thread_state(_thread_in_Java);
400 fixup_after_potential_safepoint();
401
402 // Clear the frame anchor
403 thread->reset_last_Java_frame();
404
405 // If the result was an oop then unbox it and store it in
406 // oop_temp where the garbage collector can see it before
407 // we release the handle it might be protected by.
408 if (handler->result_type() == &ffi_type_pointer) {
409 if (result[0] == 0) {
410 istate->set_oop_temp(NULL);
411 } else {
412 jobject handle = reinterpret_cast<jobject>(result[0]);
413 istate->set_oop_temp(JNIHandles::resolve(handle));
414 }
415 }
416
417 // Reset handle block
418 thread->active_handles()->clear();
419
420 unlock_unwind_and_return:
421
422 // Unlock if necessary
423 if (monitor) {
424 BasicLock *lock = monitor->lock();
425 markOop header = lock->displaced_header();
426 oop rcvr = monitor->obj();
427 monitor->set_obj(NULL);
428
429 if (header != NULL) {
430 if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {
431 monitor->set_obj(rcvr); {
432 HandleMark hm(thread);
433 CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor));
434 }
|
1 /*
2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
389
390 // Handle safepoint operations, pending suspend requests,
391 // and pending asynchronous exceptions.
392 if (SafepointSynchronize::do_call_back() ||
393 thread->has_special_condition_for_native_trans()) {
394 JavaThread::check_special_condition_for_native_trans(thread);
395 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops());
396 }
397
398 // Finally we can change the thread state to _thread_in_Java.
399 thread->set_thread_state(_thread_in_Java);
400 fixup_after_potential_safepoint();
401
402 // Clear the frame anchor
403 thread->reset_last_Java_frame();
404
405 // If the result was an oop then unbox it and store it in
406 // oop_temp where the garbage collector can see it before
407 // we release the handle it might be protected by.
408 if (handler->result_type() == &ffi_type_pointer) {
409 if (result[0])
410 istate->set_oop_temp(*(oop *) result[0]);
411 else
412 istate->set_oop_temp(NULL);
413 }
414
415 // Reset handle block
416 thread->active_handles()->clear();
417
418 unlock_unwind_and_return:
419
420 // Unlock if necessary
421 if (monitor) {
422 BasicLock *lock = monitor->lock();
423 markOop header = lock->displaced_header();
424 oop rcvr = monitor->obj();
425 monitor->set_obj(NULL);
426
427 if (header != NULL) {
428 if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {
429 monitor->set_obj(rcvr); {
430 HandleMark hm(thread);
431 CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor));
432 }
|