不可思议的堆栈跟踪

时间:2018-02-26 09:46:25

标签: java jvm stack-trace

通过分析问题,我试图理解这个奇怪的堆栈跟踪:

Thread 3049: (state = BLOCKED)
- java.lang.Object.wait(long) @bci=0 (Compiled frame; information may be imprecise)
- java.io.PipedInputStream.read() @bci=142, line=326 (Compiled frame)
- java.io.PipedInputStream.read(byte[], int, int) @bci=43, line=377 (Compiled frame)
- org.apache.http.entity.InputStreamEntity.writeTo(java.io.OutputStream) @bci=75, line=140 (Compiled frame)
- org.apache.http.impl.execchain.RequestEntityProxy.writeTo(java.io.OutputStream) @bci=10, line=123 (Compiled frame)
- org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest) @bci=31, line=156 (Compiled frame)
- org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest) @bci=5, line=162 (Compiled frame)
- org.apache.http.protocol.HttpRequestExecutor.doSendRequest(org.apache.http.HttpRequest, org.apache.http.HttpClientConnection, org.apache.http.protocol.HttpContext) @bci=223, line=238 (Compiled frame)
- org.apache.http.protocol.HttpRequestExecutor.execute(org.apache.http.HttpRequest, org.apache.http.HttpClientConnection, org.apache.http.protocol.HttpContext) @bci=25, line=123 (Compiled frame)
- org.apache.http.impl.execchain.MainClientExec.execute(org.apache.http.conn.routing.HttpRoute, org.apache.http.client.methods.HttpRequestWrapper, org.apache.http.client.protocol.HttpClientContext, org.apache.http.client.methods.HttpExecutionAware) @bci=714, line=271 (Compiled frame)
- org.apache.http.impl.execchain.ProtocolExec.execute(org.apache.http.conn.routing.HttpRoute, org.apache.http.client.methods.HttpRequestWrapper, org.apache.http.client.protocol.HttpClientContext, org.apache.http.client.methods.HttpExecutionAware) @bci=447, line=184 (Compiled frame)
- org.apache.http.impl.execchain.RetryExec.execute(org.apache.http.conn.routing.HttpRoute, org.apache.http.client.methods.HttpRequestWrapper, org.apache.http.client.protocol.HttpClientContext, org.apache.http.client.methods.HttpExecutionAware) @bci=39, line=88 (Compiled frame)
- org.apache.http.impl.client.InternalHttpClient.doExecute(org.apache.http.HttpHost, org.apache.http.HttpRequest, org.apache.http.protocol.HttpContext) @bci=168, line=184 (Compiled frame)
- java.util.concurrent.locks.AbstractQueuedSynchronizer.doReleaseShared() @bci=69, line=695 (Compiled frame)
- java.util.concurrent.locks.AbstractQueuedSynchronizer.releaseShared(int) @bci=9, line=1342 (Compiled frame)
- java.util.concurrent.CountDownLatch.countDown() @bci=5, line=291 (Compiled frame)
- com.mycompany.browse.concurrent.stream.CustomPipedInputStream.close() @bci=8, line=43 (Compiled frame)
- com.mycompany.browse.mina.handler.BrowseHttpMessageProcessor$1.run() @bci=57, line=200 (Compiled frame)
- java.util.concurrent.Executors$RunnableAdapter.call() @bci=4, line=511 (Compiled frame)
- java.util.concurrent.FutureTask.run() @bci=42, line=266 (Compiled frame)
- java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) @bci=95, line=1142 (Compiled frame)
- java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=5, line=617 (Compiled frame)
- java.lang.Thread.run() @bci=11, line=745 (Compiled frame)

基于堆栈跟踪,AbstractQueuedSynchronizer调用Apache HTTP客户端。怎么会发生这种情况? 我们在Amazon Linux上运行Oracle Java 1.8

我有很多线程具有完全相同的堆栈跟踪。随时

稍后编辑:根据建议从不可能重命名为不可思议

1 个答案:

