Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception for serializing off heap buffer #225

Open
xingbowu opened this issue Jul 6, 2017 · 1 comment
Open

Exception for serializing off heap buffer #225

xingbowu opened this issue Jul 6, 2017 · 1 comment

Comments

@xingbowu
Copy link

xingbowu commented Jul 6, 2017

StackOverflow Exception for serializing off heap ByteBuffer by allocateDirect()

Demo as below:

  public static void main(String[] args) {
      ByteBuffer buf= ByteBuffer.allocateDirect(100);
      for(int i=1; i<=buf.capacity()/4; i++) {
          buf.putInt(i);
      }
      byte[] protostuffByte ;
      LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
      Class<ByteBuffer> clazz = (Class<ByteBuffer>) buf.getClass();
      try {
          Schema<ByteBuffer> schema = RuntimeSchema.getSchema(clazz);
          protostuffByte = ProtostuffIOUtil.toByteArray(buf, schema, buffer);
      } catch (Exception e) {
          throw new IllegalStateException(e.getMessage(), e);
      } finally {
          buffer.clear();
      }
  }

Exception in thread "main" java.lang.StackOverflowError
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
at io.protostuff.runtime.DefaultIdStrategy.tryWriteDelegateIdTo(DefaultIdStrategy.java:432)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:718)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$13$1.writeTo(RuntimeUnsafeFieldFactory.java:1048)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.runtime.ObjectSchema.writeObjectTo(ObjectSchema.java:761)
at io.protostuff.runtime.ObjectSchema.writeTo(ObjectSchema.java:356)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)
at io.protostuff.runtime.RuntimeUnsafeFieldFactory$15$1.writeTo(RuntimeUnsafeFieldFactory.java:1232)
at io.protostuff.runtime.RuntimeSchema.writeTo(RuntimeSchema.java:475)
at io.protostuff.ProtostuffOutput.writeObject(ProtostuffOutput.java:363)

@dyu
Copy link
Member

dyu commented Jul 6, 2017

  1. Use a pojo that wraps the buffer.
  2. Register a delegate for the byte buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants