////////////////////////////////////////////////////////////////////////
// buffer.InMessage
////////////////////////////////////////////////////////////////////////
// LOCKS_EXCLUDED(c.mu)
166329
func (c *Connection) getInMessage() (x *buffer.InMessage) {
	c.mu.Lock()
	x = (*buffer.InMessage)(c.inMessages.Get())
	c.mu.Unlock()

	if x == nil {
		x = new(buffer.InMessage)
	}

	return
}
1173662
@Override
    public void onFragment(DirectBuffer buffer, int offset, int length, Header header) {
        ByteBuffer byteBuffer = buffer.byteBuffer();
        boolean byteArrayInput = false;
        if (byteBuffer == null) {
            byteArrayInput = true;
            byte[] destination = new byte[length];
            ByteBuffer wrap = ByteBuffer.wrap(buffer.byteArray());
            wrap.get(destination, offset, length);
            byteBuffer = ByteBuffer.wrap(destination).order(ByteOrder.nativeOrder());
        }


        //only applicable for direct buffers where we don't wrap the array
        if (!byteArrayInput) {
            byteBuffer.position(offset);
            byteBuffer.order(ByteOrder.nativeOrder());
        }

        int messageTypeIndex = byteBuffer.getInt();
        if (messageTypeIndex >= NDArrayMessage.MessageType.values().length)
            throw new IllegalStateException(
                            "Illegal index on message opType. Likely corrupt message. Please check the serialization of the bytebuffer. Input was bytebuffer: "
                                            + byteArrayInput);
        NDArrayMessage.MessageType messageType = NDArrayMessage.MessageType.values()[messageTypeIndex];

        if (messageType == NDArrayMessage.MessageType.CHUNKED) {
            NDArrayMessageChunk chunk = NDArrayMessageChunk.fromBuffer(byteBuffer, messageType);
            if (chunk.getNumChunks() < 1)
                throw new IllegalStateException("Found invalid number of chunks " + chunk.getNumChunks()
                                + " on chunk index " + chunk.getChunkIndex());
            chunkAccumulator.accumulateChunk(chunk);
            log.info("Number of chunks " + chunk.getNumChunks() + " and number of chunks " + chunk.getNumChunks()
                            + " for id " + chunk.getId() + " is " + chunkAccumulator.numChunksSoFar(chunk.getId()));

            if (chunkAccumulator.allPresent(chunk.getId())) {
                NDArrayMessage message = chunkAccumulator.reassemble(chunk.getId());
                ndArrayCallback.onNDArrayMessage(message);
            }
        } else {
            NDArrayMessage message = NDArrayMessage.fromBuffer(buffer, offset);
            ndArrayCallback.onNDArrayMessage(message);
        }


    }
40299
protected static void multTransBBlockMinus( final double[] dataA, final double []dataC,
                                                final int indexA, final int indexB, final int indexC,
                                                final int widthA, final int heightA, final int widthC ) {
//        for( int i = 0; i < heightA; i++ ) {
//            for( int j = 0; j < widthC; j++ ) {
//                double sum = 0;
//                for( int k = 0; k < widthA; k++ ) {
//                    sum += dataA[i*widthA + k + indexA] * dataA[j*widthA + k + indexB];
//                }
//                dataC[ i*widthC + j + indexC ] -= sum;
//            }
//        }
        
        int rowA = indexA;
        int c = indexC;
        for( int i = 0; i < heightA; i++ , rowA += widthA ) {
            final int endA = rowA + widthA;
            int rowB = indexB;
            final int endLoopJ = c + widthC;

            // for( int j = 0; j < widthC; j++  ) {
            while( c != endLoopJ ) {
                int a = rowA;
                int b = rowB;

                double sum = 0;
                while( a != endA ) {
                    sum += dataA[a++] * dataA[b++];
                }
                dataC[ c++ ] -= sum;
                rowB += widthA;
            }
        }
    }
710211
public static Buffer ensureNotEmpty(final Buffer reference, final String msg) throws IllegalArgumentException {
        if (reference == null || reference.isEmpty()) {
            throw new IllegalArgumentException(msg);
        }
        return reference;
    }
