public ProfiledMethods( final Ruby runtime ) { if( runtime == null ) throw new IllegalArgumentException( "Given runtime must not be null." ); this.runtime = runtime; // TODO is 10000 a good value ? this.methods = new NonBlockingHashMapLong<>(10000); }
public void clear ( ) { NonBlockingHashMapLong.this.clear ( ); } public int size ( ) { return NonBlockingHashMapLong.this.size ( ); }
public boolean contains( Object k ) { return NonBlockingHashMapLong.this.containsKey(k); } public boolean remove ( Object k ) { return NonBlockingHashMapLong.this.remove (k) != null; }
/** * Internal API * @param signatureCode * @return callable */ public final T getSignature(int signatureCode) { return cache.get(signatureCode); }
/** * Internal API * @param signatureCode * @param callable */ public final void putSignature(int signatureCode, T callable) { cache.put(signatureCode, callable); }
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Read nothing initialize(MIN_SIZE); for (;;) { final long K = s.readLong(); final TypeV V = (TypeV) s.readObject(); if( K == NO_KEY && V == null ) break; put(K,V); // Insert with an official put } }
private void writeObject(java.io.ObjectOutputStream s) throws IOException { s.defaultWriteObject(); // Write nothing for( long K : keySet() ) { final Object V = get(K); // Do an official 'get' s.writeLong (K); // Write the <long,TypeV> pair s.writeObject(V); } s.writeLong(NO_KEY); // Sentinel to indicate end-of-data s.writeObject(null); }
public ChannelFD getWrapperFromFileno(int fileno) { ChannelFD fd = filenoMap.get(fileno); // This is a hack to get around stale ChannelFD that are closed when a descriptor is reused. // It appears to happen for openpty, and in theory could happen for any IO call that produces // a new descriptor. if (fd != null && !fd.ch.isOpen() && !isFake(fileno)) { FileStat stat = posix.allocateStat(); if (posix.fstat(fileno, stat) >= 0) { // found ChannelFD is closed, but actual fileno is open; clear it. filenoMap.remove(fileno); fd = null; } } return fd; }
/** Legacy method testing if some key maps into the specified value in this * table. This method is identical in functionality to {@link * #containsValue}, and exists solely to ensure full compatibility with * class {@link java.util.Hashtable}, which supported this method prior to * introduction of the Java Collections framework. * @param val a value to search for * @return <tt>true</tt> if this map maps one or more keys to the specified value * @throws NullPointerException if the specified value is null */ public boolean contains ( Object val ) { return containsValue(val); }
/** Create a new NonBlockingHashMapLong, setting both the initial size and * the space-for-speed tradeoff. {@code true} optimizes for space and is * the default. {@code false} optimizes for speed and doubles space costs * for roughly a 10% speed improvement. */ public NonBlockingHashMapLong( final int initial_sz, final boolean opt_for_space ) { _opt_for_space = opt_for_space; initialize(initial_sz); } private final void initialize( final int initial_sz ) {
private final TypeV putIfMatch( long key, Object newVal, Object oldVal ) { if (oldVal == null || newVal == null) throw new NullPointerException(); if( key == NO_KEY ) { final Object curVal = _val_1; if( oldVal == NO_MATCH_OLD || // Do we care about expected-Value at all? curVal == oldVal || // No instant match already? (oldVal == MATCH_ANY && curVal != TOMBSTONE) || oldVal.equals(curVal) ) // Expensive equals check CAS_val_1(curVal, newVal); // One shot CAS update attempt return curVal == TOMBSTONE ? null : (TypeV)curVal; // Return the last value present } final Object res = _chm.putIfMatch( key, newVal, oldVal ); assert !(res instanceof Prime); assert res != null; return res == TOMBSTONE ? null : (TypeV)res; }
/** * Internal API * @param signatureCode * @return callable */ public final T getSignature(int signatureCode) { return cache.get(signatureCode); }
/** * Internal API * @param signatureCode * @param callable */ public final void putSignature(int signatureCode, T callable) { cache.put(signatureCode, callable); }
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Read nothing initialize(MIN_SIZE); for (;;) { final long K = s.readLong(); final TypeV V = (TypeV) s.readObject(); if( K == NO_KEY && V == null ) break; put(K,V); // Insert with an official put } }
private void writeObject(java.io.ObjectOutputStream s) throws IOException { s.defaultWriteObject(); // Write nothing for( long K : keySet() ) { final Object V = get(K); // Do an official 'get' s.writeLong (K); // Write the <long,TypeV> pair s.writeObject(V); } s.writeLong(NO_KEY); // Sentinel to indicate end-of-data s.writeObject(null); }
public ChannelFD getWrapperFromFileno(int fileno) { ChannelFD fd = filenoMap.get(fileno); // This is a hack to get around stale ChannelFD that are closed when a descriptor is reused. // It appears to happen for openpty, and in theory could happen for any IO call that produces // a new descriptor. if (fd != null && !fd.ch.isOpen() && !isFake(fileno)) { FileStat stat = posix.allocateStat(); if (posix.fstat(fileno, stat) >= 0) { // found ChannelFD is closed, but actual fileno is open; clear it. filenoMap.remove(fileno); fd = null; } } return fd; }
/** Legacy method testing if some key maps into the specified value in this * table. This method is identical in functionality to {@link * #containsValue}, and exists solely to ensure full compatibility with * class {@link java.util.Hashtable}, which supported this method prior to * introduction of the Java Collections framework. * @param val a value to search for * @return <tt>true</tt> if this map maps one or more keys to the specified value * @throws NullPointerException if the specified value is null */ public boolean contains ( Object val ) { return containsValue(val); }
/** Create a new NonBlockingHashMapLong, setting both the initial size and * the space-for-speed tradeoff. {@code true} optimizes for space and is * the default. {@code false} optimizes for speed and doubles space costs * for roughly a 10% speed improvement. */ public NonBlockingHashMapLong( final int initial_sz, final boolean opt_for_space ) { _opt_for_space = opt_for_space; initialize(initial_sz); } private final void initialize( final int initial_sz ) {