答案 0 :(得分:3)

据我所知,你已经在强制模式下获得了这个堆栈跟踪:

#!/usr/bin/env python
#coding:utf-8

from __future__ import print_function
from PIL import Image
import math

#https://stackoverflow.com/questions/13584586/sprite-sheet-detect-individual-sprite-bounds-automatically?rq=1
'''
Process each* scan line in turn
  For each scanline, walk from left to right, until you find a non-transparent pixel P.
    If the location of P is already inside a known bounded box
      Continue to the right of the bounded box
    Else
      BBox = ExploreBoundedBox(P)
      Add BBox to the collection of known bounded boxes

Function ExploreBoundedBox(pStart)
  Q = new Queue(pStart)
  B = new BoundingBox(pStart)

  While Q is not empty
    Dequeue the front element as P
    Expand B to include P

    For each of the four neighbouring pixels N
      If N is not transparent and N is not marked
        Mark N
        Enqueue N at the back of Q

  return B
'''

class Sprite:
  def __init__(self):
    self.start_x = -1
    self.start_y = -1
    self.end_x = -1
    self.end_y = -1

  def expand (self, point):
    if (self.start_x < 0 and self.start_y < 0 and self.end_x < 0 and self.end_y < 0):
      self.start_x = point[0]
      self.start_y = point[1]
      self.end_x = point[0]
      self.end_y = point[1]
    else:
      if (point[0] < self.start_x):
        self.start_x = point[0]
      if (point[0] > self.end_x):
        self.end_x = point[0]
      if (point[1] < self.start_y):
        self.start_y = point[1]
      if (point[1] > self.end_y):
        self.end_y = point[1]

  def belongs (self, point):
    result = False
    result = True
    result = result and point[0] >= self.start_x and point[0] <= self.end_x
    result = result and point[1] >= self.start_y and point[1] <= self.end_y
    return result

  def __str__(self):
    result = ""
    result = result + "("
    result = result + str(self.start_x)
    result = result + ", "
    result = result + str(self.start_y)
    result = result + ", "
    result = result + str(self.end_x)
    result = result + ", "
    result = result + str(self.end_y)
    result = result + ")"
    return result

def loadSprite (pos, sprites):
  result = None
  for sprite in sprites:
    if sprite.belongs(pos):
      result = sprite
      break
  return result


'''
Function ExploreBoundedBox(pStart)
  Q = new Queue(pStart)
  B = new BoundingBox(pStart)

  While Q is not empty
    Dequeue the front element as P
    Expand B to include P

    For each of the four neighbouring pixels N
      If N is not transparent and N is not marked
        Mark N
        Enqueue N at the back of Q

  return B
'''
def exploreBoundedBox (pStart, img):
  result = None
  q = []
  q.append(pStart)
  result = Sprite()
  result.expand(pStart)
  marks = []
  while (len(q) > 0):
    p = q.pop(0)
    result.expand(p)
    neighbouring = loadEightNeighbouringPixels(p, img)
    for n in neighbouring:
      if img.getpixel(n)[3] > 0 and not n in marks:
        marks.append(n)
        q.append(n)
  return result

def loadFourNeighbouringPixels (point, img):
  result = None
  result = []

  newPoint = (point[0], point[1] - 1)
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  newPoint = (point[0] - 1, point[1])
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  newPoint = (point[0] + 1, point[1])
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  newPoint = (point[0], point[1] + 1)
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  return result

def loadEightNeighbouringPixels (point, img):
  result = None
  result = []

  newPoint = (point[0], point[1] - 1)
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  newPoint = (point[0] - 1, point[1])
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  newPoint = (point[0] + 1, point[1])
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  newPoint = (point[0], point[1] + 1)
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  newPoint = (point[0] - 1, point[1] - 1)
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  newPoint = (point[0] + 1, point[1] - 1)
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  newPoint = (point[0] - 1, point[1] + 1)
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  newPoint = (point[0] + 1, point[1] + 1)
  if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height):
    result.append(newPoint)

  return result

