Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Truffle] Finish encapsulating JDK-specific classes in platform.
- Loading branch information
1 parent
df75a85
commit b435b4f
Showing
11 changed files
with
171 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ain/java/org/jruby/truffle/platform/openjdk/OpenJDKArrayBlockingQueueLocksConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.platform.openjdk; | ||
|
||
import org.jruby.truffle.core.queue.ArrayBlockingQueueLocksConditions; | ||
import org.jruby.truffle.core.queue.DelegatingBlockingQueue; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.util.concurrent.ArrayBlockingQueue; | ||
import java.util.concurrent.locks.Condition; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
public class OpenJDKArrayBlockingQueueLocksConditions<T> extends DelegatingBlockingQueue<T> implements ArrayBlockingQueueLocksConditions<T> { | ||
|
||
private static final MethodHandle LOCK_FIELD_GETTER = MethodHandleUtils.getPrivateGetter(ArrayBlockingQueue.class, "lock"); | ||
private static final MethodHandle NOT_EMPTY_CONDITION_FIELD_GETTER = MethodHandleUtils.getPrivateGetter(ArrayBlockingQueue.class, "notEmpty"); | ||
private static final MethodHandle NOT_FULL_CONDITION_FIELD_GETTER = MethodHandleUtils.getPrivateGetter(ArrayBlockingQueue.class, "notFull"); | ||
|
||
private final ReentrantLock lock; | ||
private final Condition notEmptyCondition; | ||
private final Condition notFullCondition; | ||
|
||
public OpenJDKArrayBlockingQueueLocksConditions(int capacity) { | ||
super(new ArrayBlockingQueue<T>(capacity)); | ||
|
||
final ArrayBlockingQueue<T> queue = (ArrayBlockingQueue<T>) getQueue(); | ||
|
||
try { | ||
lock = (ReentrantLock) LOCK_FIELD_GETTER.invokeExact(queue); | ||
notEmptyCondition = (Condition) NOT_EMPTY_CONDITION_FIELD_GETTER.invokeExact(queue); | ||
notFullCondition = (Condition) NOT_FULL_CONDITION_FIELD_GETTER.invokeExact(queue); | ||
} catch (Throwable throwable) { | ||
throw new RuntimeException(throwable); | ||
} | ||
} | ||
|
||
@Override | ||
public ReentrantLock getLock() { | ||
return lock; | ||
} | ||
|
||
@Override | ||
public Condition getNotEmptyCondition() { | ||
return notEmptyCondition; | ||
} | ||
|
||
@Override | ||
public Condition getNotFullCondition() { | ||
return notFullCondition; | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...in/java/org/jruby/truffle/platform/openjdk/OpenJDKLinkedBlockingQueueLocksConditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.platform.openjdk; | ||
|
||
import org.jruby.truffle.core.queue.DelegatingBlockingQueue; | ||
import org.jruby.truffle.core.queue.LinkedBlockingQueueLocksConditions; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.locks.Condition; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
public class OpenJDKLinkedBlockingQueueLocksConditions<T> extends DelegatingBlockingQueue<T> implements LinkedBlockingQueueLocksConditions<T> { | ||
|
||
private static final MethodHandle TAKE_LOCK_FIELD_GETTER = MethodHandleUtils.getPrivateGetter(LinkedBlockingQueue.class, "takeLock"); | ||
private static final MethodHandle NOT_EMPTY_CONDITION_FIELD_GETTER = MethodHandleUtils.getPrivateGetter(LinkedBlockingQueue.class, "notEmpty"); | ||
|
||
private final ReentrantLock lock; | ||
private final Condition notEmptyCondition; | ||
|
||
public OpenJDKLinkedBlockingQueueLocksConditions() { | ||
super(new LinkedBlockingQueue<T>()); | ||
|
||
final LinkedBlockingQueue<T> queue = (LinkedBlockingQueue<T>) getQueue(); | ||
|
||
try { | ||
lock = (ReentrantLock) TAKE_LOCK_FIELD_GETTER.invokeExact(queue); | ||
notEmptyCondition = (Condition) NOT_EMPTY_CONDITION_FIELD_GETTER.invokeExact(queue); | ||
} catch (Throwable throwable) { | ||
throw new RuntimeException(throwable); | ||
} | ||
} | ||
|
||
@Override | ||
public ReentrantLock getLock() { | ||
return lock; | ||
} | ||
|
||
@Override | ||
public Condition getNotEmptyCondition() { | ||
return notEmptyCondition; | ||
} | ||
|
||
} |