300212
public static IoBufferEx doEncode(IoBufferAllocatorEx<?> allocator, int flags, WsMessage message, int maskValue) {
        final boolean mask = true;

        IoBufferEx ioBuf = getBytes(allocator, flags, message);
        ByteBuffer buf = ioBuf.buf();

    	boolean fin = message.isFin();

    	int remaining = buf.remaining();

    	int offset = 2 + (mask ? 4 : 0) + calculateLengthSize(remaining);
    		ByteBuffer b = allocator.allocate(offset + remaining, flags);

		int start = b.position();

		byte b1 = (byte) (fin ? 0x80 : 0x00);
		byte b2 = (byte) (mask ? 0x80 : 0x00);

		b1 = doEncodeOpcode(b1, message);
		b2 |= lenBits(remaining);

		b.put(b1).put(b2);

		doEncodeLength(b, remaining);

		if (mask) {
			b.putInt(maskValue);
		}

		if ( mask ) {
            WsFrameUtils.xor(buf, b, maskValue);
        }
            // reset buffer position after write in case of reuse
            // (KG-8125) if shared, duplicate to ensure we don't affect other threads
            if (ioBuf.isShared()) {
                b.put(buf.duplicate());
            }
            else {
                int bufPos = buf.position();
                b.put(buf);
                buf.position(bufPos);
            }
            b.limit(b.position());
            b.position(start);
    		return allocator.wrap(b, flags);
	}
528868
private void unlockAllUnread() throws SIResourceException, SISessionDroppedException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "unlockAllUnread", new Object[] { new Integer(hashCode()), this });

    int unlockedMessages = 0;

    synchronized(this)
    {
      messageAvailable = false;

      // Only unlock messages if we have reached the end of the list.
      if(firstMsg != null && !endReached)
      {
        LMEMessage pointerMsg = null;

        if (currentMsg == null)
          pointerMsg = firstMsg;
        else
          pointerMsg = currentMsg.next;

        LMEMessage removedMsg = null;

        boolean more = true;

        if (pointerMsg != null)
        {
          while(more)
          {
            // See if this is the last message in the list
            if(pointerMsg == lastMsg)
              more = false;

            // Only unlock messages that are in the MS (and haven't already
            // been unlocked by us)
            if(pointerMsg != currentUnlockedMessage)
            {
              if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(tc, "Unlocking Message " + pointerMsg);
              if(pointerMsg.isStored)
              {
                try
                {
                  unlockMessage(pointerMsg.message,false);
                }
                catch (SIMPMessageNotLockedException e)
                {
                  // No FFDC code needed
                  SibTr.exception(tc, e);
                  // See defect 387591
                  // We should only get this exception if the message was deleted via
                  // the controllable objects i.e. the admin console. If we are here for
                  // another reason that we have a real error.
                }
              }

              unlockedMessages++;
            }

            removedMsg = pointerMsg;
            pointerMsg = pointerMsg.next;
            // Remove the element from the list
            removeMessage(removedMsg);
          }
        }
      }
    }

    if(unlockedMessages != 0)
      localConsumerPoint.removeActiveMessages(unlockedMessages);

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "unlockAllUnread", this);
  }
1188983
@Override protected AutoBuffer writeAll_impl(AutoBuffer ab) {
    for (Key<CompressedTree>[] ks : _output._treeKeys)
      for (Key<CompressedTree> k : ks)
        ab.putKey(k);
    for (Key<CompressedTree>[] ks : _output._treeKeysAux)
      for (Key<CompressedTree> k : ks)
        ab.putKey(k);
    return super.writeAll_impl(ab);
  }
299525
function lockCrc(inputStr){

		res = 0xff;
		inputHex = new Buffer(inputStr,'hex');

		//start from the second byte 
		for (i = 1; i<= inputHex.length; i++) {
			res = res ^ inputHex[i];
		}
		//add padding
		reshex = (res+0x100).toString(16).substr(-2);
//		console.log(reshex);

		return(inputStr+reshex);
}
892719
ChannelBuffer buffer() throws IOException {
    ChannelBufferOutputStream bout =
      new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encoded_length));

    try {
      for (TaskMessage msg : messages) {
        writeTaskMessage(bout, msg);
      }
      return bout.buffer();
    } catch (IOException e) {
      log.error("Error while writing Tasks to Channel Buffer - {}", e.getMessage());
    } finally {
      Closeables.close(bout, false);
    }
    return null;
  }
848187
public static boolean isContiguousInBuffer(INDArray in) {
        long length = in.length();
        long dLength = in.data().length();
        if (length == dLength)
            return true; //full buffer, always contiguous

        char order = in.ordering();

        long[] shape = in.shape();
        long[] stridesIfContiguous;
        if (order == 'f') {
            stridesIfContiguous = ArrayUtil.calcStridesFortran(shape);
        } else if (order == 'c') {
            stridesIfContiguous = ArrayUtil.calcStrides(shape);
        } else if (order == 'a') {
            stridesIfContiguous = new long[] {1, 1};
        } else {
            throw new RuntimeException("Invalid order: not c or f (is: " + order + ")");
        }

        return Arrays.equals(in.stride(), stridesIfContiguous);
    }