MINIMUM_SPRITE = 8

def firstNonSprites (sprites):
  result = None
  for sprite in sprites:
    if (sprite.end_x - sprite.start_x + 1) < MINIMUM_SPRITE or (sprite.end_y - sprite.start_y + 1) < MINIMUM_SPRITE:
      result = sprite
      break
  return result

def mergeSprites (sprite1, sprite2):
  result = None
  if (sprite1 != None and sprite2 != None):
    result = Sprite()
    result.start_x = min(sprite1.start_x, sprite2.start_x)
    result.start_y = min(sprite1.start_y, sprite2.start_y)
    result.end_x = max(sprite1.end_x, sprite2.end_x)
    result.end_y = max(sprite1.end_y, sprite2.end_y)
  return result

def findNextSprite (pivot, sprites):
  result = None
  distance = 99999999
  for sprite in sprites:
    if sprite != pivot:
      itemDistance = distanceSprites(pivot, sprite)
      if (itemDistance < distance):
        distance = itemDistance
        result = sprite
  return result

#Pitagoras
def distancePoints (point1, point2):
  result = 99999999
  if (point1 != None and point2 != None):
    a = abs(point2[0] - point1[0])
    b = abs(point2[1] - point1[1])
    result = math.sqrt(math.pow(a, 2) + math.pow(b, 2))
  return result

def distancePointSprite (point, sprite):
  result = 99999999
  if (point != None and sprite != None):
    distance = distancePoints(point, (sprite.start_x, sprite.start_y))
    if (distance < result):
      result = distance
    distance = distancePoints(point, (sprite.end_x, sprite.start_y))
    if (distance < result):
      result = distance
    distance = distancePoints(point, (sprite.start_x, sprite.end_y))
    if (distance < result):
      result = distance
    distance = distancePoints(point, (sprite.end_x, sprite.end_y))
    if (distance < result):
      result = distance
  return result


def distanceSprites (sprite1, sprite2):
  result = 99999999
  if (sprite1 != None and sprite2 != None):
    distance = distancePointSprite((sprite1.start_x, sprite1.start_y), sprite2)
    if (distance < result):
      result = distance
    distance = distancePointSprite((sprite1.end_x, sprite1.start_y), sprite2)
    if (distance < result):
      result = distance
    distance = distancePointSprite((sprite1.start_x, sprite1.end_y), sprite2)
    if (distance < result):
      result = distance
    distance = distancePointSprite((sprite1.end_x, sprite1.end_y), sprite2)
    if (distance < result):
      result = distance
  return result

def fixMergeSprites (sprites):
  result = []
  pivotNonSprite = firstNonSprites(sprites)
  while (pivotNonSprite != None):
    nextSprite = findNextSprite(pivotNonSprite, sprites)
    if nextSprite == None:
      break
    mergeSprite = mergeSprites(pivotNonSprite, nextSprite)
    sprites.remove(nextSprite)
    sprites.remove(pivotNonSprite)
    sprites.append(mergeSprite)
    pivotNonSprite = firstNonSprites(sprites)
  result = sprites
  return result

im = Image.open("test.png")
print(im.format, im.size, im.mode)
#PNG (640, 252) RGBA
#im.show()
print("width = " + str(im.width))
print("height = " + str(im.height))



sprites = []
for y in range(im.height):
  for x in range(im.width):
    pixel = im.getpixel((x, y))
    haycolor = True if pixel[3] > 0 else False
    if (haycolor):
      pos = (x, y)
      #print("(" + str(x) + ", " + str(y) + ") -> " + str(pixel))
      pixelP = pixel
      sprite = loadSprite(pos, sprites)
      if (sprite != None):
        x = sprite.end_x
      else:
        sprite = exploreBoundedBox(pos, im)
        sprites.append(sprite)

sprites = fixMergeSprites(sprites)

