AshmemMemoryChunk.smali
.class public Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;
.super Ljava/lang/Object;
.source "AshmemMemoryChunk.java"
# interfaces
.implements Lcom/facebook/imagepipeline/memory/MemoryChunk;
.implements Ljava/io/Closeable;
# annotations
.annotation build Landroid/annotation/TargetApi;
value = 0x1b
.end annotation
# static fields
.field public static final TAG:Ljava/lang/String; = "AshmemMemoryChunk"
# instance fields
.field public mByteBuffer:Ljava/nio/ByteBuffer;
.annotation runtime Ljavax/annotation/Nullable;
.end annotation
.end field
.field public final mId:J
.field public mSharedMemory:Landroid/os/SharedMemory;
.annotation runtime Ljavax/annotation/Nullable;
.end annotation
.end field
# direct methods
.method static constructor <clinit>()V
.registers 1
return-void
.end method
.method public constructor <init>()V
.registers 3
.annotation build Lcom/facebook/common/internal/VisibleForTesting;
.end annotation
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
const/4 v0, 0x0
iput-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mSharedMemory:Landroid/os/SharedMemory;
iput-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
invoke-static {p0}, Ljava/lang/System;->identityHashCode(Ljava/lang/Object;)I
move-result v0
int-to-long v0, v0
iput-wide v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mId:J
return-void
.end method
.method public constructor <init>(I)V
.registers 4
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
if-lez p1, :cond_7
const/4 v0, 0x1
goto :goto_8
:cond_7
const/4 v0, 0x0
:goto_8
invoke-static {v0}, Lcom/facebook/common/internal/Preconditions;->checkArgument(Z)V
:try_start_b
const-string v0, "AshmemMemoryChunk"
invoke-static {v0, p1}, Landroid/os/SharedMemory;->create(Ljava/lang/String;I)Landroid/os/SharedMemory;
move-result-object p1
iput-object p1, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mSharedMemory:Landroid/os/SharedMemory;
invoke-virtual {p1}, Landroid/os/SharedMemory;->mapReadWrite()Ljava/nio/ByteBuffer;
move-result-object p1
iput-object p1, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
:try_end_19
.catch Landroid/system/ErrnoException; {:try_start_b .. :try_end_19} :catch_21
invoke-static {p0}, Ljava/lang/System;->identityHashCode(Ljava/lang/Object;)I
move-result p1
int-to-long v0, p1
iput-wide v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mId:J
return-void
:catch_21
move-exception p1
new-instance v0, Ljava/lang/RuntimeException;
const-string v1, "Fail to create AshmemMemory"
invoke-direct {v0, v1, p1}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V
throw v0
.end method
.method private doCopy(ILcom/facebook/imagepipeline/memory/MemoryChunk;II)V
.registers 7
instance-of v0, p2, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;
if-eqz v0, :cond_3d
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->isClosed()Z
move-result v0
xor-int/lit8 v0, v0, 0x1
invoke-static {v0}, Lcom/facebook/common/internal/Preconditions;->checkState(Z)V
invoke-interface {p2}, Lcom/facebook/imagepipeline/memory/MemoryChunk;->isClosed()Z
move-result v0
xor-int/lit8 v0, v0, 0x1
invoke-static {v0}, Lcom/facebook/common/internal/Preconditions;->checkState(Z)V
invoke-interface {p2}, Lcom/facebook/imagepipeline/memory/MemoryChunk;->getSize()I
move-result v0
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->getSize()I
move-result v1
invoke-static {p1, v0, p3, p4, v1}, Lcom/facebook/imagepipeline/memory/MemoryChunkUtil;->checkBounds(IIIII)V
iget-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
invoke-virtual {v0, p1}, Ljava/nio/ByteBuffer;->position(I)Ljava/nio/Buffer;
invoke-interface {p2}, Lcom/facebook/imagepipeline/memory/MemoryChunk;->getByteBuffer()Ljava/nio/ByteBuffer;
move-result-object p1
invoke-virtual {p1, p3}, Ljava/nio/ByteBuffer;->position(I)Ljava/nio/Buffer;
new-array p1, p4, [B
iget-object p3, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
const/4 v0, 0x0
invoke-virtual {p3, p1, v0, p4}, Ljava/nio/ByteBuffer;->get([BII)Ljava/nio/ByteBuffer;
invoke-interface {p2}, Lcom/facebook/imagepipeline/memory/MemoryChunk;->getByteBuffer()Ljava/nio/ByteBuffer;
move-result-object p2
invoke-virtual {p2, p1, v0, p4}, Ljava/nio/ByteBuffer;->put([BII)Ljava/nio/ByteBuffer;
return-void
:cond_3d
new-instance p1, Ljava/lang/IllegalArgumentException;
const-string p2, "Cannot copy two incompatible MemoryChunks"
invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
throw p1
.end method
# virtual methods
.method public declared-synchronized close()V
.registers 2
monitor-enter p0
:try_start_1
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->isClosed()Z
move-result v0
if-nez v0, :cond_16
iget-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
invoke-static {v0}, Landroid/os/SharedMemory;->unmap(Ljava/nio/ByteBuffer;)V
iget-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mSharedMemory:Landroid/os/SharedMemory;
invoke-virtual {v0}, Landroid/os/SharedMemory;->close()V
const/4 v0, 0x0
iput-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
iput-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mSharedMemory:Landroid/os/SharedMemory;
:try_end_16
.catchall {:try_start_1 .. :try_end_16} :catchall_18
:cond_16
monitor-exit p0
return-void
:catchall_18
move-exception v0
monitor-exit p0
throw v0
.end method
.method public copy(ILcom/facebook/imagepipeline/memory/MemoryChunk;II)V
.registers 10
invoke-static {p2}, Lcom/facebook/common/internal/Preconditions;->checkNotNull(Ljava/lang/Object;)Ljava/lang/Object;
invoke-interface {p2}, Lcom/facebook/imagepipeline/memory/MemoryChunk;->getUniqueId()J
move-result-wide v0
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->getUniqueId()J
move-result-wide v2
cmp-long v4, v0, v2
if-nez v4, :cond_46
new-instance v0, Ljava/lang/StringBuilder;
invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
const-string v1, "Copying from AshmemMemoryChunk "
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->getUniqueId()J
move-result-wide v1
invoke-static {v1, v2}, Ljava/lang/Long;->toHexString(J)Ljava/lang/String;
move-result-object v1
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
const-string v1, " to AshmemMemoryChunk "
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-interface {p2}, Lcom/facebook/imagepipeline/memory/MemoryChunk;->getUniqueId()J
move-result-wide v1
invoke-static {v1, v2}, Ljava/lang/Long;->toHexString(J)Ljava/lang/String;
move-result-object v1
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
const-string v1, " which are the same "
invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
move-result-object v0
const-string v1, "AshmemMemoryChunk"
invoke-static {v1, v0}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I
const/4 v0, 0x0
invoke-static {v0}, Lcom/facebook/common/internal/Preconditions;->checkArgument(Z)V
:cond_46
invoke-interface {p2}, Lcom/facebook/imagepipeline/memory/MemoryChunk;->getUniqueId()J
move-result-wide v0
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->getUniqueId()J
move-result-wide v2
cmp-long v4, v0, v2
if-gez v4, :cond_60
monitor-enter p2
:try_start_53
monitor-enter p0
:try_end_54
.catchall {:try_start_53 .. :try_end_54} :catchall_5d
:try_start_54
invoke-direct {p0, p1, p2, p3, p4}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->doCopy(ILcom/facebook/imagepipeline/memory/MemoryChunk;II)V
monitor-exit p0
:try_end_58
.catchall {:try_start_54 .. :try_end_58} :catchall_5a
:try_start_58
monitor-exit p2
:try_end_59
.catchall {:try_start_58 .. :try_end_59} :catchall_5d
return-void
:catchall_5a
move-exception p1
:try_start_5b
monitor-exit p0
:try_end_5c
.catchall {:try_start_5b .. :try_end_5c} :catchall_5a
:try_start_5c
throw p1
:catchall_5d
move-exception p1
monitor-exit p2
:try_end_5f
.catchall {:try_start_5c .. :try_end_5f} :catchall_5d
throw p1
:cond_60
monitor-enter p0
:try_start_61
monitor-enter p2
:try_end_62
.catchall {:try_start_61 .. :try_end_62} :catchall_6b
:try_start_62
invoke-direct {p0, p1, p2, p3, p4}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->doCopy(ILcom/facebook/imagepipeline/memory/MemoryChunk;II)V
monitor-exit p2
:try_end_66
.catchall {:try_start_62 .. :try_end_66} :catchall_68
:try_start_66
monitor-exit p0
:try_end_67
.catchall {:try_start_66 .. :try_end_67} :catchall_6b
return-void
:catchall_68
move-exception p1
:try_start_69
monitor-exit p2
:try_end_6a
.catchall {:try_start_69 .. :try_end_6a} :catchall_68
:try_start_6a
throw p1
:catchall_6b
move-exception p1
monitor-exit p0
:try_end_6d
.catchall {:try_start_6a .. :try_end_6d} :catchall_6b
throw p1
.end method
.method public getByteBuffer()Ljava/nio/ByteBuffer;
.registers 2
.annotation runtime Ljavax/annotation/Nullable;
.end annotation
iget-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
return-object v0
.end method
.method public getNativePtr()J
.registers 3
new-instance v0, Ljava/lang/UnsupportedOperationException;
const-string v1, "Cannot get the pointer of an AshmemMemoryChunk"
invoke-direct {v0, v1}, Ljava/lang/UnsupportedOperationException;-><init>(Ljava/lang/String;)V
throw v0
.end method
.method public getSize()I
.registers 2
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->isClosed()Z
move-result v0
xor-int/lit8 v0, v0, 0x1
invoke-static {v0}, Lcom/facebook/common/internal/Preconditions;->checkState(Z)V
iget-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mSharedMemory:Landroid/os/SharedMemory;
invoke-virtual {v0}, Landroid/os/SharedMemory;->getSize()I
move-result v0
return v0
.end method
.method public getUniqueId()J
.registers 3
iget-wide v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mId:J
return-wide v0
.end method
.method public declared-synchronized isClosed()Z
.registers 2
monitor-enter p0
:try_start_1
iget-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
if-eqz v0, :cond_c
iget-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mSharedMemory:Landroid/os/SharedMemory;
:try_end_7
.catchall {:try_start_1 .. :try_end_7} :catchall_f
if-nez v0, :cond_a
goto :goto_c
:cond_a
const/4 v0, 0x0
goto :goto_d
:cond_c
:goto_c
const/4 v0, 0x1
:goto_d
monitor-exit p0
return v0
:catchall_f
move-exception v0
monitor-exit p0
throw v0
.end method
.method public declared-synchronized read(I)B
.registers 5
monitor-enter p0
:try_start_1
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->isClosed()Z
move-result v0
const/4 v1, 0x1
const/4 v2, 0x0
if-nez v0, :cond_b
const/4 v0, 0x1
goto :goto_c
:cond_b
const/4 v0, 0x0
:goto_c
invoke-static {v0}, Lcom/facebook/common/internal/Preconditions;->checkState(Z)V
if-ltz p1, :cond_13
const/4 v0, 0x1
goto :goto_14
:cond_13
const/4 v0, 0x0
:goto_14
invoke-static {v0}, Lcom/facebook/common/internal/Preconditions;->checkArgument(Z)V
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->getSize()I
move-result v0
if-ge p1, v0, :cond_1e
goto :goto_1f
:cond_1e
const/4 v1, 0x0
:goto_1f
invoke-static {v1}, Lcom/facebook/common/internal/Preconditions;->checkArgument(Z)V
iget-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
invoke-virtual {v0, p1}, Ljava/nio/ByteBuffer;->get(I)B
move-result p1
:try_end_28
.catchall {:try_start_1 .. :try_end_28} :catchall_2a
monitor-exit p0
return p1
:catchall_2a
move-exception p1
monitor-exit p0
throw p1
.end method
.method public declared-synchronized read(I[BII)I
.registers 7
monitor-enter p0
:try_start_1
invoke-static {p2}, Lcom/facebook/common/internal/Preconditions;->checkNotNull(Ljava/lang/Object;)Ljava/lang/Object;
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->isClosed()Z
move-result v0
if-nez v0, :cond_c
const/4 v0, 0x1
goto :goto_d
:cond_c
const/4 v0, 0x0
:goto_d
invoke-static {v0}, Lcom/facebook/common/internal/Preconditions;->checkState(Z)V
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->getSize()I
move-result v0
invoke-static {p1, p4, v0}, Lcom/facebook/imagepipeline/memory/MemoryChunkUtil;->adjustByteCount(III)I
move-result p4
array-length v0, p2
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->getSize()I
move-result v1
invoke-static {p1, v0, p3, p4, v1}, Lcom/facebook/imagepipeline/memory/MemoryChunkUtil;->checkBounds(IIIII)V
iget-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
invoke-virtual {v0, p1}, Ljava/nio/ByteBuffer;->position(I)Ljava/nio/Buffer;
iget-object p1, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
invoke-virtual {p1, p2, p3, p4}, Ljava/nio/ByteBuffer;->get([BII)Ljava/nio/ByteBuffer;
:try_end_2a
.catchall {:try_start_1 .. :try_end_2a} :catchall_2c
monitor-exit p0
return p4
:catchall_2c
move-exception p1
monitor-exit p0
throw p1
.end method
.method public declared-synchronized write(I[BII)I
.registers 7
monitor-enter p0
:try_start_1
invoke-static {p2}, Lcom/facebook/common/internal/Preconditions;->checkNotNull(Ljava/lang/Object;)Ljava/lang/Object;
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->isClosed()Z
move-result v0
if-nez v0, :cond_c
const/4 v0, 0x1
goto :goto_d
:cond_c
const/4 v0, 0x0
:goto_d
invoke-static {v0}, Lcom/facebook/common/internal/Preconditions;->checkState(Z)V
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->getSize()I
move-result v0
invoke-static {p1, p4, v0}, Lcom/facebook/imagepipeline/memory/MemoryChunkUtil;->adjustByteCount(III)I
move-result p4
array-length v0, p2
invoke-virtual {p0}, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->getSize()I
move-result v1
invoke-static {p1, v0, p3, p4, v1}, Lcom/facebook/imagepipeline/memory/MemoryChunkUtil;->checkBounds(IIIII)V
iget-object v0, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
invoke-virtual {v0, p1}, Ljava/nio/ByteBuffer;->position(I)Ljava/nio/Buffer;
iget-object p1, p0, Lcom/facebook/imagepipeline/memory/AshmemMemoryChunk;->mByteBuffer:Ljava/nio/ByteBuffer;
invoke-virtual {p1, p2, p3, p4}, Ljava/nio/ByteBuffer;->put([BII)Ljava/nio/ByteBuffer;
:try_end_2a
.catchall {:try_start_1 .. :try_end_2a} :catchall_2c
monitor-exit p0
return p4
:catchall_2c
move-exception p1
monitor-exit p0
throw p1
.end method