949097
static int mergeDelimitedFrom(InputStream in, byte[] buf, Object message, 
            Schema schema, boolean decodeNestedMessageAsGroup) throws IOException
    {
        final int size = in.read();
        if(size == -1)
            throw new EOFException("mergeDelimitedFrom");
        
        final int len = size < 0x80 ? size : CodedInput.readRawVarint32(in, size);
        
        if(len < 0)
            throw ProtobufException.negativeSize();
        
        if(len != 0)
        {
            // not an empty message
            if(len > buf.length)
            {
                // size limit exceeded.
                throw new ProtobufException("size limit exceeded. " + 
                        len + " > " + buf.length);
            }
            
            fillBufferFrom(in, buf, 0, len);
            final ByteArrayInput input = new ByteArrayInput(buf, 0, len, 
                    decodeNestedMessageAsGroup);
            try
            {
                schema.mergeFrom(input, message);
            }
            catch(ArrayIndexOutOfBoundsException e)
            {
                throw ProtobufException.truncatedMessage(e);
            }
            input.checkLastTagWas(0);
        }
        
        return len;
    }
485708
func (me *Engine) LockDB(newMessages map[string][]*MessageRow, changedMessages map[string][]string) func() {
	// Short-circuit to avoid taking any locks if there's nothing to do.
	if len(newMessages) == 0 && len(changedMessages) == 0 {
		return func() {}
	}

	// Build the set of affected messages tables.
	combined := make(map[string]struct{})
	for name := range newMessages {
		combined[name] = struct{}{}
	}
	for name := range changedMessages {
		combined[name] = struct{}{}
	}

	// Build the list of manager objects (one per table).
	var mms []*messageManager
	// Don't do DBLock while holding lock on mu.
	// It causes deadlocks.
	func() {
		me.mu.Lock()
		defer me.mu.Unlock()
		for name := range combined {
			if mm := me.managers[name]; mm != nil {
				mms = append(mms, mm)
			}
		}
	}()
	if len(mms) > 1 {
		// Always use the same order in which manager objects are locked to avoid deadlocks.
		// The previous order in "mms" is not guaranteed for multiple reasons:
		// - We use a Go map above which does not guarantee an iteration order.
		// - Transactions may not always use the same order when writing to multiple
		//   messages tables.
		sort.Slice(mms, func(i, j int) bool { return mms[i].name.String() < mms[j].name.String() })
	}

	// Lock each manager/messages table.
	for _, mm := range mms {
		mm.DBLock.Lock()
	}
	return func() {
		for _, mm := range mms {
			mm.DBLock.Unlock()
		}
	}
}
1149610
@Override
  public final void onMessageSent(Session session, Object msg) {
    Command command = (Command) msg;
    command.setStatus(OperationStatus.SENT);
    // After message sent,we can set the buffer to be null for gc friendly.
    command.setIoBuffer(EMPTY_BUF);
    switch (command.getCommandType()) {
      case ADD:
      case APPEND:
      case SET:
      case SET_MANY:
        // After message sent,we can set the value to be null for gc
        // friendly.
        if (command instanceof StoreCommand) {
          ((StoreCommand) command).setValue(null);
        }
        break;
    }
  }
659432
function ErrorLocked (message) {

  Error.call(this);

  // Add Information
  this.name    = 'ErrorLocked';
  this.type    = 'client';
  this.status  = 423;
  if (message) {
    this.message = message;
  }

}
536430
protected static void multTransABlockMinus( double[] dataA, double []dataC,
                                                int indexA, int indexB, int indexC,
                                                final int heightA, final int widthA, final int widthC ) {
//        for( int i = 0; i < widthA; i++ ) {
//            for( int k = 0; k < heightA; k++ ) {
//
//                double valA = dataA[k*widthA + i + indexA];
//                for( int j = 0; j < widthC; j++ ) {
//                    dataC[ i*widthC + j + indexC ] -= valA * dataA[k*widthC + j + indexB];
//                }
//            }
//        }

        int rowB = indexB;
        int endLoopK = rowB + heightA*widthC;
        int startA = indexA;

        //for( int k = 0; k < heightA; k++ ) {
        for( ; rowB != endLoopK; rowB += widthC , startA += widthA ) {
            int a = startA;
            int c = indexC;

            int endA = a + widthA;
            int endB = rowB + widthC;

            while( a != endA ) {
                double valA = dataA[a++];

                int b = rowB;
                while( b != endB ) {
                    dataC[ c++ ] -= valA * dataA[b++];
                }
            }
        }
    }