print("sprites")
print(str(sprites))
idx = 1
for sprite in sprites:
  print("sprite " + str(idx) + ". -> " + str(sprite))
  imSprite = im.crop((sprite.start_x, sprite.start_y, sprite.end_x + 1, sprite.end_y + 1))
  #imSprite.show()
  imSprite.save("sprite" + str(idx) + ".png")
  idx += 1
。描述here#!/usr/bin/env python #coding:utf-8 from __future__ import print_function from PIL import Image import math #https://stackoverflow.com/questions/13584586/sprite-sheet-detect-individual-sprite-bounds-automatically?rq=1 ''' Process each* scan line in turn For each scanline, walk from left to right, until you find a non-transparent pixel P. If the location of P is already inside a known bounded box Continue to the right of the bounded box Else BBox = ExploreBoundedBox(P) Add BBox to the collection of known bounded boxes Function ExploreBoundedBox(pStart) Q = new Queue(pStart) B = new BoundingBox(pStart) While Q is not empty Dequeue the front element as P Expand B to include P For each of the four neighbouring pixels N If N is not transparent and N is not marked Mark N Enqueue N at the back of Q return B ''' class Sprite: def __init__(self): self.start_x = -1 self.start_y = -1 self.end_x = -1 self.end_y = -1 def expand (self, point): if (self.start_x < 0 and self.start_y < 0 and self.end_x < 0 and self.end_y < 0): self.start_x = point[0] self.start_y = point[1] self.end_x = point[0] self.end_y = point[1] else: if (point[0] < self.start_x): self.start_x = point[0] if (point[0] > self.end_x): self.end_x = point[0] if (point[1] < self.start_y): self.start_y = point[1] if (point[1] > self.end_y): self.end_y = point[1] def belongs (self, point): result = False result = True result = result and point[0] >= self.start_x and point[0] <= self.end_x result = result and point[1] >= self.start_y and point[1] <= self.end_y return result def __str__(self): result = "" result = result + "(" result = result + str(self.start_x) result = result + ", " result = result + str(self.start_y) result = result + ", " result = result + str(self.end_x) result = result + ", " result = result + str(self.end_y) result = result + ")" return result def loadSprite (pos, sprites): result = None for sprite in sprites: if sprite.belongs(pos): result = sprite break return result ''' Function ExploreBoundedBox(pStart) Q = new Queue(pStart) B = new BoundingBox(pStart) While Q is not empty Dequeue the front element as P Expand B to include P For each of the four neighbouring pixels N If N is not transparent and N is not marked Mark N Enqueue N at the back of Q return B ''' def exploreBoundedBox (pStart, img): result = None q = [] q.append(pStart) result = Sprite() result.expand(pStart) marks = [] while (len(q) > 0): p = q.pop(0) result.expand(p) neighbouring = loadEightNeighbouringPixels(p, img) for n in neighbouring: if img.getpixel(n)[3] > 0 and not n in marks: marks.append(n) q.append(n) return result def loadFourNeighbouringPixels (point, img): result = None result = [] newPoint = (point[0], point[1] - 1) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) newPoint = (point[0] - 1, point[1]) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) newPoint = (point[0] + 1, point[1]) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) newPoint = (point[0], point[1] + 1) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) return result def loadEightNeighbouringPixels (point, img): result = None result = [] newPoint = (point[0], point[1] - 1) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) newPoint = (point[0] - 1, point[1]) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) newPoint = (point[0] + 1, point[1]) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) newPoint = (point[0], point[1] + 1) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) newPoint = (point[0] - 1, point[1] - 1) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) newPoint = (point[0] + 1, point[1] - 1) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) newPoint = (point[0] - 1, point[1] + 1) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) newPoint = (point[0] + 1, point[1] + 1) if (newPoint[0] >= 0 and newPoint[1] >= 0 and newPoint[0] < img.width and newPoint[1] < img.height): result.append(newPoint) return result MINIMUM_SPRITE = 8 def firstNonSprites (sprites): result = None for sprite in sprites: if (sprite.end_x - sprite.start_x + 1) < MINIMUM_SPRITE or (sprite.end_y - sprite.start_y + 1) < MINIMUM_SPRITE: result = sprite break return result def mergeSprites (sprite1, sprite2): result = None if (sprite1 != None and sprite2 != None): result = Sprite() result.start_x = min(sprite1.start_x, sprite2.start_x) result.start_y = min(sprite1.start_y, sprite2.start_y) result.end_x = max(sprite1.end_x, sprite2.end_x) result.end_y = max(sprite1.end_y, sprite2.end_y) return result def findNextSprite (pivot, sprites): result = None distance = 99999999 for sprite in sprites: if sprite != pivot: itemDistance = distanceSprites(pivot, sprite) if (itemDistance < distance): distance = itemDistance result = sprite return result #Pitagoras def distancePoints (point1, point2): result = 99999999 if (point1 != None and point2 != None): a = abs(point2[0] - point1[0]) b = abs(point2[1] - point1[1]) result = math.sqrt(math.pow(a, 2) + math.pow(b, 2)) return result def distancePointSprite (point, sprite): result = 99999999 if (point != None and sprite != None): distance = distancePoints(point, (sprite.start_x, sprite.start_y)) if (distance < result): result = distance distance = distancePoints(point, (sprite.end_x, sprite.start_y)) if (distance < result): result = distance distance = distancePoints(point, (sprite.start_x, sprite.end_y)) if (distance < result): result = distance distance = distancePoints(point, (sprite.end_x, sprite.end_y)) if (distance < result): result = distance return result def distanceSprites (sprite1, sprite2): result = 99999999 if (sprite1 != None and sprite2 != None): distance = distancePointSprite((sprite1.start_x, sprite1.start_y), sprite2) if (distance < result): result = distance distance = distancePointSprite((sprite1.end_x, sprite1.start_y), sprite2) if (distance < result): result = distance distance = distancePointSprite((sprite1.start_x, sprite1.end_y), sprite2) if (distance < result): result = distance distance = distancePointSprite((sprite1.end_x, sprite1.end_y), sprite2) if (distance < result): result = distance return result def fixMergeSprites (sprites): result = [] pivotNonSprite = firstNonSprites(sprites) while (pivotNonSprite != None): nextSprite = findNextSprite(pivotNonSprite, sprites) if nextSprite == None: break mergeSprite = mergeSprites(pivotNonSprite, nextSprite) sprites.remove(nextSprite) sprites.remove(pivotNonSprite) sprites.append(mergeSprite) pivotNonSprite = firstNonSprites(sprites) result = sprites return result im = Image.open("test.png") print(im.format, im.size, im.mode) #PNG (640, 252) RGBA #im.show() print("width = " + str(im.width)) print("height = " + str(im.height)) sprites = [] for y in range(im.height): for x in range(im.width): pixel = im.getpixel((x, y)) haycolor = True if pixel[3] > 0 else False if (haycolor): pos = (x, y) #print("(" + str(x) + ", " + str(y) + ") -> " + str(pixel)) pixelP = pixel sprite = loadSprite(pos, sprites) if (sprite != None): x = sprite.end_x else: sprite = exploreBoundedBox(pos, im) sprites.append(sprite) sprites = fixMergeSprites(sprites) print("sprites") print(str(sprites)) idx = 1 for sprite in sprites: print("sprite " + str(idx) + ". -> " + str(sprite)) imSprite = im.crop((sprite.start_x, sprite.start_y, sprite.end_x + 1, sprite.end_y + 1)) #imSprite.show() imSprite.save("sprite" + str(idx) + ".png") idx += 1 之间存在很大差异。

强制模式在进程外,异步进行,没有JVM的合作。它不如常规jstack -F可靠,因为JVM不在安全点,其状态可能不一致。例如,它可以处于垃圾收集的中间。

第二个原因是堆栈转储由外部工具(可维护性代理)重建,这不是很完美。因此,为了获得可靠的堆栈跟踪,我建议尽可能在正常模式下使用jstack