154889
function buffer(patch) {
		var mw = (patch || core.base());
		mw.lines = [];
		mw.enabled = true;
		mw.writeln = function (line) {
			if (mw.enabled) {
				mw.lines.push(String(line));
			}
		};
		//TODO add wordwrap?
		mw.concat = function (seperator, indent, sepAfter) {
			if (mw.lines.length > 0) {
				sepAfter = (typeof sepAfter !== 'undefined' ? sepAfter : true);
				seperator = (typeof seperator !== 'undefined' ? seperator : '\n');
				indent = (typeof indent !== 'undefined' ? indent : '');
				return indent + mw.lines.join(seperator + indent) + (sepAfter ? seperator : '');
			}
			return '';
		};
		mw.clear = function () {
			mw.lines.length = 0;
		};
		if (!patch) {
			mw.toString = function () {
				return '<miniwrite-buffer>';
			};
		}
		return mw;
	}
961075
@Override
	protected int decode(ByteBuffer b, char[] chars, int pos, int len, MutableBoolean interrupt, int min) {
		if (b == null) {
			// end
			if (state == 0)
				return -1;
			chars[pos] = (char)val;
			state = 0;
			return 1;
		}
		int nb = 0;
		while ((state == 7 || b.hasRemaining()) && nb < len && (nb < min || interrupt == null || !interrupt.get())) {
			int a = state == 7 ? 0 : b.get() & 0xFF;
			switch (state) {
			case 0:
				if (a < 0x80) {
					// 0aaa aaaa
					chars[pos + (nb++)] = (char)a;
				} else if ((a & 0xE0) == 0xC0) {
					// 110a aaaa 10bb bbbb
					val = (a & 0x1F) << 6;
					state = 1;
				} else if ((a & 0xF0) == 0xE0) {
					// 1110 aaaa 10bb bbbb 10cc cccc
					val = (a & 0x0F) << 12;
					state = 2;
				} else if ((a & 0xF8) == 0xF0) {
					// 1111 0aaa 10bb bbbb 10cc cccc 10dd dddd
					val = (a & 0x07) << 12;
					state = 4;
				} else {
					chars[pos + (nb++)] = invalidChar;
				}
				break;
			case 1:
				// second byte of 110a aaaa 10bb bbbb
				if ((a & 0xC0) == 0x80) {
					chars[pos + (nb++)] = (char)(val | (a & 0x3F));
				} else {
					chars[pos + (nb++)] = invalidChar;
				}
				state = 0;
				break;
			case 2:
				// second byte of 1110 aaaa 10bb bbbb 10cc cccc
				if ((a & 0xC0) == 0x80) {
					val |= (a & 0x3F) << 6;
					state = 3;
				} else {
					chars[pos + (nb++)] = invalidChar;
					state = 0;
				}
				break;
			case 3:
				// third byte of 1110 aaaa 10bb bbbb 10cc cccc
				if ((a & 0xC0) == 0x80) {
					chars[pos + (nb++)] = (char)(val | (a & 0x3F));
				} else {
					chars[pos + (nb++)] = invalidChar;
				}
				state = 0;
				break;
			case 4:
				// second byte of 1111 0aaa 10bb bbbb 10cc cccc 10dd dddd
				if ((a & 0xC0) == 0x80) {
					val |= (a & 0x3F) << 6;
					state = 5;
				} else {
					chars[pos + (nb++)] = invalidChar;
					state = 0;
				}
				break;
			case 5:
				// third byte of 1111 0aaa 10bb bbbb 10cc cccc 10dd dddd
				if ((a & 0xC0) == 0x80) {
					val |= (a & 0x3F);
					state = 6;
				} else {
					chars[pos + (nb++)] = invalidChar;
					state = 0;
				}
				break;
			case 6:
				// fourth byte of 1111 0aaa 10bb bbbb 10cc cccc 10dd dddd
				if ((a & 0xC0) == 0x80) {
					// UTF-8:   [1111 0uuu] [10uu zzzz] [10yy yyyy] [10xx xxxx]*
					// Unicode: [1101 10ww] [wwzz zzyy] (high surrogate)
					//          [1101 11yy] [yyxx xxxx] (low surrogate)
					//          * uuuuu = wwww + 1
					int uuuuu = (val & 0x7C00) >> 10;
					// TODO if > 0x10 invalid Surrogate
					int wwww = uuuuu - 1;
					chars[pos + (nb++)] = (char)(0xD800 | (wwww << 6) | ((val & 0x3C0) >> 4) | ((val & 0x30) >> 4));
					val = (0xDC00 | ((val & 0xF) << 6) | (a & 0x3F));
					state = 7;
				} else {
					chars[pos + (nb++)] = invalidChar;
					state = 0;
				}
				break;
			case 7:
				chars[pos + (nb++)] = (char)val;
				state = 0;
				break;
			}
		}
		return nb;
	}